Reputation: 1012
I have the following Assembly code:
section .text
global _start
_start:
mov edx,len2
mov ecx,msg1
mov ebx,1
mov eax,4
int 0x80 ; write(1, msg1, len2)
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
msg1 db 'Hello '
len1 equ $ - msg1
msg2 db 'world!',0xa
len2 equ $ - msg1
I have been told that this code should print "Hello World!" but I can't understand why?
When I first looked at it I was sure it supposed to print just "Hello ". Can someone please help me to understand this, please?
Upvotes: 1
Views: 431
Reputation: 1012
as @Jester said in the comment the reason is that len2
is defined as $ - msg1
not as $ - msg2
so it includes the length of the Hello as well.
Upvotes: 4