I'm trying to figure out how to work with 16-bit values in 32-bit spaces because some functions need to use the space as 32-bit but I only use 16-bit numbers.
In this code example, we assume I'm calling DOS interrupt 2Fh with function 0 (AX=0) and we assume function treats the internal 32-bit value aval as a size to a string (for example).
The values I want to use are all 16-bit so I want to be able to load a 16-bit value in and retrieve a 16-bit value from the same variable after the interrupt is executed.
The safest approach is with the code below:
myfunction:
xor EAX,EAX
mov AX,CX
mov [CS:aval],EAX
xor AX,AX
int 2Fh
mov EAX,[CS:aval]
mov CX,AX
ret
aval dd 0h ;32-bit storage space that an interrupt requires
;because interrupt checks ALL 32 bits, not just part.
I thought of replacing the above with one of these fragments, but the endianness of the intel processors sometimes confuse me because in some instances, values are stored backwards.
Here's idea 1 of shorter code:
myfunction:
mov [CS:aval],CX
xor AX,AX
int 2Fh
mov CX,[CS:aval]
ret
aval dd 0h
Here's idea 2 of shorter code:
myfunction:
mov [CS:aval+2],CX
xor AX,AX
int 2Fh
mov CX,[CS:aval+2]
ret
aval dd 0h
So which of my 2 ideas would work best? or is there a better idea? This code fragment will be part of an MS-DOS COM file when compiled.