The MASM Forum Archive 2004 to 2012

General Forums => The Laboratory => Topic started by: Ficko on June 22, 2010, 11:30:26 AM

Title: low32
Post by: Ficko on June 22, 2010, 11:30:26 AM
I see that MASM understands "LOW32" as well but how to use it.
I can't manage to declare a constant bigger than DWORD.  ::)


.686p
.model flat, stdcall
option casemap :none
Val     EQU     12345678h
;Val     EQU     112345678h ;Error too big
.code
start:
mov eax, low32 Val
nop
end start
Title: Re: low32
Post by: dedndave on June 22, 2010, 01:13:25 PM
i think EQUates are traditionally limited to the machine width
as i recall, with old versions of MASM (5 and earlier), it had to resolve to a 16-bit integer
Title: Re: low32
Post by: jj2007 on June 22, 2010, 01:19:06 PM
mov eax, low32 (Val*12345678h) works.
Title: Re: low32
Post by: dedndave on June 22, 2010, 01:24:40 PM
oh - i suppose you could use TEXTEQU and have it resolve to other sizes   :P
or, as in Jochen's example...
MyConst TEXTEQU <low32 (Val*12345678h)>
        mov     eax,MyConst
Title: Re: low32
Post by: qWord on June 22, 2010, 01:38:31 PM
masm use internal 64Bit arithmetic for calculations on constants, but it can only emit 32Bit constants.
Title: Re: low32
Post by: Ficko on June 22, 2010, 01:43:53 PM
All right I guess since there is no "high32" anyway it is just a "dead end" command. :bg
Title: Re: low32
Post by: MichaelW on June 22, 2010, 05:09:10 PM
Perhaps is has something to do with 64-bit initializers. Even MASM 5.1 would allow statements like:

xxx dq 1234567812345678h
Title: Re: low32
Post by: dedndave on June 22, 2010, 08:35:01 PM
yah - but defining data is different than using EQUates for constants
thing is - there aren't very many (single) 32-bit instructions that allow use of 64-bit constants
the EQUates "mechanism" wasn't really designed with SSE in mind
Title: Re: low32
Post by: GregL on June 23, 2010, 02:05:10 AM
QuoteAll right I guess since there is no "high32" anyway it is just a "dead end" command. BigGrin

But, there is a HIGH32 (http://msdn.microsoft.com/en-us/library/ms235621%28VS.80%29.aspx)    (in later versions).

Title: Re: low32
Post by: clive on July 06, 2010, 06:56:55 PM
Well crap, both of these seem totally useless.

Microsoft (R) Macro Assembler Version 10.00.30319.01     07/06/10 13:53:46
...
        push    high32 400921FB54442D18h ; PI
test27.asm(23) : error A2084:constant value too large
        push    low32  400921FB54442D18h
test27.asm(24) : error A2084:constant value too large
Title: Re: low32
Post by: GregL on July 06, 2010, 07:22:30 PM
Clive,

Try

push HIGH32(400921FB54442D18h) ; PI
push LOW32(400921FB54442D18h)


[Edit] Oops, I guess not.

Here are some macros I wrote for the earlier versions of MASM.  I thought they worked the same as the ones in MASM 8.0 and later, I guess not.

; ====================================
; MASM 8.0 has a macro with the same name and function built in
LOW32 MACRO Q:REQ
    lea edx, Q
    mov eax, DWORD PTR [edx]
    EXITM <eax>
ENDM
; ====================================
; MASM 8.0 has a macro with the same name and function built in
HIGH32 MACRO Q:REQ
    lea edx, Q
    mov eax, DWORD PTR [edx+4]
    EXITM <eax>
ENDM



I'm trying to figure out what LOW32 and HIGH32 in MASM 8.0 and later are good for.

Title: Re: low32
Post by: GregL on July 06, 2010, 08:26:41 PM
Quote from: jj2007mov eax, low32 (Val*12345678h) works.

I get error A2026: constant expected on that one.  I'm using ML 10.0.

[Edit] OK, I see what he means, the following works.

mov eax, LOW32(20*12345678h)

Title: Re: low32
Post by: clive on July 06, 2010, 08:52:15 PM
Greg,

I'd tried a bunch of combinations, MASM just doesn't like direct input of constants bigger than 32-bits.

Here's what I finally got to work, but I still don't feel Microsoft really understands the point of these functions.

-Clive

Microsoft (R) Macro Assembler Version 10.00.30319.01     07/06/10 15:49:16
test27.asm      Page 1 - 1


        .686
        .MODEL FLAT

= 3.141592653589793238 PI      EQU     3.141592653589793238

00000000         .DATA

00000000  40490FDB         REAL4   PI
00000004  400921FB54442D18         REAL8   PI

00000000         .CODE

= 54442D18 _PI    EQU     ((400921FBh SHL 32) + (54442D18h)) ; PI

00000000 _start:

00000000  68 400921FB         push    high32 _PI
00000005  68 54442D18         push    low32  _PI

0000000A  C3         ret

        end         _start
Title: Re: low32
Post by: qWord on July 06, 2010, 08:57:34 PM
as said, masm internally use 64bit arithmetic. The only way I currently see is to 'calculate' the 64Bit constant from two 32Bit ones:
foo = (0cccccccch SHL 32) OR (0aaaaaaaah)
.radix 16
%echo @CatStr(%(HIGH32 foo),<_>,%(LOW32 foo))
.radix 10

:bg
Title: Re: low32
Post by: drizz on July 06, 2010, 11:17:40 PM
masm language could definitely be improved in this area.

not accepting constants for qword,real4,real8 arguments is just annoying.

myproc1 proc qw1:qword,r41:real4,r41:real8
   ret
myproc1 endp

   invoke myproc1,1,2.0,3.0



just for fun:
pushR8 macro r8:req
dq r8
org $-8
db 3 dup(02eh), 68h
org $+4
db 68h
dq r8
org $-4
endm

PI      EQU     3.141592653589793238

pushR8 PI
Title: Re: low32
Post by: jj2007 on July 07, 2010, 06:37:36 AM
Quote from: drizz on July 06, 2010, 11:17:40 PM

just for fun:
pushR8 macro r8:req
dq r8
org $-8
db 3 dup(02eh), 68h
org $+4
db 68h
dq r8
org $-4
endm

PI      EQU     3.141592653589793238

pushR8 PI


See real or BCD number not allowed (http://www.masm32.com/board/index.php?topic=14312.msg114490#msg114490) for a solution that is compatible with invoke :bg