Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the "MOV" instruction in Assembly to allocate memory?

Tags:

assembly

I notice that MOV is supposed to copy and overwrite data to and from registers, but if there's no present data in any other register, does MOV move a certain sized byte(s) from RAM to the register to temporarily hold it, or how does this work exactly?

To clarify my question, say I use:

MOV AL, 0x10;

In such a case, where is the "10" digit data that is moved to the 8-bit register?

Is this moved from RAM to AL as eight bits to hold, or is the "10" byte just a scratchpad number that is not in memory?

I don't understand this, and it would be amazing if someone could straighten this out.

My problem is that I need to know where and how much memory is used, and how and what exactly is addressing it(and tutorials don't make clear of this).

like image 809
Lester Bonker Avatar asked Dec 11 '22 19:12

Lester Bonker


1 Answers

Guessing at the mental block: it is important to understand that RAM both contains code and data. The value 0x10 comes from code. It was encoded into the machine code instruction by the assembler. That code got loaded into RAM by the operating system when it started executing your code.

Notable is that it is not a variable, the instruction will always load 0x10, regardless of the state of your program. Other parts of RAM store the data that you declared in your assembly program. Like the .data and .stack sections. But is not otherwise used by this particular instruction.

Adding to the possible confusion: it doesn't have to be in RAM. On embedded systems without an operating system or boot drive, the code is often burned into ROM instead. The processor doesn't otherwise care about it, it just reads bytes from a memory bus, using the EIP register (the instruction pointer) to tell the memory sub-system what bytes it needs.

like image 63
Hans Passant Avatar answered Jan 16 '23 19:01

Hans Passant