The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: boydtbk on June 07, 2010, 12:27:24 PM

Title: help me about highword
Post by: boydtbk on June 07, 2010, 12:27:24 PM
I'm using MASM32 SDK verison 10, and I have a problem with highword:

            val dd 10101011b
            mov val, HIGHWORD val


error A2105: HIGH and LOW require immediate operands
Can some body help me?
Title: Re: help me about highword
Post by: dedndave on June 07, 2010, 12:35:20 PM
i have never used HIGHWORD
but, you can't do memory to memory MOV that way
try getting the value into a register first
        movzx   eax,word ptr val+2   ;same as HIGHWORD ?
        mov word ptr val,ax

i think that's what you are trying to do   :P
Title: Re: help me about highword
Post by: boydtbk on June 07, 2010, 05:21:59 PM
and about lowword ? I don't know exactly what I have to do. Can you show me ?
Title: Re: help me about highword
Post by: jj2007 on June 07, 2010, 05:48:32 PM
movzx   eax, word ptr val is the low word
movzx   eax, word ptr val+2 is the high word
Title: Re: help me about highword
Post by: GregL on June 07, 2010, 09:31:06 PM
boydtbk,

I prefer to write it as


movzx   eax, word ptr val+0  ;is the low word
movzx   eax, word ptr val+2  ;is the high word


just for clarity.


Title: Re: help me about highword
Post by: clive on June 09, 2010, 03:42:15 PM
The typical usage for LOWWORD/HIGHWORD is as follows

= DEADBEEF val     EQU     0DEADBEEFh

0000  B8 BEEF         mov     ax,LOWWORD val
0003  BA DEAD         mov     dx,HIGHWORD val


They are designed to handle immediate values (ie EQU, or simple constants/math)

As for style, I'd prefer this if you are pulling high/low values from memory


value  dd  0DEADBEEFh
;...
movzx   eax, word ptr value[0] ; is the low word
movzx   edx, word ptr value[2] ; is the high word