NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: Beta on June 27, 2020, 11:52:23 AM
-
Hi , this is my first post
I dont understand why this code prints 2 blank line when it exit
(Linux bash)
section .data
msg db "Hello I'm Nasm !!!!!!!",10 ; 10 (ritorno a capo)
msgend equ $
msgTot db "first value: "
msgEndTot equ $
section .text
global _start
_start:
;Welcome message
mov rax,1 ; 1 = sys_write syscall number
mov rdi,1 ; 1 = STDOUT file descriptor
mov rsi,msg ; message's buffer
mov rdx,msgend-msg ; Calculate the len(message)
syscall ; Kernel calls
;Input first message
mov rax,1 ; 1 = sys_write syscall number
mov rdi,1 ; 1 = STDOUT file descriptor
mov rsi,msgTot ; message's buffer
mov rdx,msgend-msg ; Calculate the len(message)
syscall ; Kernel calls
;Request first value
mov rax,0 ; 0 = sys_read syscall number
sub rsp,8 ; Allocates 8 byte nello stack
sub rbx,0x30 ; Convert Ascii to dec
and rbx,0xff ; ensures high bytes are set to zero
mov rdi,0 ; 0 = STDIN file descriptor
lea rsi,[rsp] ; char *buff points to stack address allocated space
mov rdx,1 ; size_t = 1
syscall ; Kernel calls
mov rdi,0 ; returns zero
mov rax,60 ; Exit calls
syscall ; Kernel calls
output:
beta@beta:~/TestC$ ./test
Hello I'm Nasm !!!!!!!
first value: 1
beta@beta:~/TestC$
beta@beta:~/TestC$
-
Hi Beta,
Welcome to the forum.
sys_read does not return until the "enter" key is hit. With just 1 in rdx, you do not get this. Get at least 2. Throw away the linefeed if you don't want it. I'm not in the mood to fool with this, but I think that'll solve your problem...
Best,
Frank
-
That has solved the issue, but I have more questions about asm :D
-
Hello Beta:
I'm happy you finally solved this issue, but please, can you bring us the code?. It could be interesting by the rest of members.
Anyway, i did this, but i don't know to convert strings to number yet (i'm a newbie):
section .data
msg db "Hello I'm Nasm !!!!!!!",10 ; 10 (ritorno a capo)
msgend equ $ - msg ; <--- length of msg
msgTot db "first value: "
msgEndTot equ $ - msgTot ; <--- length of msgTot
section .bss
rqst_space equ 8 ; <--- reserve 8 bytes to fill
value resb rqst_space ; <--- lenght of value
section .text
global _start
_start:
;Welcome message
mov rax,1 ; 1 = sys_write syscall number
mov rdi,1 ; 1 = STDOUT file descriptor
mov rsi,msg ; message's buffer
mov rdx,msgend ; <--- input the length
syscall ; Kernel calls
;Input first message
mov rax,1 ; 1 = sys_write syscall number
mov rdi,1 ; 1 = STDOUT file descriptor
mov rsi,msgTot ; message's buffer
mov rdx,msgEndTot ; <--- input the length
syscall ; Kernel calls
;Request first value
mov rax, 0 ; 0=sys_read syscall number
mov rdi, 0 ; 0=STDIN file descriptor
mov rsi, value ; <--- loading the value
mov rdx, rqst_space ; <--- length of the input field
syscall
;Print the first value
mov rax, 1 ; 1=sys_write syscall number
mov rdi, 1 ; 1=STDOUT file descriptor
mov rsi, value ; <--- unloading the value in display
mov rdx, rqst_space ; <--- lenght of field
syscall
; exit
xor edi, edi ; <--- returns zero
mov rax,60 ; Exit calls
syscall ; Kernel calls
Ci vediamo ! ;D