Author Topic: Why Does it print two blank line when exit  (Read 295 times)

Offline Beta

  • Jr. Member
  • *
  • Posts: 3
Why Does it print two blank line when exit
« 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)

Code: [Select]
     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:
Quote
beta@beta:~/TestC$ ./test
Hello I'm Nasm !!!!!!!
first value: 1
beta@beta:~/TestC$
beta@beta:~/TestC$

« Last Edit: June 27, 2020, 11:59:22 AM by Beta »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2437
  • Country: us
Re: Why Does it print two blank line when exit
« Reply #1 on: June 27, 2020, 08:17:40 PM »
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


Offline Beta

  • Jr. Member
  • *
  • Posts: 3
Re: Why Does it print two blank line when exit
« Reply #2 on: July 02, 2020, 05:08:11 PM »
That has solved the issue, but  I have more questions about asm :D