I am learning assembly language and has a question regarding this. I have a bootloader in real mode where we can access memory upto 1 mb. What will happen if we request 2 byte data at the end location of 1 mb space,will it return only one byte or raise some exception? I have similar questions when we are in protected mode (paging enabled and disabled). The another question is what happens when a program tries to access address more then the physically installed memory in bare metal non paging environment? (Say accessing address 0x00FFFFFF on a 2gb machine, the address here is more than 2gb) I have read some sections of Intel's manual but they are bulky and it's really difficult to find this information.
The effect depends on a lot of things, including your CPU, other hardware, and how you try to access that last byte.
On the original 8086, accessing the last byte would wrap around to the beginning of memory.
On later CPUs (like the 80286), which support more than 1MB of memory, the access to the last byte could trigger a fault (if trying to access real mode address 0xF000:FFFF
as a 16-bit word), or (depending on if the system's A20 address line was enabled) wrap around to access physical address 0
or read the byte stored in physical address 0x100000 (at 1MB). This could be done by trying to read, for example, address 0xFFFF:000F
as a word.
With the 80386's greatly expanded protected mode, there are other considerations possible (like is the segment being addressed large enough to hold the address), but it ultimately boils down to either you get you word read or you'll get an exception.
In summary, you'll either read both bytes, or get an exception. You won't get a partial read.
As far as what value you get trying to read a physical memory address that does not exist, that depends on the hardware. If you try to read a value using a 32 bit address, but the hardware only has 24 address bits, then some of those larger logical addresses will "wrap around" and read from the lower addressed physical memory (because the higher address bits are effectively masked off with the absence of address lines to hold them). Or you could get back a 0, 0xFF, or possibly some indeterminate value that happens to be floating on the data lines.