64 bit assembler > 64 Bit Assembler

Syntax error when using "ASSUME RAX" directive

(1/2) > >>

Misha paranski:
Greetings,
I'm creating a common header for masm 32bit and 64bit, and i have the following macro:

IFDEF RAX
REG_AX textequ <rax>
ELSE
REG_AX textequ <eax>
ENDIF

; Copy the value from requested member in the BOOK structs array
; to the general purpose register.
GET_BOOK_MEMBER MACRO Member, BookIndex
    mov REG_AX, gBooks
    add REG_AX, SIZEOF BOOK * BookIndex
    assume REG_AX:PTR BOOK
    mov REG_AX, [REG_AX].Member
ENDM

I'm compling using visual studio, and the compliation FAILS!!! with ml64.exe with the following errors:
A2008: syntax error: rax
A2008: syntax error: rax

If i remove the   "assume REG_AX:PTR BOOK" it works.... the assume statement works in 32bit. What did i do wrong? i want to
use rax as a pointer to a struct.

jj2007:
It is safer to use a global switch (credits to rrr):


--- Code: ---if @AssembleAs64bit
  SIZE_P equ <QWORD> ; int and long are 32-bit, pointer is 64-bit
else
  SIZE_P equ <DWORD> ; int, long, and pointer are 32-bit
  rax equ eax
  rcx equ ecx
  rdx equ edx
  rsi equ esi
  rdi equ edi
  rbx equ ebx
  rbp equ ebp
  rsp equ esp
endif
--- End code ---

This works like a charm with ML/ML64, UAsm, AsmC and JWasm (-> 64-bit assembly with RichMasm).

The principle is simple: You write all code using rax for pointers and pointer-sized variables; when assembled as 32-bit code, rax is not a keyword, so the preprocessor translates it to eax.

Misha paranski:
Thank you for the reply!

I'm still getting the same errors...

Here's the full code:

--- Code: ---HARRY_POTTER = 0

IFDEF RAX
EXTERN gBooks:NEAR
SIZE_P equ <QWORD> ; int and long are 32-bit, pointer is 64-bit
_gBooks textequ <gBooks>
ELSE
EXTERN _gBooks:NEAR
SIZE_P equ <DWORD> ; int, long, and pointer are 32-bit
rax equ eax
ENDIF

BOOK struc
    Name SIZE_P ?
    Length SIZE_P ?
BOOK endS

; Copy the value from requested member in the BOOK struct
; to the general purpose register rax.
GET_HOOK_MEMBER MACRO Member, BookIndex
    mov rax, _gBooks
    add rax, SIZEOF BOOK * BookIndex
    assume rax:PTR BOOK
    mov rax, [rax].Member
    assume rax:nothing
ENDM

;Get the name in rax
BOOK_NAME MACRO BookIndex
    GET_BOOK_MEMBER Name, BookIndex
ENDM

;Get the length in rax
BOOK_LENGTH MACRO BookIndex
    GET_BOOK_MEMBER Length, BookIndex
ENDM

--- End code ---

I'm still getting
"syntax error: rax"
"undefined symbol: Length"
"undefined symbol: Name"

When using these macros in my assembly code.
If i remove the "ASSUME rax: ptr BOOK", it compiles... but i need that statement.

hutch--:
It is probably the case that ML64 treats registers as key words and won't let you equate them to anything else.

Misha paranski:
Well... this is literally my code now:

--- Code: ---.CODE

Foo PROC
    ASSUME rax:NOTHING
Foo ENDP

END

--- End code ---

And i'm getting the same errors.. still:

--- Code: ---Severity Code Description Project File Line Suppression State
Error A2008 syntax error : rax foo_project foo.asm 3
--- End code ---
Severity   Code   Description   Project   File   Line   Suppression State

--- Code: ---Error MSB3721 The command "ml64.exe /c /nologo /Zi /Fo"C:\foo\x64\Release\foo.obj"" /W3 /errorReport:prompt  /foo.asm" exited with code 1. foo_project C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\V140\BuildCustomizations\masm.targets 50

--- End code ---

This is indeed... weird.. i'm not sure what to do now.. it doesn't like the "ASSUME" directive. Is it obsolete?



Navigation

[0] Message Index

[#] Next page

Go to full version