flat assembler
Message board for the users of flat assembler.

Index > Main > Instruction/Command aliases in fasmg

Author
Thread Post new topic Reply to topic
ScriptTiger



Joined: 17 Jul 2022
Posts: 4
ScriptTiger 17 Jul 2022, 05:55
Greetings! I am currently making the switch from fasm to fasmg. I've read through the manuals and as many of the posts by Tomasz I could find about making the switch. I've already made all the relevant changes to all of my macros, but I seem to be hitting a wall when it comes to what I thought would be simple equates (equ).

Given the following line of code:

_message DH 'Hello, World!',0

fasm equ header example:

DH equ db

The above works as expected in fasm, but fasmg throws them all out as illegal instructions.

Admittedly, my head is still spinning a bit after reading the fasmg material and trying to wrap my head around everything. I know there's probably a million and one ways to do this, but what would be the simplest way to alias instructions like in the example in fasmg? I use this quite a lot for fasm code to alias dd/dq, rd/rq, movsd/movsq, scasd/scasq, etc., to quickly change code from 32 to 64-bit with as little effort as possible and without needing macros which would require the line to be rearranged to lead with the macro name and followed by the label and/or other arguments separated by commas.
Post 17 Jul 2022, 05:55
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8034
Location: Kraków, Poland
Tomasz Grysztar 17 Jul 2022, 07:43
In this case you need to define a symbol of "labeled instruction" class, which is done with STRUC directive:
Code:
struc (label) DH data&
        label DB data
end struc    
To catch the cases when the same name is used without any label, you'd need to add also a plain macro:
Code:
macro DH data&
        DB data
end macro    
You can also forward all custom data directives to EMIT, to avoid clashing with any redefinitions (for example if you need to override some of the standard ones like DB or DW):
Code:
struc (label) DH data&
        label EMIT 1: data
end struc

macro DH data&
        EMIT 1: data
end macro    

BTW, in fasm 1 EQU could not alias preprocessor's directives or macros in very much the same way - and fasmg has a unified language, meaning every directive is like a preprocessor's directive of fasm.
Post 17 Jul 2022, 07:43
View user's profile Send private message Visit poster's website Reply with quote
ScriptTiger



Joined: 17 Jul 2022
Posts: 4
ScriptTiger 17 Jul 2022, 08:55
Brilliant! I never even thought of using struc, but it totally makes sense in retrospect. Thank you so much!

What about alias word size/casting? For example, I also have something like the following in fasm:

HCX equ rcx
HAX equ rax
HWORD equ qword

mov HWORD[HCX],HAX

Substituting HCX and HAX both work as regular (equ)ates, but HWORD gets thrown as an invalid expression.

I realize I was probably abusing equ a bit from the start as kind of a universal "replace all". So, hopefully I'll do things properly this time with fasmg.
Post 17 Jul 2022, 08:55
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8034
Location: Kraków, Poland
Tomasz Grysztar 17 Jul 2022, 09:19
ScriptTiger wrote:
Substituting HCX and HAX both work as regular (equ)ates, but HWORD gets thrown as an invalid expression.
There might be something additional interfering, because this assembles correctly for me (with standard compatibility headers):
Code:
include 'cpu/x64.inc'

HCX equ rcx
HAX equ rax
HWORD equ qword

use64
mov HWORD[HCX],HAX    
Post 17 Jul 2022, 09:19
View user's profile Send private message Visit poster's website Reply with quote
ScriptTiger



Joined: 17 Jul 2022
Posts: 4
ScriptTiger 17 Jul 2022, 09:56
My apologies, I think I probably gave you a bad example. The exact error is as follows:

invoke HeapFree,\
[os.Prchp],\
0,\
HWORD[HCX]
macro invoke? [1] macro fastcall? [72] mov? [3] x86.parse_operand@src [32] (CALM)
Error: invalid expression.

Using the mov instruction versus the invoke macro are probably totally different, so sorry about that again. I just tried copying HWORD[HCX] into the HCX register first and then just passing HCX and it works fine.

mov HCX,HWORD[HCX]
invoke HeapFree,\
[os.Prchp],\
0,\
HCX

I'm not sure if that's just a difference between the way invoke works between fasm and fasmg or maybe I'm just using it wrong.
Post 17 Jul 2022, 09:56
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8034
Location: Kraków, Poland
Tomasz Grysztar 17 Jul 2022, 10:09
Oh, the "fastcall" macro puts additional proxy variable in there, which hides the EQU replacement. It's a quirk of how the internal implementations of these macros interact, I should correct it.

A quick fix is to take PROC64.INC, and replace all occurrences of "redefine value " with "value reequ ". This makes the EQU replacements processed when the proxy is defined.
Post 17 Jul 2022, 10:09
View user's profile Send private message Visit poster's website Reply with quote
ScriptTiger



Joined: 17 Jul 2022
Posts: 4
ScriptTiger 17 Jul 2022, 10:24
Thank you again!

I also tried just dropping the cast altogether and it works, too.

invoke HeapFree,\
[os.Prchp],\
0,\
[HCX]

I'm assuming the invoke macro already casts it correctly, so there wasn't any need to cast it again on my part. Maybe it was actually a problem with the fasm 1 invoke macro that I felt the need to cast it, I'm not sure. But your quick fix will definitely come in handy on other parts. Thanks again!
Post 17 Jul 2022, 10:24
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.