Master the fundamental concepts of real mode programming through this focused micro-challenge.
You have read the whole brief, and the concepts above stay free on every task. Writing and running the code needs a plan.
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it worksLODSB loads from DS:SI, STOSB stores to ES:DI, MOVSB copies byte from DS:SI to ES:DI, each optionally repeating with REP using CX as a counter. For example, REP MOVSB copies 80 bytes from a source buffer to 0xB8000 for a fast screen fill when direction flag is cleared.
nasmLoading…
SCASB/CMPSB for strlen and strcmpES is fixed for STOS/MOVS destinationString instructions shrink loop code dramatically inside the 510-byte budget of a boot sector. Always issue CLD before forward REP MOVSB unless you intentionally copy backward for overlapping regions. Remember that ES cannot be the same arbitrary segment as DS unless you load it; many snippets set both to the same paragraph for video memory copies to 0xB800.
You will implement memory fill and copy with REP STOSB and REP MOVSB. This exercise requires setting DS, ES, SI, DI, and CX correctly and clearing the direction flag before forward copies.
Simulate the two workhorse x86 string instructions on a 16-byte buffer that starts as all zeros. Both run forward (DF = 0):
REP STOSB stores the same byte at cnt consecutive offsets.REP MOVSB copies cnt bytes one at a time, reading the current buffer at each step. A copy to an overlapping, higher destination therefore repeats the source bytes, exactly as the real instruction does. memmove would not.Offsets behave like the 16-bit SI and DI registers in real mode: each step adds 1 modulo 0x10000, so 0xFFFF is followed by 0x0000. Only offsets 0-15 are inside the buffer. A store outside it is dropped, and a copy step whose source or destination is outside it does nothing.
A sequence of whitespace-separated commands. Every number is hexadecimal.
F off val cnt: REP STOSB, storing byte val at offsets off, off+1, ... (cnt times).M src dst cnt: REP MOVSB, copying from src to dst, cnt bytes.D: dump the buffer.For each D, one line with the 16 bytes as 32 uppercase hex digits: 11111111000000000000000000000000 after F 0 11 4 D.