The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: SteveAsm on January 11, 2012, 04:27:50 PM

Title: HIWORD/LOWORD macro error
Post by: SteveAsm on January 11, 2012, 04:27:50 PM
Hey guys,
I'm having a problem with a pair of HIWORD/LOWORD macros that work when using Masm32, but, generate an error with jwasm.
Quote
Test1.asm(443) : Error A2209: Syntax error: LOWORD
Test1.asm(448) : Error A2209: Syntax error: HIWORD
Here are the macros:

ifndef HIWORD
    _hiword macro a
        mov  eax, a
        shr  eax, 16
        and  eax, 0FFFFH
    endm
    HIWORD    equ    _hiword
endif
;-----------------------------------------
ifndef LOWORD
    _loword macro a
        mov  eax, a
        and  eax, 0FFFFH
    endm
    LOWORD    equ    _loword
endif
;-----------------------------------------


The calling code looks like this:

  LOWORD  fcoord
  mov  iCOL, eax
;
  HIWORD  fcoord
  mov  iROW, eax
;


bare in mind that this code does work with Masm/Masm32
Title: Re: HIWORD/LOWORD macro error
Post by: dedndave on January 11, 2012, 05:59:30 PM

Unsigned versions:

LoWord:
        movzx   eax,word ptr SomeDword

HiWord:
        movzx   eax,word ptr SomeDword+2

Sign-extended versions:

LoWord:
        movsx   eax,word ptr SomeDword

HiWord:
        movsx   eax,word ptr SomeDword+2
Title: Re: HIWORD/LOWORD macro error
Post by: jj2007 on January 11, 2012, 07:11:08 PM
Dave's solution is a lot more elegant, but apart from that, I don't get an error message from JWasm. Which version are you using? I have 2.07 pre of 2 November.

include \masm32\include\masm32rt.inc

ifndef HIWORD
    _hiword macro a
        mov  eax, a
        shr  eax, 16
        and  eax, 0FFFFH
    endm
    HIWORD    equ    _hiword
endif

ifndef LOWORD
    _loword macro a
        mov  eax, a
        and  eax, 0FFFFH
    endm
    LOWORD    equ    _loword
endif

.data
fcoord dd 00FF00FEh
iCOL dd ?
iROW dd ?

.code
start:
LOWORD  fcoord
mov  iCOL, eax

HIWORD  fcoord
mov  iROW, eax
print str$(iCOL), "=col", 13, 10
print str$(iROW), "=row", 13, 10
exit

end start
Title: Re: HIWORD/LOWORD macro error
Post by: SteveAsm on January 11, 2012, 07:33:31 PM
Dave, your code does work, (when used on its own), but, it does not solve the macro issue.

Quote from: jj2007 on January 11, 2012, 07:11:08 PM
... I don't get an error message from JWasm.
Which version are you using? I have 2.07 pre of 2 November.

I'm using v-2.06.
And I know why you don't get an error. It's because you are using Masm32.

include \masm32\include\masm32rt.inc


Try using jwasm without masm32rt.inc.

These are my includes:

    include C:\...\JWasm206\Include\windows.inc
    include C:\...\JWasm206\Include\stdio.inc
    include C:\...\JWasm206\Include\stdlib.inc
    include C:\...\JWasm206\Include\CommCtrl.inc
    include C:\...\JWasm206\Include\commdlg.inc
    include C:\...\JWasm206\Include\oleauto.inc
    include C:\...\JWasm206\Include\windowsx.inc
    include C:\...\JWasm206\Include\math.inc


Please bare in mind, that unless Steve (Hutch) removes the constraints he has imposed on the usage of Masm32, I can not use Masm32 in my project.
Title: Re: HIWORD/LOWORD macro error
Post by: jj2007 on January 11, 2012, 07:44:38 PM
Quote from: SteveAsm on January 11, 2012, 07:33:31 PM
I'm using v-2.06.
And I know why you don't get an error. It's because you are using Masm32.

You know so many things ::)

      .486                                      ; create 32 bit code
      .model flat, stdcall                      ; 32 bit memory model
      option casemap :none                      ; case sensitive


ifndef HIWORD
echo HI
    _hiword macro a
        mov  eax, a
        shr  eax, 16
        and  eax, 0FFFFH
    endm
    HIWORD    equ    _hiword
endif

ifndef LOWORD
echo LO
    _loword macro a
        mov  eax, a
        and  eax, 0FFFFH
        mov eax, 123
    endm
    LOWORD    equ    _loword
endif

.data
fcoord dd 00FF00FEh
iCOL dd ?
iROW dd ?

.code
start:
LOWORD  fcoord
mov  iCOL, eax

HIWORD  fcoord
mov  iROW, eax
ret

; print str$(iCOL), "=col", 13, 10
; print str$(iROW), "=row", 13, 10
; exit

end start
Title: Re: HIWORD/LOWORD macro error
Post by: rags on January 11, 2012, 08:40:14 PM
Steve,
HIWORD and LOWORD are already defined macros in Japeths set of includes in the WINDEF.INC file.
Maybe this is the source of the problem.
Title: Re: HIWORD/LOWORD macro error
Post by: SteveAsm on January 11, 2012, 08:44:50 PM
Quote from: jj2007 on January 11, 2012, 07:44:38 PM
You know so many things ::)

::)

Quote

     .486                                      ; create 32 bit code
     .model flat, stdcall                      ; 32 bit memory model
     option casemap :none                      ; case sensitive


ifndef HIWORD
<snip>


