I am trying to learn assembly from scratch. I have been reading up quite a bit, but even the following simple program I found in a reference book has me stumped:
section .data
msg db "Hello!", 0xa
len equ $ - msg
section .text
global _start
_start:
move edx, len
move ecx, msg
move ebx, 1
move eax, 4
int 0x80
move ebx, 0
move eax, 1
int 0x80
Now apparently this is supposed to print “Hello”.
But I don’t even know whats happening at any of the stages.
The first two stages put the message length and messgae in two registers, which are never used again. I don’t understand why.
I don’t know why four different registers are needed.
int 0x80is a mechanism in some(a) UNIX-like operating systems for making system calls.For these calls, the registers are used for specific values. From the
syscallsfile:you can see that number 4 is the
writecall and needs three other parameters. Number 1 isexitand needs only the return code.When making the call,
eaxis the syscall that you’re making whileebx,ecxandedxare the three parameters (assuming they’re all needed –exitfor example only needs one).So, you could comment the code as follows:
(a) Later versions of Linux introduced a new interface which can use different methods based on which provides the best speed. For example, some Intel chips are much faster if you use
sysenterrather thanint 0x80.