News:

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

Main Menu

Use the MOV instruction to obtain the value in the array

Started by wanker742126, September 04, 2024, 05:35:02 PM

Previous topic - Next topic

wanker742126

I was writing a 64-bit Windows program and noticed something strange:
The following program can be successfully assembled using ML64, but will appear when using UASM64
"Error A2031: invalid addressing mode with current CPU setting"
--------------------------------------------------
array DD 20h DUP (1)
... ...
mov rcx,2
mov eax,array[rcx*4+8]
--------------------------------------------------
Does anyone know what's going on?

six_L

Hi,wanker742126
lea    rdx,array    ;mov    rdx,offset array
mov    rcx,2
mov    eax,[rdx+rcx*4]

rdx: the frist address of  your array
rcx: index
4: 1"DD"=4"BYTE"
Say you, Say me, Say the codes together for ever.

wanker742126

Hello Six_L
I know it can be written like this, but I would like to know why ML64 can be successfully assembled, but UASM64 cannot. Is it necessary to make any settings on the CPU?

_japheth

Quote from: wanker742126 on September 04, 2024, 10:17:47 PMI know it can be written like this, but I would like to know why ML64 can be successfully assembled, but UASM64 cannot. Is it necessary to make any settings on the CPU?

No. It's valid syntax, and if UASM refuses it, it's a bug.
Dummheit, gepaart mit Dreistigkeit - eine furchtbare Macht.

six_L

Hi,wanker742126
Quotewhy ML64 can be successfully assembled, but UASM64 cannot. Is it necessary to make any settings on the CPU?
1,ML64 is written by microsoft; UASM64 is written by John Hankinson and Branislav Habus, _japheth (our forum member). they are different assembler.
2,Assembly language syntax of ML64 is not ml32-compatible, don't support HLL features. But UASM64 does.
3,ML64 only works on MS OS; UASM64 can work on MS OS, Linux and OSX.
Say you, Say me, Say the codes together for ever.

wanker742126

Thanks for your answer, six_L and _japheth.
Maybe I have to wait until UASM supports this syntax. Or maybe try using macros.

six_L

Hi,wanker742126
QuoteMaybe I have to wait until UASM supports this syntax.
Maybe You will never be the outcome. because the register addressing is faster than the memory addressing.
Say you, Say me, Say the codes together for ever.

mineiro

;this is a simple workaround, tested in linux
;I was trying to create a macro but displacement have not been added to array offset
;so I put displacement in a register
mov rcx,2
mov edx,8
mov eax,array[ecx*sizeof dword+edx]

;+8 displacement is not being added
mov eax,array[rcx*sizeof dword+8+rdx]      ;<---
USE32
mov eax,dword ptr [array+8+ecx*4]         ;<---
USE64
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

wanker742126

Today I found that ADD, SUB, MUL, and DIV can all accept array usage, but only MOV cannot.
The following program can be successfully assembled using UASM64
OPTION  CASEMAP:NONE
OPTION  WIN64:3

INCLUDELIB      KERNEL32.LIB
INCLUDELIB      USER32.LIB

MessageBoxA     PROTO   :QWORD,:QWORD,:QWORD,:DWORD
ExitProcess     PROTO   :DWORD
;*********************************************************************
.CONST
array           DD      20h DUP (1)
szCaption       DB      "TITLE",0
szText          DB      "64-BIT ASSEMBLY.",0
;*********************************************************************
.CODE
;---------------------------------------------------------------------
main    PROC
        mov     rcx,2
        add     eax,array[rcx*4+8]
        sub     eax,array[rcx*4+8]
        xor     eax,array[rcx*4+8]
        mul     array[rcx*4+8]
        div     array[rcx*4+8]
        invoke  MessageBoxA,0,OFFSET szText,OFFSET szCaption,0
        invoke  ExitProcess,0
main    ENDP
;*********************************************************************
END     main


But the program below will fail to assemble and compile, and the error occurs in the MOV line.
OPTION  CASEMAP:NONE
OPTION  WIN64:3

INCLUDELIB      KERNEL32.LIB
INCLUDELIB      USER32.LIB

MessageBoxA     PROTO   :QWORD,:QWORD,:QWORD,:DWORD
ExitProcess     PROTO   :DWORD
;*********************************************************************
.CONST
array           DD      20h DUP (1)
szCaption       DB      "TITLE",0
szText          DB      "64-BIT ASSEMBLY.",0
;*********************************************************************
.CODE
;---------------------------------------------------------------------
main    PROC
        mov     rcx,2
        mov     eax,array[rcx*4+8]
        add     eax,array[rcx*4+8]
        sub     eax,array[rcx*4+8]
        xor     eax,array[rcx*4+8]
        mul     array[rcx*4+8]
        div     array[rcx*4+8]
        invoke  MessageBoxA,0,OFFSET szText,OFFSET szCaption,0
        invoke  ExitProcess,0
main    ENDP
;*********************************************************************
END     main


six_L

you are digging the bugs of compiler, not learning the assembler language.
Come on!
the TAIWAN's frog is sitting on well and talking the vastness of sky.
Say you, Say me, Say the codes together for ever.