Answer the question
In order to leave comments, you need to log in
Explain someone about registers in assembler?
Hello.
I started learning Assembler.
It is very difficult to perceive and I have a question that no one has answered yet.
Why are registers needed?
Is it like variables?
If variables are their names?
Why are there several? Rax, rbx, rcx?
Is it of type like int, char, double?
The main question here - I do not understand how they work.
For example, I wrote the following code:
format ELF64
public _start
new_line equ 0xA
msg db "WTF, Dude", new_line, 0
len = $-msg
_start:
mov eax, 4
mov rbx, 1
mov rcx, msg
mov rax, len
int 0x80
call exit
exit:
mov rdx, 1
mov rbx, 0
int 0x80
Answer the question
In order to leave comments, you need to log in
I don't have Linux to check, but the program seems to be fundamentally wrong. You are using the 32 bit calling convention on a 64 bit machine.
https://www.informatik.htw-dresden.de/~beck/ASM/sy...
https://blog.rchapman.org/posts/Linux_System_Call_...
Where is the 32-bit call on x64 from - give a prooflink, maybe it is in your linux.
Registers are small and very fast memory cells built into the processor. There are a limited number of them, and they have specific clearly fixed names.
Often, to work with data of small bits and compatibility with early code, the processor gives access to halves of the registers. So, the lower half of the rax register is eax, the lower quarter is ax, the halves of ax (respectively, the eighths of rax) are called al and ah. You understand: when the processor was 16 bits, the register was called ax = al + ah. Made 32 bits - became eax. Made 64 bits - became rax.
This calling convention is used to call Linux system functions. All functions hang on interrupt 0x80, rax is the name of the function, the rest of the parameters are sorted into registers.
About int, char, double. Signedness (signed/unsigned) is determined by assembler instructions (e.g. ja = jump if above for unsigned, jg = jump if greaterfor signed). The length is the part of the register involved (rax = long long, eax = int/long, ax = short, al = char). Fractional numbers are handled by a separate processor unit, the so-called. a coprocessor with its own registers (in the first x86 it was a separate chip that did not exist in all computers, hence the name).
A register is a hardware static memory location within a processor that has been given a name. And there are commands or subroutines that do something with the value from this register. In the example, the command int 80h (software interrupt) executes a system call, which, depending on the values in specific registers (should be described in the system documentation, what to put where), does one thing or another. Accordingly, you just need to look at the documentation and find this description in it, and then you will figure it out.
Registers are not variables. These are memory cells in the processor. They can't be named after the bullshit, like variables in high-level languages. Because these are specific physical cells, which are assigned some letter names.
They can be used for a variety of purposes, and depending on the purpose for which they are used at a particular moment, they need to be "put" in a variety of ways.
What specifically needs to be put there depends on what command you are going to execute.
What exactly and where exactly to put - it is written, surprise, in the documentation. By rewriting the code from the bulldozer, you will never be able to learn Assembler, there you must first understand what you are doing, and then do it.
It is easier to understand what MP registers are using the example of a person. A register is a hand in which the processor takes a number in order to do something with it later (add, multiply, or simply write somewhere). Modern microprocessors have approximately 5 to 50 such registers.
The work with registers occurs at the clock frequency of the processor. This is the fastest "memory", although calling a register a memory is the same as calling a person's hand a storage shelf. Of course, the hand can serve as a shelf for some time, but this is very irrational.
Below the registers in terms of speed is the processor cache, the programmer does not have a direct opportunity to access the cache, it is just for storing frequently used information. Even lower in speed is RAM, it can be accessed from a program, for example, write a number from a register to a RAM cell. Even lower so-called. "external" memory. This is where files are stored - hard drive, flash drives, etc.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question