Differences while exiting a program in assembler

L00PeR
7 years ago

0

Hi, I’m learning assembler and I would like to know if this does exactly the same while quitting a program:
code 1:
mov eax, 1 mov ebx, 0 int 0x80
code 2:
mov eax, 1 int 0x80

2replies
2voices
185views
latency
7 years ago

1

In eax register, you’re loading the system call number (this example 0x1 = 1 = exit)

From ebx register on, you are loading all parameters to give to the sc.

In this case, in ebx you are loading the value 0x0 = 0 ? exit success.

The two ways are “quite” the same: maybe in this case you do not need for loading a singular value to ebx, but in general, when you’re calling a sc, you want the exact parameters.

So, when in ebx the already stored value (cause you just launched your application or an other set of instruction(s) put ebx to 0, the two codes performs the same sequence.

If not, the right way to do thinks is to use the first one.

[in this, I’m assuming you’re using intel assembly instructions]
```
mov ebx, 0x1

; some stuff which does not changes ebx

mov eax, 0x1 ; loading the sc number for exit
int 0x80
```

mov ebx, 0x1  

; some stuff which does not changes ebx  

mov eax, 0x1  ; loading the sc number for exit  
mov ebx, 0x0  ; exit successful, so the arg for exit is 0  

int 0x80  

Try to create these two codes (let’s call them code1.asm and code2.asm)

If you compile, link and launch the two executables obtained in an environment (maybe a debugger) which tells you with which status they exits, the second one will not generate any type of warn/error, cause the call of exit(0) tells to the system “all ok, all good. no problems here!”; while the first one will raise something saying you that the executable 1 exited with an error status.

L00PeR
7 years ago

0

WOW!, excellent explanation!

Thanks!!

Discussion thread has been locked. You can no longer add new posts.
1 of 3

This site only uses cookies that are essential for the functionality of this website. Cookies are not used for tracking or marketing purposes.

By using our site, you acknowledge that you have read and understand our Privacy Policy, and Terms of Service.

Dismiss