News:

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

Main Menu

mov [eax],word ptr 005Dh

Started by jimg, August 20, 2019, 03:22:46 AM

Previous topic - Next topic

jimg

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


habran

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
Cod-Father

jimg

isn't
66| C7 00 005D
the same as
66 C7 00 5D 00
one written as bytes, one written as word?

habran

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:
Cod-Father

jimg

Yes, I dumped the exes and it is the same.  Just listing vagaries between masm and uasm.

jj2007

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

jimg

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.

jj2007

It's clearly a matter of taste, Jim. And it should be corrected in UAsm, of course.

habran

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
Cod-Father

jimg

Sorry, I used masm 6.15 for the test, and it indeed gives what I said.

habran

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
Cod-Father

aw27

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.
?

LiaoMi

Classic case for fuzzing instructions  :rolleyes:

HSE

AsmC 2.28.16:011E1001  |.  66:C700 5D00  MOV WORD PTR DS:[EAX],5D
Equations in Assembly: SmplMath

johnsa

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