News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

UASM 2.41 Release + WinInc 2.09

Started by johnsa, September 29, 2017, 10:30:05 PM

Previous topic - Next topic

aw27

Quote from: habran on September 30, 2017, 07:46:01 PM
I have found what was wrong, will be fixed soon and I'll post the exe here as soon as I fix it because I don't believe that John will be available tonight (OZ time)
That was very good find aw27 :t
as you know we see what we want to see but it doesn't have to be a common  reality :biggrin:

For the 64 bit case, if we have a frame, even if not needed, it will assemble the record correctly:  :badgrin:


main proc
LOCAL someVar : dword
mov someVar, 1
; Now assemble the record correctly
mov rax, _FP64<0, 400h, 999999999999Ah>
mov someDouble.parts, rax
; and this does not work:
;mov someDouble.parts, _FP64<0, 400h, 999999999999Ah>

INVOKE printf, "Value %f", someDouble.number ; expected to print 3.2
ret
main endp



habran

now this assembles properly:

--- awrec.asm ------------------------------------------------------------------
     1: includelib msvcrt.lib
     2:
     3: OPTION LITERALS:ON
     4:
     5: printf proto :ptr, :vararg
     6:
     7: _FP32 RECORD sign:1, exponent:8, mantissa:23
     8: FP32_t UNION
     9: parts _FP32 <>
    10: number REAL4 ?
    11: FP32_t ENDS
    12:
    13: .data
    14: someFloat FP32_t <>
    15:
    16: .code
    17:
    18: main proc
00007FF750E61010 55                   push        rbp 
00007FF750E61011 48 8B EC             mov         rbp,rsp 
00007FF750E61014 48 83 EC 10          sub         rsp,10h 
    19: LOCAL _real8 : REAL8
    20: ; This works ...
    21: mov ecx, _FP32<0, 80h, 4ccccdh> ; but why need a 64-bit register for a 32-bit record?
00007FF750E61018 B9 CD CC 4C 40       mov         ecx,404CCCCDh 
    22: mov someFloat.parts, ecx
00007FF750E6101D 89 0D DD 3F 00 00    mov         dword ptr [someFloat (07FF750E65000h)],ecx 
    23: ; This does not work:
    24: mov someFloat.parts, _FP32<0, 80h, 4ccccdh>
00007FF750E61023 C7 05 D3 3F 00 00 CD CC 4C 40 mov         dword ptr [someFloat (07FF750E65000h)],404CCCCDh 
    25:
    26: fld someFloat.number
00007FF750E6102D D9 05 CD 3F 00 00    fld         dword ptr [someFloat (07FF750E65000h)] 
    27: fstp _real8
00007FF750E61033 DD 5D F8             fstp        qword ptr [_real8] 
    28: INVOKE printf, "Value %f", _real8 ; expected to print 3.2
00007FF750E61036 48 83 EC 20          sub         rsp,20h 
00007FF750E6103A 48 8B 55 F8          mov         rdx,qword ptr [_real8] 
00007FF750E6103E 48 8D 0D C8 3F 00 00 lea         rcx,[__ls2393 (07FF750E6500Dh)] 
00007FF750E61045 E8 18 10 00 00       call        printf (07FF750E62062h) 
00007FF750E6104A 48 83 C4 20          add         rsp,20h 
    29: ret
00007FF750E6104E 48 83 C4 10          add         rsp,10h 
00007FF750E61052 5D                   pop         rbp 
00007FF750E61053 C3                   ret 
--- No source file -------------------------------------------------------------
Cod-Father

habran

Interesting enough, that last one
QuoteFor the 64 bit case, if we have a frame, even if not needed, it will assemble the record correctly:  :badgrin:
causes uasm to break in :dazzled:
What did you mean with " if we have a frame"?

Cod-Father

habran

Can you give me a complete source please of the last one?
Cod-Father

nidud

#19
deleted

habran

Cod-Father

habran

aw27, here is fixed uasm.exe for the first part
I don't have enough info for the second part
Cod-Father

aw27

Quote from: habran on September 30, 2017, 08:33:31 PM
Can you give me a complete source please of the last one?

Sure:



includelib \masm32\lib64\msvcrt.lib

OPTION LITERALS:ON

printf proto :ptr, :vararg

_FP64 RECORD sign:1, exponent:11, mantissa:52
FP64_t UNION
parts _FP64 <>
number REAL8 ?
FP64_t ENDS

.data
someDouble FP64_t <>

.code

main proc
LOCAL someVar : dword
mov someVar, 1
; This assemble the record correctly when there is a frame as we have here now
mov rax, _FP64<0, 400h, 999999999999Ah>
mov someDouble.parts, rax
; and this does not work:
;mov someDouble.parts, _FP64<0, 400h, 999999999999Ah>

INVOKE printf, "Value %f", someDouble.number ; expected to print 3.2
ret
main endp


end main

habran

Let me know what is wrong here:
sorry, I was watching a movie (Witness, with Harrison Ford) with one eye
I can see what is wrong now

--- awrec.asm ------------------------------------------------------------------
     1:
     2: includelib msvcrt.lib
     3:
     4: OPTION LITERALS:ON
     5:
     6: printf proto :ptr, :vararg
     7:
     8: _FP64 RECORD sign:1, exponent:11, mantissa:52
     9: FP64_t UNION
    10: parts _FP64 <>
    11: number REAL8 ?
    12: FP64_t ENDS
    13:
    14: .data
    15: someDouble FP64_t <>
    16:
    17: .code
    18:
    19: main proc
