The MASM Forum

64 bit assembler => UASM Assembler Development => Topic started by: jimg on August 20, 2019, 03:22:46 AM

Title: mov [eax],word ptr 005Dh
Post by: jimg on August 20, 2019, 03:22:46 AM
John-

for the following instruction:

   mov [eax],word ptr 005Dh   ; add terminating "]",0


masm gives:
0000005C  66| C7 00 005D      mov [eax],word ptr 005Dh   ; add terminating "]",0

uasm64 2.45.4.0 gives:
0000005C  66C7005D00               mov [eax],word ptr 005Dh   ; add terminating "]",0

uasm64 2.46.10 - 2.49.02 give:
0000005C  C6005D                   mov [eax],word ptr 005Dh   ; add terminating "]",0   **** incorrect

Title: Re: mov [eax],word ptr 005Dh
Post by: habran on August 20, 2019, 05:13:41 AM
masm is incorect
it should be : 66 C7 00 5D 00
if you write it with word ptr [eax] you will get proper result:
mov word ptr[eax],  005Dh; add terminating "]", 0
0000000000401012 67 66 C7 00 5D 00    mov         word ptr [eax],5Dh

we will check why uasm doesn't recognize 'word ptr' before second operand
Title: Re: mov [eax],word ptr 005Dh
Post by: jimg on August 20, 2019, 06:51:41 AM
isn't
66| C7 00 005D
the same as
66 C7 00 5D 00
one written as bytes, one written as word?
Title: Re: mov [eax],word ptr 005Dh
Post by: habran on August 20, 2019, 07:31:29 AM
Try to play with it, check stored data, use al, ah to retrieve it and than let me know what did you find about it :biggrin:
Title: Re: mov [eax],word ptr 005Dh
Post by: jimg on August 20, 2019, 08:29:18 AM
Yes, I dumped the exes and it is the same.  Just listing vagaries between masm and uasm.
Title: Re: mov [eax],word ptr 005Dh
Post by: jj2007 on August 20, 2019, 08:30:51 AM
This looks indeed like a UAsm bug. ML and AsmC do it correctly. I must admit, though, that I never used that syntax - for me it's mov word ptr [eax], 123, and that one is OK for UAsm.

include \masm32\include\masm32rt.inc
.data
string db "xxxxxxxxxxxxxxxxxx"
.code
start:
  mov eax, offset string
  int 3
  mov [eax],word ptr 005dh
  nop
  mov [eax],word ptr 00aah
  nop
  mov [eax],word ptr 00bbcch
  nop
  mov [eax],word ptr 7788h
  nop
  mov word ptr [eax],"aa"
  nop
  exit
end start


ML:
  mov eax, offset 00402000                ; ASCII "xxxxxxxxxxxxxxxxxx"
  int3
  mov word ptr [eax], 5D
  nop
  mov word ptr [eax], 0AA
  nop
  mov word ptr [eax], 0BBCC
  nop
  mov word ptr [eax], 7788
  nop
  mov word ptr [eax], 6161
  nop                                     ; ³


UAsm:
  mov eax, offset 00402000                ; ASCII "xxxxxxxxxxxxxxxxxx"
  int3
  mov byte ptr [eax], 5D
  nop
  mov byte ptr [eax], 0AA
  nop
  mov dword ptr [eax], 0BBCC
  nop
  mov dword ptr [eax], 7788
  nop
  mov word ptr [eax], 6161
  nop
Title: Re: mov [eax],word ptr 005Dh
Post by: jimg on August 20, 2019, 08:53:57 AM
So far I have found 14 of my programs that use that syntax, spread over 20 years.   And that's only word ptr.  It's slow going.
Title: Re: mov [eax],word ptr 005Dh
Post by: jj2007 on August 20, 2019, 09:13:44 AM
It's clearly a matter of taste, Jim. And it should be corrected in UAsm, of course.
Title: Re: mov [eax],word ptr 005Dh
Post by: habran on August 20, 2019, 10:24:06 AM
jimg, you have given wrong output from masm :
0000005C  66| C7 00 005D      mov [eax],word ptr 005Dh   ; add terminating "]",0
that is why I told you that it is incorect, however, I have tested masm and it gives the correct output:
000000013F2D103B 66 C7 00 5D 00       mov         word ptr [rax],5Dh 

if you try:
db 66h, 0c7h, 00h, 00h, 5dh;  gives  00 5d
and this:
db 66h, 0c7h, 00h, 5dh, 00h;  gives 5d 00

however, thank you for pointing an error in UASM
will be fixed
Title: Re: mov [eax],word ptr 005Dh
Post by: jimg on August 20, 2019, 10:34:20 AM
Sorry, I used masm 6.15 for the test, and it indeed gives what I said.
Title: Re: mov [eax],word ptr 005Dh
Post by: habran on August 20, 2019, 02:21:38 PM
In that case masm 6.15 gives wrong output for that instruction.
It is fixed now in newer versions.
I am curious if masm 6.15 would output it correctly if you use  mov word ptr [eax], 005Dh
Title: Re: mov [eax],word ptr 005Dh
Post by: aw27 on August 20, 2019, 04:06:54 PM
There is no bug in MASM, for this instance, all MASM versions produce the same output. There is a bug in UASM, it translates "mov [eax],word ptr 005Dh" to "mov     byte ptr [eax], 5Dh". Yes, the sysntax "mov [eax],word ptr 005Dh" is a bit weird :skrewy:, it would never cross my head to use it.


.386
.model flat, stdcall

.code

main proc
int 3
mov [eax],word ptr 005Dh   ; add terminating "]",0
ret
main endp

end

comment ?
00401001 66c7005d00      mov     word ptr [eax],5Dh ; Microsoft (R) Macro Assembler Version 14.22.27905.0
00401001 66c7005d00      mov     word ptr [eax],5Dh ; Microsoft (R) Macro Assembler Version 6.14.8444
00401001 c6005d          mov     byte ptr [eax],5Dh ; UASM v2.49, Jun 21 2019, Masm-compatible assembler.
?
Title: Re: mov [eax],word ptr 005Dh
Post by: LiaoMi on August 20, 2019, 05:33:16 PM
Classic case for fuzzing instructions  :rolleyes:
Title: Re: mov [eax],word ptr 005Dh
Post by: HSE on August 20, 2019, 08:07:39 PM
AsmC 2.28.16:011E1001  |.  66:C700 5D00  MOV WORD PTR DS:[EAX],5D
Title: Re: mov [eax],word ptr 005Dh
Post by: johnsa on October 21, 2019, 05:13:15 AM
Branch 2.50:

this now produces equivalent results:

mov word ptr [rsi],0x20
mov byte ptr [rsi+10],0x10
mov dword ptr [rsi+20],0x100

mov [rsi],word ptr 0x20
mov [rsi+10],byte ptr 0x10
mov [rsi+20],dword ptr 0x100



0:  66 c7 06 20 00          mov    WORD PTR [rsi],0x20
5:  c6 46 0a 10             mov    BYTE PTR [rsi+0xa],0x10
9:  c7 46 14 00 01 00 00    mov    DWORD PTR [rsi+0x14],0x100
10: 66 c7 06 20 00          mov    WORD PTR [rsi],0x20
15: c6 46 0a 10             mov    BYTE PTR [rsi+0xa],0x10
19: c7 46 14 00 01 00 00    mov    DWORD PTR [rsi+0x14],0x100