Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What’s the difference between eax ebx ecx in assembly

I’m trying to learn some assembly, but I have a hard time understanding what some basic things do. Are EAX, EBX, and ECX just variables or do they all have a unique specific use other than storing values?

like image 278
Fritiof Rusck Avatar asked Dec 22 '22 20:12

Fritiof Rusck


2 Answers

eax, ebx, ecx and so on are actually registers, which can be seen as "hardware" variables, somewhat similar to higher level-language's variables. Registers can be used in your software directly with instructions such as mov, add or cmp. The leading e stands for extended and means that your register is 32 bits wide. On the other hand, 64-bit registers begin with r.

These registers are not always used for the purposes illustrated below. This graphic shows the register usage for Linux 64-bit ABI.

Linux 64-bit ABI

Not all registers are described in this capture though. For instance *ipis a special register (process counter) that holds the next instruction to be executed.

You can find the full ABI there. Some information is specific to Linux but most remains relevant for any POSIX-compliant system.

like image 148
Maxime B. Avatar answered Dec 26 '22 12:12

Maxime B.


The EAX, EBX, ECX, EDX, EBP, EDI, and ESI registers are all 32-bit general-purpose registers, used for temporary data storage and memory access.

https://web.archive.org/web/20191114093028/https://gerardnico.com/computer/cpu/register/general

Some of CPU instructions modify specific registers. For instance, movsb takes Source address from ESI and Destination from EDI, copies one byte and changes ESI and EDI registers.

In other words, you could use them as variables, but they also might have a specific purpose when using specific instructions.

You may want to consult the reference. Both Intel and AMD provide manuals, available online.

like image 23
rtxndr Avatar answered Dec 26 '22 11:12

rtxndr