@ArgRev MACRO args:VARARG
LOCAL arg,y
y TEXTEQU <>
FOR arg,<&args>
y CATSTR <arg>,<!,>,y
ENDM
y SUBSTR y,1,@SizeStr(%y) - 1
EXITM y
ENDM
@SaveRegs MACRO regs:VARARG
LOCAL myEnd, num, flag, reg
num=0
flag=0
WHILE flag EQ 0
% IFDEF @CatStr(<RealEnd>,<%num>)
num = num + 1
ELSE
flag = 1
ENDIF
ENDM
% FOR reg, <regs>
push reg
ENDM
@RestoreRegs MACRO
@CatStr(<RealEnd>,<%num>) %num
ENDM
@CatStr(<RealEnd>,<%num>) MACRO depth:REQ
LOCAL reg
IF (OPATTR (myEnd)) AND 0100000y
RealEnd&depth %(depth-1)
ELSE
myEnd LABEL BYTE ;; dummy
% FOR reg, < @ArgRev( [u]&[/u]regs ) > ;<<-- the board had a problem with this line
pop reg
ENDM
ENDIF
ENDM
ENDM
;Example usage:
@SaveRegs eax,ebx,ecx,edx
@SaveRegs esi,edi,eax,ebx,ecx,edx
@SaveRegs esi,edi
@RestoreRegs
@RestoreRegs
@SaveRegs esi,edi,eax,ebx,ecx,edx
@RestoreRegs
@RestoreRegs
Just have equal pairs of Saves/Restores and the stack will be the same as you left it. I just wrote this to fix the versions in the MASM manual. That version had a single global varible to hold which registers were pushed - no flexiblity what-so-ever. :) I hope someone can use it?Great macros bitRAKE.
Prevents me from doing stupid mistakes in reverse order poping.
I alredy have them added to my sniplets.
KetilO
Prevents me from doing stupid mistakes in reverse order poping.
I alredy have them added to my sniplets.
KetilO
Should have just posted the file - board doesn't catch '®s' in a code block. Should read ®s between the quotes. :) Here is the file form.
Please re-download: It's fixed.
Please re-download: It's fixed.
bitRAKE,
seems that last @RestoreRegs produces no code?! :)
japheth
seems that last @RestoreRegs produces no code?! :)
japheth
I thought I was being smart, and broke it. :)
Should be fixed.
japheth, you were using the downloaded code, not the post code, right?
Oh, you can certainly pass values other than registers! Anything that can be pushed/poped. f0dder, was the inspiration for this one - this is just a modified version of the advanced BEGIN/END byte offset macro I did. Let me go find it so everyone knows what I'm talking about - it's a very handy LIFO stack using local symbols. I'm wondering how far I can take this stuff before I run up against MASM's internal limits?
Should be fixed.
japheth, you were using the downloaded code, not the post code, right?
Oh, you can certainly pass values other than registers! Anything that can be pushed/poped. f0dder, was the inspiration for this one - this is just a modified version of the advanced BEGIN/END byte offset macro I did. Let me go find it so everyone knows what I'm talking about - it's a very handy LIFO stack using local symbols. I'm wondering how far I can take this stuff before I run up against MASM's internal limits?
Well, your "title" say it all, bitrake... "Use the Macro, Luke."
Hehe...yeah, cool. :alright:
bitRAKE,
no I used the downloaded version (the first gives assembly errors) :) .
I just included some echos in your @CatStr macro :
and when assembling the following code:
I should get 4 times "after pops", but what I get is:
so the error seems to be "real" (Could you please explain why I get 5 displays!? :) ).
japheth
no I used the downloaded version (the first gives assembly errors) :) .
I just included some echos in your @CatStr macro :
@CatStr(<RealEnd>,<%num>) MACRO depth:REQ
LOCAL reg
IF (OPATTR (myEnd)) AND 0100000y
@CatStr(<RealEnd>,%(depth-1)) %(depth-1)
PURGE RealEnd&depth
echo after purge
ELSE
myEnd LABEL BYTE ;; dummy
% FOR reg, < @ArgRev( ®s ) >
pop reg
ENDM
echo after pops
ENDIF
and when assembling the following code:
@SaveRegs eax,ebx,ecx,edx
@SaveRegs eax,ebx,ecx
@SaveRegs esi,edi
@RestoreRegs
@RestoreRegs
@SaveRegs esi,edi,eax,ebx,ecx,edx
@RestoreRegs
@RestoreRegs
I should get 4 times "after pops", but what I get is:
Microsoft (R) Macro Assembler Version 6.15.8803
Copyright (C) Microsoft Corp 1981-2000. All rights reserved.
Assembling: GetIconn.asm
after pops
after pops
after purge
after pops
after purge
Linking...
GetIconn.exe - 0 error(s), 0 warning(s)
so the error seems to be "real" (Could you please explain why I get 5 displays!? :) ).
japheth
Do not use PURGE version, that is the error.
Re-Download, or just comment out the PURGE line. :)
Have you looked at the code produced?
I'll explain later - have to go to work, been up all night.
I think it's still got errors. :) The @RestoreRegs macro get redefined everytime the @SaveRegs macro is called. Need to PURGE and have @RestoreRegs selective execute the other macro based on the highest number not PURGE'd. Will fix later...(this means the other(BEGIN/END) one is broken, too.)
Re-Download, or just comment out the PURGE line. :)
Have you looked at the code produced?
I'll explain later - have to go to work, been up all night.
I think it's still got errors. :) The @RestoreRegs macro get redefined everytime the @SaveRegs macro is called. Need to PURGE and have @RestoreRegs selective execute the other macro based on the highest number not PURGE'd. Will fix later...(this means the other(BEGIN/END) one is broken, too.)
I've given up on the fancy approach! :)
PURGE doesn't work like I thought it does.
This one really works.
PURGE doesn't work like I thought it does.
This one really works.
@ArgRev MACRO args:VARARG
LOCAL arg,y
y TEXTEQU <>
FOR arg,<&args>
y CATSTR <arg>,<!,>,y
ENDM
y SUBSTR y,1,@SizeStr(%y) - 1
EXITM @CatStr(<!<>,y,<!>>)
ENDM
StackGlobalNumber = 0
@StackSave MACRO vars:VARARG
LOCAL var
StackGlobalNumber = StackGlobalNumber + 1
@CatStr(<StackGlobalContent>,%StackGlobalNumber) TEXTEQU @ArgRev(&vars)
FOR var,<&vars>
push var ;; Push each value
ENDM
ENDM
@StackRestore MACRO
LOCAL var
% FOR var,@CatStr(<StackGlobalContent>,%StackGlobalNumber)
pop var
ENDM
StackGlobalNumber = StackGlobalNumber - 1
ENDM
Better attach it, bitRAKE. Remind the "&-problem".:)
EDIT: &-Problem seems to be solved!
EDIT: And it really works and is much easier to understand, bitRAKE :alright: .
But thread name "nested macro magic..." is now wrong ;)
EDIT: &-Problem seems to be solved!
EDIT: And it really works and is much easier to understand, bitRAKE :alright: .
But thread name "nested macro magic..." is now wrong ;)
The problem isn't fixed, I just didn't include any HTML codes in the source. :)
®
Yeah, but I didn't want to start a new thread for this.
The simple solution is usually the best.
I was trying to show-off and I messed it all up. :grin:
®
Yeah, but I didn't want to start a new thread for this.
The simple solution is usually the best.
I was trying to show-off and I messed it all up. :grin: