hello, I trying to translate some 16-bit code to 32-bit and need to know the best way
to put the value in DX:AX into a 32-bit register, also to do the reverse.
thanks :)
Posted on 2007-07-09 20:21:34 by jack
The accepted interpretation of DX:AX is that DX would be the high word and AX would be the low word.

One way to transfer a low word to a high word in a 32-bit register is to shift it by 16 bits, i.e.
shl edx,16


You can then overwrite the low word with any other low word, i.e.
mov dx,ax


And the above would have transferred the DX:AX value into the EDX 32-bit register.

To do the reverse, transfer the low word into any other low word, i.e. assuming that your 32-bit value is in EDX
mov ax,dx
or, if you need the high word of EAX to be zero
movzx eax,dx


Then shift the high word back into the low word, i.e.
shr edx,16


Raymond
Posted on 2007-07-09 20:40:13 by Raymond
it just occured to me you could also push DX and AX and then pop into 32-bit register, but which 16-bit register do you push first?
also what about xchg?
Posted on 2007-07-09 21:01:19 by jack
First push the High Order Word of the DWORD value and then the Low Order Word. For example:

  MOV     AX , 0xAAAA
  MOV    DX , 0xFFFF
  PUSH    DX
  PUSH    AX
  POP    ECX
  ; ECX = 0xFFFFAAAA


AX will be the Low Order Word of ECX and DX its High Order Word so DX is pushed onto the stack first.

Posted on 2007-07-09 21:29:16 by XCHG
thanks XCHG :)
Posted on 2007-07-09 21:38:24 by jack
push/push/pop is going to be slow... and partial register access isn't too good either. Another alternative would be

shl eax, 16
shld edx, eax, 16

or

and eax, 0FFFFh
shl edx, 16
or edx, eax


But what are you aiming for anyway, speed or size? :)
Posted on 2007-07-10 06:23:42 by f0dder
speed of course :)
Posted on 2007-07-10 08:47:01 by jack