commodorejohn
Veteran Member
I'm picking up one of my projects again, developing a game engine with DOS as one of the target platforms. Unlike the other targets, which are written in C with SDL, the DOS version is actually a reimplementation in 32-bit assembly language. The bit I'm currently working on is the bytecode interpreter by which game code is executed, and I'm trying to figure out the best way to implement a couple of instructions which use 11-bit constants, with the high three bits embedded in the opcode.
What I've got now is as follows:
But the opcode is already in AL, so I can see a way to eliminate an instruction here:
However: I've heard tell of undefined behavior from CPU to CPU with the LODSB/LODSW instructions, regarding whether they clear the high bits of AX/EAX or leave them unmolested. But I'm having trouble confirming this. Does anybody know if this is really the case or not? The performance gain from this would hardly be significant enough to risk undefined behavior over, but every little bit counts, and in any case I'd like to know for certain.
What I've got now is as follows:
Code:
; ESI currently points to the location immediately after the instruction
dec esi ; roll back a space
lodsw ; get a word, not a byte
xchg al, ah ; swap the byte order
bc_extendlong eax ; macro: sign-extend the lower 11 bits
But the opcode is already in AL, so I can see a way to eliminate an instruction here:
Code:
; ESI currently points to the location immediately after the instruction
xchg al, ah ; swap the byte order
lodsb ; get the low byte of the constant
bc_extendlong eax ; macro: sign-extend the lower 11 bits
However: I've heard tell of undefined behavior from CPU to CPU with the LODSB/LODSW instructions, regarding whether they clear the high bits of AX/EAX or leave them unmolested. But I'm having trouble confirming this. Does anybody know if this is really the case or not? The performance gain from this would hardly be significant enough to risk undefined behavior over, but every little bit counts, and in any case I'd like to know for certain.