The int 80h call itself will not corrupt anything, apart from putting the return value in eax So the code fragment you have is fine. (But if your code fragment is part of a larger routine which is expected to be called by other code following the usual Linux x86 ABI, you will need to preserve ebx and possibly other registers, on entry to your routine, and restore on exit. ).
The int 80h call itself will not corrupt anything, apart from putting the return value in eax. So the code fragment you have is fine. (But if your code fragment is part of a larger routine which is expected to be called by other code following the usual Linux x86 ABI, you will need to preserve ebx, and possibly other registers, on entry to your routine, and restore on exit.) The relevant code in the kernel can be found in arch/x86/kernel/entry_32.S.
It's a bit hard to follow, due to extensive use of macros, and various details (support for syscall tracing, DWARF debugging annotations, etc. ) but: the int 80h handler is system_call (line 529 in the version I've linked to); the registers are saved via the SAVE_ALL macro (line 533); and they're restored again via RESTORE_REGS (line 567) just before returning.
Yes, you should save and restore as in linuxjournal.com/files/linuxjournal.com/....
That code is saving and restoring %ebx so that it can use it to pass in the argument - not because the int $0x80 itself is corrupting it. – Matthew Slattery Apr 25 '10 at 16:56.
The int 80h call itself will not corrupt anything, apart from putting the return value in eax . So the code fragment you have is fine. (But if your code fragment is part of a larger routine which is expected to be called by other code following the usual Linux x86 ABI, you will need to preserve ebx and possibly other registers, on entry to your routine, and restore on exit.
).
Up vote 5 down vote favorite share g+ share fb share tw.
I have the below code that opens up a file, reads it into a buffer and then closes the file. The close file system call requires that the file descriptor number be in the ebx register. The ebx register gets the file descriptor number before the read system call is made.
My question is should I save the ebx register on the stack or somewhere before I make the read system call, (could int 80h trash the ebx register? ). And then restore the ebx register for the close system call?
Or is the code I have below fine and safe? I have run the below code and it works, I'm just not sure if it is generally considered good assembly practice or not because I don't save the ebx register before the int 80h read call. ;; open up the input file mov eax,5 ; open file system call number mov ebx,esp+8 ; null terminated string file name, first command line parameter mov ecx,0o ; access type: O_RDONLY int 80h ; file handle or negative error number put in eax test eax,eax js Error ; test sign flag (SF) for negative number which signals error ;; read in the full input file mov ebx,eax ; assign input file descripter mov eax,3 ; read system call number mov ecx,InputBuff ; buffer to read into mov edx,INPUT_BUFF_LEN ; total bytes to read int 80h test eax,eax js Error ; if eax is negative then error jz Error ; if no bytes were read then error add eax,InputBuff ; add size of input to the begining of InputBuff location mov InputEnd,eax ; assign address of end of input ;; close the input file ;; file descripter is already in ebx mov eax,6 ; close file system call number int 80h linux assembly x86 syscall link|improve this question edited Apr 25 '10 at 16:53Matthew Slattery12.6k1630 asked Apr 24 '10 at 18:42mudge992520 70% accept rate.
The int 80h call itself will not corrupt anything, apart from putting the return value in eax. So the code fragment you have is fine. (But if your code fragment is part of a larger routine which is expected to be called by other code following the usual Linux x86 ABI, you will need to preserve ebx, and possibly other registers, on entry to your routine, and restore on exit.
) The relevant code in the kernel can be found in arch/x86/kernel/entry_32.S. It's a bit hard to follow, due to extensive use of macros, and various details (support for syscall tracing, DWARF debugging annotations, etc.) but: the int 80h handler is system_call (line 529 in the version I've linked to); the registers are saved via the SAVE_ALL macro (line 533); and they're restored again via RESTORE_REGS (line 567) just before returning.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.