This is weird asm syntax. It's using ()
for memory operands like AT&T syntax, but it only makes sense if it's destination on the left like Intel syntax. (It's also using AT&T-style mnemonic suffixes for operand-size, like movb
for byte mov
.)
I think it's basically NASM syntax, but with ()
instead of []
, because the comment says mov ebx, _gdt
is a mov-immediate of the address. In GAS .intel_syntax noprefix
, that would be a load like in MASM syntax.
Minix's compiler has it's own flavour of asm, and it's documented here. (Thanks @MichaelPetch).
So this is a byte-at-a-time copy loop, from es:esi
to ds:edi
, for ecx=8*8
bytes. This is exactly what the comments say it does, so that makes it easy to figure out this syntax I hadn't seen before.
movb (ebx), al
stores AL into memory, at the address in EBX. i.e. NASM mov [ebx], al
or AT&T mov %al, (%ebx)
.
The store is using the default segment selector for EBX, which is DS. You wouldn't normally need to mention segments in 32-bit mode, but notice the eseg
prefix on the load. You haven't shown, and the comments don't mention, what ES is set to, and why / how it's different from DS.
It seems the code is optimized for code-size, not speed (which is ok because it only runs once at startup). e.g. it's using the slow loop
instruction, and it copies one byte at a time so it can inc
the pointers (1 byte) instead of add esi, 4
(3 bytes). Still, I suspect that with an indexed addressing mode, you could make it just about as small but copy 4 bytes at a time. (The byte count is fixed at 8*8
, so it's always a multiple of 4.)
The loop is very close to what rep movsb
(or rep movsd
) does, which is to copy ecx
elements from DS:(E)SI
to ES:(E)DI
. (The ds
can be overridden with a segment prefix, so you could e.g. copy from fs:esi
to es:edi
). But in the Minix code, the loads are from ES:something, and movs
always uses es
as the destination segment.
fseg rep movsd
would have been even more compact (and faster) than a loop, but presumably there was some obstacle to setting up segment registers appropriately. Using EDI and ESI instead of ESI and EBX shouldn't be an obstacle.