flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Increasing EQU number. How do this ?

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 2143
Roman 23 Nov 2026, 12:17
Fasmw 1.73
Code:
reg0 EQU eax
reg1 EQU ebx
reg2 EQU ecx
reg3 EQU edx
reg4 EQU [edi]
reg5 EQU [esi]
reg6 EQU [memval1]
reg7 EQU [memval2]
reg8 EQU [memval3]
reg9 EQU [memval4]


macro changeReg val { } ;how do this ?

;data
memval1 dd 0
memval2 dd 0
memval3 dd 0
memval4 dd 0

;in code
curReg EQU reg0  ;= eax

changeReg curReg ;after curReg = reg1
changeReg curReg ;after curReg = reg2
changeReg curReg ;after curReg = reg3
restore   curReg ;after curReg = reg2
    
Post 23 Nov 2026, 12:17
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 21220
Location: In your JS exploiting you and your system
revolution 23 Nov 2026, 12:30
I think define is needed here
Code:
reg0 EQU eax
reg1 EQU ebx
reg2 EQU ecx
reg3 EQU edx
reg4 EQU [edi]
reg5 EQU [esi]
reg6 EQU [memval1]
reg7 EQU [memval2]
reg8 EQU [memval3]
reg9 EQU [memval4]

define curRegPointer reg0
curReg equ reg0

macro changeReg val {
        ; add more here in reverse order
        ; can maybe use a rept loop to make it automated
        match =reg2, curRegPointer \{
                define curRegPointer reg3
                curReg equ reg3
        \}
        match =reg1, curRegPointer \{
                define curRegPointer reg2
                curReg equ reg2
        \}
        match =reg0, curRegPointer \{
                define curRegPointer reg1
                curReg equ reg1
        \}

}

match r,curReg {display `r,13,10}
mov     eax,curReg
changeReg
match r,curReg {display `r,13,10}
mov     eax,curReg
changeReg
match r,curReg {display `r,13,10}
mov     eax,curReg    
Code:
flat assembler  version 1.73.31  (16384 kilobytes memory)
eax
ebx
ecx
1 passes, 9 bytes.    
Code:
00000000  6689C0            mov eax,eax
00000003  6689D8            mov eax,ebx
00000006  6689C8            mov eax,ecx    
Post 23 Nov 2026, 12:30
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 2143
Roman 23 Nov 2026, 13:26
Quote:

can maybe use a rept loop to make it automated

Yes.

Not comfortable do many times in macro
Code:
match =reg2, curRegPointer \{
                define curRegPointer reg3
                curReg equ reg3
        \}
        match =reg1, curRegPointer \{
                define curRegPointer reg2
                curReg equ reg2
        \}
        match =reg0, curRegPointer \{
                define curRegPointer reg1
                curReg equ reg1
        \}
    


or do this variant.
Code:
reg0 EQU eax
reg1 EQU ebx
reg2 EQU ecx
reg3 EQU edx
reg4 EQU [edi]
reg5 EQU [esi]
reg6 EQU [memval1]
reg7 EQU [memval2]
reg8 EQU [memval3]
reg9 EQU [memval4]

define curRegPointer reg0
curReg equ reg0

macro mmatchr r,r2 {
      match =r, curRegPointer \{
                define curRegPointer r2
                curReg equ r2
        \}
}

macro changeReg  {
        mmatchr reg2,reg3
        mmatchr reg1,reg2
        mmatchr reg0,reg1

} 
    
Post 23 Nov 2026, 13:26
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-2026, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.