Reputation: 127
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).
Upvotes: 4
Views: 3074
Reputation:
I suppose that the primary memory in your device/machine is RAM. So basically your application would be exists there at run-time (after you run that application from hard disk for example, it will be load into the device memory). By the way, all of the binary-instructions which are executable for the processor are in RAM now.
To simplify that, let say processor will start reading the memory from the very first cells, like 0, will try to understand what to do with that, and after finishing will move on to the next one which is 1 in this case and so on.
Now let say mov al, 0x10
is equal to 0xAABB
in our imaginary processor. At the physical memory, 0xAA
is stored at the cell number 20
and 0xBB
at 21
. Our processor is still busy to reading the stream. When it reaches the memory at 20
, it would load the binary value that is 0xAA
in this case. By the way, in our processor's documentation it means Fill up the AL with the Following data. The Following data in our case is 0xBB
, so the processor will do that.
As you can see:
mov al, 0x10
wasn't allocate at the run-time, but it was all hard-coded by the compiler, and stored into an executable file (for example)0xBB
is exists on the RAM, but you can't change it at the run-time. Again keep it in mind that it wasn't also created at the run-time, it was just loaded into the RAM, at run-timeI hope it helps you understand that better.
Upvotes: 2
Reputation: 1847
assembly instruction
mov al, 0x10
is equal to 0xb010
in binary
mov al, 0xff
is equal to 0xb0ff
if you are on windows you can click start - run - debug and in a debug window, write
a
[Enter]
mov al, ff
[Enter]
[Enter]
it change mov al, ff to binary
and then you can see 0xb0ff by..
u 100
[Enter]
a
mov al, ff
means 'assemble' mov al, ff and save to current location(may be 0x100)
u 100
means 'unassemble' location 0x100
Upvotes: 1
Reputation: 942518
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.
Upvotes: 6
Reputation: 44316
your code lives in RAM ie, the bytes that represent MOV AL, 0x10;
, the 0x10 is part of the instruction, its not stored seperately. Typically it wont be coming from RAM at the point of execution but a instruction pipeline on the CPU, The CPU fetches instructions from RAM into its pipelines as it see's fit.
for a great free online book on assembly try http://cs.smith.edu/~thiebaut/ArtOfAssembly/artofasm.html
chapter 4 deals with memory addressing http://cs.smith.edu/~thiebaut/ArtOfAssembly/CH04/CH04-1.html
there are a lot of concepts to get your head around, memory addressing in all its forms and how to work with the CPU architecture can seem daunting at first, but will slowly start making sense as you try stuff out.
Upvotes: 4