Author Topic: Syntax error when using "ASSUME RAX" directive  (Read 95 times)

Misha paranski

  • Regular Member
  • *
  • Posts: 3
Syntax error when using "ASSUME RAX" directive
« on: June 14, 2018, 09:08:49 PM »
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

  • Member
  • *****
  • Posts: 8428
  • Assembler is fun ;-)
    • MasmBasic
Re: Syntax error when using "ASSUME RAX" directive
« Reply #1 on: June 14, 2018, 10:17:55 PM »
It is safer to use a global switch (credits to rrr):

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

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

  • Regular Member
  • *
  • Posts: 3
Re: Syntax error when using "ASSUME RAX" directive
« Reply #2 on: June 14, 2018, 10:27:01 PM »
Thank you for the reply!

I'm still getting the same errors...

Here's the full code:
Code: [Select]
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

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

  • Administrator
  • Member
  • ******
  • Posts: 5421
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Syntax error when using "ASSUME RAX" directive
« Reply #3 on: June 14, 2018, 11:57:42 PM »
It is probably the case that ML64 treats registers as key words and won't let you equate them to anything else.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

Misha paranski

  • Regular Member
  • *
  • Posts: 3
Re: Syntax error when using "ASSUME RAX" directive
« Reply #4 on: June 15, 2018, 12:02:35 AM »
Well... this is literally my code now:
Code: [Select]
.CODE

Foo PROC
    ASSUME rax:NOTHING
Foo ENDP

END

And i'm getting the same errors.. still:
Code: [Select]
Severity Code Description Project File Line Suppression State
Error A2008 syntax error : rax foo_project foo.asm 3
Severity   Code   Description   Project   File   Line   Suppression State
Code: [Select]
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

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




jj2007

  • Member
  • *****
  • Posts: 8428
  • Assembler is fun ;-)
    • MasmBasic
Re: Syntax error when using "ASSUME RAX" directive
« Reply #5 on: June 15, 2018, 01:17:56 AM »
ML64 is indeed weird. Your code assembles fine with UAsm. Give it a try...

Otherwise, use an equate instead of assume:

book equ [rax.BOOK]
Mov rdx, book.xName
Mov rcx, book.xLength

I added the x because Name and Length are reserved words. Change your struct.

BugCatcher

  • Regular Member
  • *
  • Posts: 40
Re: Syntax error when using "ASSUME RAX" directive
« Reply #6 on: June 15, 2018, 04:29:07 AM »
Maybe this?
   assume   rax:ptr StructureName
              mov rsi, [rax].whatever
        assume     rax:nothing