1

Is the below instruction in message: an correct? Specifically, because "Hello, World", is a total of 12 bytes, however, the right operand has "10".

I wanted to know if that is an error. If not, why does it specify 10 as the right operand? I got this code from here: (http://cs.lmu.edu/~ray/notes/x86assembly/)

Also, in mov rdx,13 why does it specify 13 bytes and not the actual size of message?

    global _start

    section .text
_start:
    ; write(1, message, 13)
    mov     rax, 1            ; system call write is 1
    mov     rdi, 1            ; 1 is stdout
    mov     rsi, message      ; address of string
    mov     rdx, 13           ; number of bytes
    syscall           ; invoke operating system call

    ; exit(0)
    mov eax, 60       ; system call 60 is exit
    xor rdi, rdi      ; exit code 0
    syscall           ; invoke exit
message:
    db  "Hello, World", 10
Ryan
  • 14,392
  • 8
  • 62
  • 102

1 Answers1

3

If not, why does it specify 10 as the right operand?

The 10 is a newline character after the string. 10 in ASCII is LF (line feed) which is newline on Unix/Linux systems. On other systems it's different.

why does it specify 13 bytes and not the actual size of message?

13 bytes is the size of the message (12 bytes) plus the newline character (1 byte)

Community
  • 1
  • 1
samgak
  • 23,944
  • 4
  • 60
  • 82