• Please review our updated Terms and Rules here

x86 assembly language question

commodorejohn

Veteran Member
Joined
Jul 6, 2010
Messages
3,302
Location
California, USA
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:
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.
 
That's what I figured based on all the documentation I can find, I just know I read whispers of inconsistencies in later years (I want to say the Pentium Pro was named,) but now that it actually matters of course I can't find it.
 
I've had a look at some of my early 32-bit code. If LODS screwed up the upper part of the A register, it would have been broken something awful.

Code in peace.
 
Back
Top