00007FF6FB5F1010 55                   push        rbp 
00007FF6FB5F1011 48 8B EC             mov         rbp,rsp 
00007FF6FB5F1014 48 83 EC 10          sub         rsp,10h 
    20: LOCAL someVar : dword
    21: mov someVar, 1
00007FF6FB5F1018 C7 45 FC 01 00 00 00 mov         dword ptr [someVar],1 
    22: ; This assemble the record correctly when there is a frame as we have here now
    23: mov rax, _FP64<0, 400h, 999999999999Ah>
00007FF6FB5F101F 48 B8 9A 99 99 99 99 99 09 40 mov         rax,400999999999999Ah 
    24: mov someDouble.parts, rax
00007FF6FB5F1029 48 89 05 D0 3F 00 00 mov         qword ptr [someDouble (07FF6FB5F5000h)],rax 
    25: ; and this does not work:
    26: ;mov someDouble.parts, _FP64<0, 400h, 999999999999Ah>
    27:
    28: INVOKE printf, "Value %f", someDouble.number ; expected to print 3.2
00007FF6FB5F1030 48 83 EC 20          sub         rsp,20h 
00007FF6FB5F1034 48 8B 15 C5 3F 00 00 mov         rdx,qword ptr [someDouble (07FF6FB5F5000h)] 
00007FF6FB5F103B 48 8D 0D D8 3F 00 00 lea         rcx,[__ls2393 (07FF6FB5F501Ah)] 
00007FF6FB5F1042 E8 19 10 00 00       call        printf (07FF6FB5F2060h) 
00007FF6FB5F1047 48 83 C4 20          add         rsp,20h 
    29: ret
00007FF6FB5F104B 48 83 C4 10          add         rsp,10h 
00007FF6FB5F104F 5D                   pop         rbp 
00007FF6FB5F1050 C3                   ret 
--- No source file -------------------------------------------------------------

That is actually not wrong:
1>awrec.asm(26): error A2055: Initializer value too large
because only GPR 64 bit registers can accept 64 bit constant unfortunately, you should complain to INTEL ;)
So, uasm is not letting you get wrong data
It took me several hours to actually make that happen, here is the code from expreval.c:

                    if (recordsym && recordsym->sym.typekind == TYPE_RECORD)
{
if ( InitRecordVar( opnd1, curr_operator, tokenarray, recordsym, NULL ) != ERROR )
                          if (tokenarray[1].token == T_REG) {
                            p=tokenarray->tokpos + 3;
                            while (isspace(*p))p++;
                            if (*p == 'r' || *p == 'R')
rc = NOT_ERROR;
                            else goto testsize;
                        }else
testsize:                 if (opnd1->llvalue < 0x100000000){
                          rc = NOT_ERROR;
                          }
                          else {
                           rc = ERROR;
                          EmitErr(INITIALIZER_OUT_OF_RANGE);
                          }
   return( rc );
                    }
                    else
  OperErr( curr_operator, tokenarray );
                  }
                break;

Cod-Father

habran

that is what would happen if I let it happen:

    26: mov someDouble.parts, _FP64<0, 400h, 999999999999Ah>
00007FF6A40E1030 48 C7 05 C5 3F 00 00 9A 99 99 99 mov         qword ptr [someDouble (07FF6A40E5000h)],0FFFFFFFF9999999Ah 

INTEL extends 32 bit to this: 0FFFFFFFF9999999Ah instead of 400999999999999Ah
that happens with all instructions except MOV GPR64,64BITVALUE
not even CMP RAX, 400999999999999Ah would work, so you have to do this:
MOV RCX,400999999999999Ah
CMP RAX,RCX
but I am sure you are aware of that
so that uasm64.exe above is now wrking as it is supposed to 8)
Cod-Father

aw27

Quote from: habran on September 30, 2017, 11:59:45 PM
1>awrec.asm(26): error A2055: Initializer value too large
because only GPR 64 bit registers can accept 64 bit constant unfortunately, you should complain to INTEL ;)
So, uasm is not letting you get wrong data
Damn, I was expecting some behind the scene magic from UAsm to make it happen. :(

habran

We could have done that magic behind the scene but it would be more appropriate to do it with a sleight of hand what you have done already :lol::

    23: mov rax, _FP64<0, 400h, 999999999999Ah>
00007FF66074101F 48 B8 9A 99 99 99 99 99 09 40 mov         rax,400999999999999Ah 
    24: mov someDouble.parts, rax
00007FF660741029 48 89 05 D0 3F 00 00 mov         qword ptr [someDouble (07FF660745000h)],rax

because this is exactly what we would have to do behind the scene ;)
IMAO that sleight of hand is already more than any other assembler can do 8)
Cod-Father

aw27

IYAO, is the presence of a frame necessary to make mov rax, _FP64<0, 400h, 999999999999Ah> work then? Or you just forgot that detail?

habran

which frame? :dazzled:
Try that uasm64.exe above and see if works as you expect, if not give me wrong code.
Cod-Father

aw27

Quote from: habran on October 01, 2017, 12:03:50 PM
which frame? :dazzled:
Try that uasm64.exe above and see if works as you expect, if not give me wrong code.

You can't really see the differences in spite of my supply of complete examples.  :(

Let me try again:
1)
   ; This does not assemble the record correctly <-------------
   mov rax, _FP64<0, 400h, 999999999999Ah>

What I meant is that the value that goes to rax is not correct.

2)

   LOCAL someVar : dword
   mov someVar, 1
   mov rax, _FP64<0, 400h, 999999999999Ah>

Here the value that goes into rax is correct. The existence of a frame, i.e, LOCAL someVar:dword, made a difference in spite of being apparently irrelevant for the case.