Code: Select all
mov [ds:cx],0xee
Code: Select all
error: invalid effective address
Code: Select all
mov [es:bx],0xff
Code: Select all
mov [ds:cx],0xee
Code: Select all
error: invalid effective address
Code: Select all
mov [es:bx],0xff
In real mode, only a subset of the available registers can be used for address formation. Read the memory addressing section of the Real_Mode wiki page for more details, or look up the mod r/m byte and its role in addressing.Isaac wrote:Notice how I used BX instead. But, what is the difference between these two lines? Why does NASM only complain about the first one? Can't I set any register to whatever I want? Why does it make a difference which one I use?
Code: Select all
and ecx, 0xffff
mov ax, [ecx]
Code: Select all
mov ax, [eax *4 +ecx] ;valid as long as eax*4+ecx <=64k
Right -- all of the 32 bit registers, and the addressing modes you can form using them, are available in Real Mode; it just costs you a prefix byte, and you still have to stay within 64K segment limits. I probably should have clarified that I was speaking only about standard 16-bit addressing, where the register choices are limited to what the 8086 offered.azblue wrote:However, I'm fairly certain you can use ECX and all the other addressing modes you're used to even in Real Mode, so long as you don't cross 64K boundaries.
For example:
OrCode: Select all
and ecx, 0xffff mov ax, [ecx]
Code: Select all
mov ax, [eax *4 +ecx] ;valid as long as eax*4+ecx <=64k
However, I'm fairly certain you can use ECX and all the other addressing modes you're used to even in Real Mode, so long as you don't cross 64K boundaries.
Just wanted to ask a question about this (too small for another thread), isn't the 386 Real Mode same as the Protected Mode just that the segment64K boundaries
16-bit mode didn't quite have "general purpose" registers, but rather many were designed for a certain task. To make typical instructions shorter, they removed AX, CX and DX from addressing modes, and replaced them with the composites BX+SI and BX+DI so you can have a separate pointer and index in a register.Isaac wrote:Can't I set any register to whatever I want? Why does it make a difference which one I use?
Yup, in unreal mode you're no longer limited to the 64K boundaries; you can use all the normal 32-bit addressing modes you'd have in protected mode with no restrictions.sid123 wrote: Just wanted to ask a question about this (too small for another thread), isn't the 386 Real Mode same as the Protected Mode just that the segment
limits are 64KB, plus memory protection schemes are not available,
I think there is a hack which switches to protected mode and streches the segment limits to 4GB (?), so that you can access more that 1MB?
EDIT : Whoops sorry for being too ignorant, the hack was unreal mode.
You can store whatever you want in EAX, even while in real mode; you just have to stick to under 64K if you use it to access memory.Isaac wrote:So certain registers can't do certain things. Hmm... interesting. And I can use EAX in real mode, but I just won't be able to store a value over 0xffff. Right?
Code: Select all
mov eax, 0x12345678 ;this is OK in real mode
mov ebx, [eax] ;this is NOT OK in real mode, because EAX < 64K
The history is that the original 8086 could only access memory through bx, si, di, bx+si or bx+di, maybe with an offset added, such as bx+si + 8. The old timers such as me, still tend to rely upon those three registers, even though I know the others are available in protected mode.Isaac wrote:Why doesn't th CPU let me use other registers (like CX)? Is there some history behind that?
Almost -- any one, two, or all three of (bx or bp) + (si or di) + offset.mathematician wrote:The history is that the original 8086 could only access memory through bx, si, di, bx+si or bx+di, maybe with an offset added, such as bx+si + 8.