News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

HIWORD/LOWORD macro error

Started by SteveAsm, January 11, 2012, 04:27:50 PM

Previous topic - Next topic

SteveAsm

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

dedndave


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

jj2007

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

SteveAsm

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.

jj2007

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

rags

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.
God made Man, but the monkey applied the glue -DEVO

SteveAsm

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




SteveAsm

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: 

SteveAsm

Okay...,
now that we know where the macros are defined, how do you use them ?
Because, they generate an error with the above examples.


dedndave

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"

rags

They seem to be compile time macros working with only constants. Probably youll have to do as Dave suggests.
God made Man, but the monkey applied the glue -DEVO

SteveAsm


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

hutch--

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
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

SteveAsm

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

jj2007

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