简体   繁体   中英

registers and interrupts in assembly

I'm reading the manual on nasm programming in Linux and there is a thing I can't find the answer to.

Consider the following code:

mov eax, 4
mov ebx, 1
mov ecx, buffer
int 0x80

As far as I understand this sets settings to the appropriate registers and then "pushes" them to execution. My question is why eax would store syscall, not ebx? Why ecx stores things we want to print on the screen? Is there some technical differences between eax and ebx, or this is simply a naming convention? If it is, where is the table "register name - function" stored?

Thanks

That's a system specific thing, so you have to read the manual of your operating system. What you describe looks like a Linux system call. Those are well documented . The software interrupt by itself has no semantics with regard to the registers, but the OS will tell you what data it expects in the various registers and on the stack and how it communicates the result.

Here is what your program do :

; print a byte to stdout
mov eax, 4           ; the system interprets 4 as "write"
mov ebx, 1           ; standard output (print to terminal)
mov ecx, buffer      ; pointer to the value being passed
mov edx, 1           ; size of the buffer
int 0x80             ; call the kernel

Atfer that it is system specific ...

Like it is said in the following document for linux system calls, the sys_call numbers are stored in eax .

I would suggest to take a look at this very good document : http://docs.cs.up.ac.za/programming/asm/derick_tut/syscalls.html

The numbers of the system calls will be put in register eax . The other values are put into the remaining registers before calling the software interrupt int 0x80 . After each syscall, an integer is returned in eax .

To answer specically :

My question is why eax would store syscall, not ebx?

It is system specific. The system define that it should be like that, so it is.

Why ecx stores things we want to print on the screen?

Same thing...

Is there some technical differences between eax and ebx, or this is simply a naming convention?

  • EAX - Accumulator Register
  • EBX - Base Register
  • ECX - Counter Register
  • EDX - Data Register
  • ESI - Source Index
  • EDI - Destination Index
  • EBP - Base Pointer
  • ESP - Stack Pointer

Source : http://www.swansontec.com/sregisters.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM