Author Topic: UASM 2.41 Release + WinInc 2.09  (Read 1453 times)

aw27

  • Member
  • ****
  • Posts: 854
  • Let's Make ASM Great Again!
Re: UASM 2.41 Release + WinInc 2.09
« Reply #15 on: September 30, 2017, 07:54:42 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:

Code: [Select]
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

  • Member
  • *****
  • Posts: 1116
    • uasm
Re: UASM 2.41 Release + WinInc 2.09
« Reply #16 on: September 30, 2017, 08:17:12 PM »
now this assembles properly:
Code: [Select]
--- 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

  • Member
  • *****
  • Posts: 1116
    • uasm
Re: UASM 2.41 Release + WinInc 2.09
« Reply #17 on: September 30, 2017, 08:25:27 PM »
Interesting enough, that last one
Quote
For 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

  • Member
  • *****
  • Posts: 1116
    • uasm
Re: UASM 2.41 Release + WinInc 2.09
« Reply #18 on: September 30, 2017, 08:33:31 PM »
Can you give me a complete source please of the last one?
Cod-Father

nidud

  • Member
  • *****
  • Posts: 1410
    • https://github.com/nidud/asmc
Re: UASM 2.41 Release + WinInc 2.09
« Reply #19 on: September 30, 2017, 08:35:26 PM »
Keep in mind that these declarations have a global scope.

https://github.com/nidud/asmc/blob/master/include/winbase.inc#L497

Code: [Select]
include stdio.inc
include stdlib.inc
include winbase.inc

.code

main proc

    printf("DCB_fDummy\t%d\n",  DCB_fDummy)
    printf("DCB_fParity\t%d\n", DCB_fParity)
    exit(0)

main endp

    end main

test case:
Code: [Select]
.486
.model flat

DCB_R0 RECORD \
    DCB_fDummy:             17,
    DCB_fAbortOnError:      1,
    DCB_fRtsControl:        2,
    DCB_fNull:              1,
    DCB_fErrorChar:         1,
    DCB_fInX:               1,
    DCB_fOutX:              1,
    DCB_fTXContinueOnXoff:  1,
    DCB_fDsrSensitivity:    1,
    DCB_fDtrControl:        2,
    DCB_fOutxDsrFlow:       1,
    DCB_fOutxCtsFlow:       1,
    DCB_fParity:            1,
    DCB_fBinary:            1

.data
R0 DCB_R0< 3,0,0,0,0,0,0,0,0,0,0,0,1,0 >

    end

same as:
Code: [Select]
typedef struct {

    unsigned long fBinary:            1;
    unsigned long fParity:            1;
    unsigned long fOutxCtsFlow:       1;
    unsigned long fOutxDsrFlow:       1;
    unsigned long fDtrControl:        2;
    unsigned long fDsrSensitivity:    1;
    unsigned long fTXContinueOnXoff:  1;
    unsigned long fOutX:              1;
    unsigned long fInX:               1;
    unsigned long fErrorChar:         1;
    unsigned long fNull:              1;
    unsigned long fRtsControl:        2;
    unsigned long fAbortOnError:      1;
    unsigned long fDummy:             17;
} DCB_R0;

DCB_R0 R0 = { 0,1,0,0,0,0,0,0,0,0,0,0,0,3 };

Code: [Select]
        dd 00018002h

habran

  • Member
  • *****
  • Posts: 1116
    • uasm
Re: UASM 2.41 Release + WinInc 2.09
« Reply #20 on: September 30, 2017, 08:46:20 PM »
Please explain(Pauline) :biggrin:
Cod-Father

habran

  • Member
  • *****
  • Posts: 1116
    • uasm
Re: UASM 2.41 Release + WinInc 2.09
« Reply #21 on: September 30, 2017, 08:49:24 PM »
aw27, here is fixed uasm.exe for the first part
I don't have enough info for the second part
Cod-Father

aw27

  • Member
  • ****
  • Posts: 854
  • Let's Make ASM Great Again!
Re: UASM 2.41 Release + WinInc 2.09
« Reply #22 on: September 30, 2017, 10:53:44 PM »
Can you give me a complete source please of the last one?

Sure:

Code: [Select]

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

  • Member
  • *****
  • Posts: 1116
    • uasm
Re: UASM 2.41 Release + WinInc 2.09
« Reply #23 on: September 30, 2017, 11:59:45 PM »
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
Code: [Select]
--- 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:
Code: [Select]
                    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

  • Member
  • *****
  • Posts: 1116
    • uasm
Re: UASM 2.41 Release + WinInc 2.09
« Reply #24 on: October 01, 2017, 12:36:35 AM »
that is what would happen if I let it happen:
Code: [Select]
    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

  • Member
  • ****
  • Posts: 854
  • Let's Make ASM Great Again!
Re: UASM 2.41 Release + WinInc 2.09
« Reply #25 on: October 01, 2017, 01:15:21 AM »
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

  • Member
  • *****
  • Posts: 1116
    • uasm
Re: UASM 2.41 Release + WinInc 2.09
« Reply #26 on: October 01, 2017, 06:24:21 AM »
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::
Code: [Select]
    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

  • Member
  • ****
  • Posts: 854
  • Let's Make ASM Great Again!
Re: UASM 2.41 Release + WinInc 2.09
« Reply #27 on: October 01, 2017, 11:52:04 AM »
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

  • Member
  • *****
  • Posts: 1116
    • uasm
Re: UASM 2.41 Release + WinInc 2.09
« Reply #28 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.
Cod-Father

aw27

  • Member
  • ****
  • Posts: 854
  • Let's Make ASM Great Again!
Re: UASM 2.41 Release + WinInc 2.09
« Reply #29 on: October 01, 2017, 01:47:14 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.