NASM compiler remind me the following code is error, "error: instruction not supported in 16-bit mode".
[bits 16]
xor ax, ax
mov ds, ax
mov qword [ds:0x0], 0x0
But the following code is ok:
[bits 16]
xor ax, ax
mov ds, ax
mov dword [ds:0x0], 0x0
mov dword [ds:0x0], 0x0
Who can tell me the reasons, I just want to write 8 bytes of data to memory at once in 16-bit mode.
I try to set some data to memory.
To write exactly 8 bytes of data at once in real mode, your choices are:
a) The
cmpxch8binstruction, which requires a Pentium CPU or laterb) A floating point store (
fstorfstp), which requires an FPU and that it's valid for double precision floating point's encoding.c) The
movqinstruction, which requires a CPU that supports MMX.You might also be able to write more than 8 bytes (e.g. read the last 8 bytes, then write 16 bytes with
pushaso that the last 8 bytes are the same as they were previously). In that case, there's no atomicity guarantee withpusha(orpushad) so it may or may not meet your definition of "at once". There are multiple SSE and AVX stores that could work if your CPU is new enough to support them (if you do the required setup where necessary).Of course if you don't need atomicity then it's easier to just do a pair of 32-bit stores (which requires an 80386 or later CPUs), like:
..or four 16-bit stores (which will work on all 80x86 CPUs in real mode).
The other alternative is to use no instructions at all, like:
There are always limits, and 8 bytes is four times as much as "16-bit" (or 2 bytes) was originally designed for. Over the years the limits have been increased with the introduction of new features (e.g. from 16-bit to 32-bit). The last increase (up to 64-bit) couldn't be made compatible with real mode due to not having enough previously unused opcodes that could become size override prefixes (AMD literally recycled previously used opcodes to make 64-bit code viable).