Yes, your example works...,
because it appears that the problem stems from somewhere in windows.inc, which was not included in your sample.

Try this code, adjusting your path to include jwasm's windows.inc:

     .486                                      ; create 32 bit code
     .model flat, stdcall                      ; 32 bit memory model
     option casemap :none                      ; case sensitive


include \..\JWasm206\Include\windows.inc
;        /\.....adjust path to your system

ifndef HIWORD
echo HI
   _hiword macro a
       mov  eax, a
       shr  eax, 16
       and  eax, 0FFFFH
   endm
   HIWORD    equ    _hiword
endif

ifndef LOWORD
echo LO
   _loword macro a
       mov  eax, a
       and  eax, 0FFFFH
       mov eax, 123
   endm
   LOWORD    equ    _loword
endif

.data
fcoord dd 00FF00FEh
iCOL dd ?
iROW dd ?

.code
start:
LOWORD  fcoord
mov  iCOL, eax

HIWORD  fcoord
mov  iROW, eax
ret

; print str$(iCOL), "=col", 13, 10
; print str$(iROW), "=row", 13, 10
; exit

end start



Title: Re: HIWORD/LOWORD macro error
Post by: SteveAsm on January 11, 2012, 08:48:54 PM
Quote from: rags on January 11, 2012, 08:40:14 PM
Steve,
HIWORD and LOWORD are already defined macros in Japeths set of includes in the WINDEF.INC file.
Maybe this is the source of the problem.

Ahhh!  :'(
That's got to be the problem. Damn!
I looked everywhere and couldn't find it.
Thanks rags.    :clap: 
Title: Re: HIWORD/LOWORD macro error
Post by: SteveAsm on January 11, 2012, 08:59:35 PM
Okay...,
now that we know where the macros are defined, how do you use them ?
Because, they generate an error with the above examples.

Title: Re: HIWORD/LOWORD macro error
Post by: dedndave on January 11, 2012, 09:04:11 PM
not sure how they are defined - lol
but, here's how i would have done it - for maximum flexibility

LOWORD  TEXTEQU <word ptr>
HIWORD  TEXTEQU <word ptr 2+>


        movzx   edx,HIWORD wParam

or
        mov     HIWORD LocalDword,25h

:bg

maybe you can make your own as above and call them "LoWord" and "HiWord"
Title: Re: HIWORD/LOWORD macro error
Post by: rags on January 11, 2012, 09:12:36 PM
They seem to be compile time macros working with only constants. Probably youll have to do as Dave suggests.
Title: Re: HIWORD/LOWORD macro error
Post by: SteveAsm on January 11, 2012, 09:13:34 PM

LOWORD macro l
exitm <( ( l ) ) >
endm
HIWORD macro l
exitm <( ( ( ( l )  shr  16 )  and  0FFFFh ) ) >
endm


Quote from: dedndave on January 11, 2012, 09:04:11 PM
not sure how they are defined - lol
...
maybe you can make your own as above and call them "LoWord" and "HiWord"

I think you are right Dave, I just might do that.  :thumbu

Edit:
Dave, I did as you suggested  (call them "LoWord" and "HiWord") and it all works fine now.
Thanks guys, I appreciate the discussion.  :U
Title: Re: HIWORD/LOWORD macro error
Post by: hutch-- on January 11, 2012, 10:01:04 PM
Steve,

> Please bare in mind, that unless Steve (Hutch) removes the constraints he has imposed on the usage of Masm32, I can not use Masm32 in my project

I have the same debt to Open Watcom /Open Source/ GPL etc ... as it has to me, zero.

Please bare in mind that if you hold your breath waiting for the MASM32 project being given to the Open Source brigade, you may suffocate. MASM32 will always be freeware, not open "Sauce".  :bg
Title: Re: HIWORD/LOWORD macro error
Post by: SteveAsm on January 11, 2012, 10:27:28 PM
Quote from: hutch-- on January 11, 2012, 10:01:04 PM
Please bare in mind that if you hold your breath waiting for the MASM32 project being given to the Open Source brigade, you may suffocate.

Hutch,
don't get me wrong, I commend you for the work you have done compiling and coding Masm32.
I love programming with Masm32.
It's always been my first choice.
I feel I'm having to reinvent the wheel by not using it.

My remark was aimed at deterring the off-hand suggestion that I just simply use Masm32, instead (as has been suggested before).
Since my project is open source, I can't very well infringe on your wishes that Masm32 not be used in that way.
No offense intended.  :wink
Title: Re: HIWORD/LOWORD macro error
Post by: jj2007 on January 12, 2012, 01:02:34 AM
Is mov iROW, HiWord(fcoord) ok?

Works with JWasm and Masm.

.486 ; create 32 bit code
.model flat, stdcall ; 32 bit memory model
option casemap :none ; case sensitive

include \JWasm\WinInc\Include\WINDOWS.INC
include LoHiMacs.asm

; include \masm32\macros\macros.asm ; incompatible with JWinInc

.data
fcoord dd 00FF00FEh
iCOL dd ?
iROW dd ?

.code
start: mov iCOL, LoWord(fcoord)
mov iROW, HiWord(fcoord)
ret
end start

Title: Re: HIWORD/LOWORD macro error
Post by: SteveAsm on January 12, 2012, 02:54:59 PM
Quote from: jj2007 on January 12, 2012, 01:02:34 AM
Is mov iROW, HiWord(fcoord) ok?

Yes, I like that. Very clean.  :wink