Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

what is the purpose of "movl $0, %ebx" or getting 0 into ebx?

I know that its getting 0 into ebx but why? I’m so sorry if it looks like a no-brainer question to you, its my first week of learning assembly and a few months of programming.

I haven’t included everything below because it is a quite long, lmk if its necessary

The assembly is from the book "Programming From Ground Up Chapter 6"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

summary of assembly:

Opens an input and output file, reads records from the input, increments the age, writes the new record to the output file

SYS_EXIT is 1
LINUX_SYSCALL is 0x80

loop_begin:
pushl ST_INPUT_DESCRIPTOR(%ebp)
pushl $record_buffer
call read_record
addl $8, %esp 

# Returns the number of bytes read. If it isn’t the same number we requested, then it’s either an end-of-file, or an error, so we’re quitting
cmpl $RECORD_SIZE, %eax
jne loop_end

#Increment the age
incl record_buffer + RECORD_AGE

#Write the record out
pushl ST_OUTPUT_DESCRIPTOR(%ebp)
pushl $record_buffer
call write_record
addl $8, %esp
jmp loop_begin

loop_end:
movl $SYS_EXIT, %eax
movl $0, %ebx                             <------------------------ THE INSTRUCTION'S PURPOSE THAT IM ASKING FOR
int $LINUX_SYSCALL```

>Solution :

This is the equivalent of exit(0); in C; except that the Linux kernel uses different calling conventions (parameters passed in registers and not on the stack).

The movl $0, %ebx is loading the 2nd parameter (0) into the right register for the kernel’s calling convention. The first parameter is the function number (SYS_EXIT).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading