Simple FOR macro for Poasm to handle more effectively the loops :
ForCounter = 0
FOR_ MACRO var,init,_end
mov var,init
ForCounter=ForCounter+1
@CatStr(<Cnd>,ForCounter)= _end
@CatStr(<ForLoop>,ForCounter) :
ENDM
NEXT MACRO var
inc var
cmp var,@CatStr(<Cnd>,ForCounter)
jbe @CatStr(<ForLoop>,ForCounter)
ENDM
Hi Vortex!
I think "simple" begin when you can nest loops. So so simple can be disappointing :thumbsup:
HSE.
Hi HSE,
I already have a FOR macro for Masm allowing nested constructs :
http://masm32.com/board/index.php?topic=9378.0
Converting the same macro to Poasm is not easy. I am receiving some error messages.
Quote from: Vortex on June 03, 2023, 05:22:46 AM
I already have a FOR macro for Masm allowing nested constructs
That is good. :thumbsup:
Quote from: Vortex on June 03, 2023, 05:22:46 AM
Converting the same macro to Poasm is not easy.
Ok. :biggrin:
Converting FOR macro for €ASM is not necessary, because %FOR/%ENDFOR asm-time loops are already built-in, see https://euroassembler.eu/eatests/t2642.htm (https://euroassembler.eu/eatests/t2642.htm) for instance.
Quote from: vitsoft on June 04, 2023, 09:08:33 PM
Converting FOR macro for €ASM is not necessary, because %FOR/%ENDFOR asm-time loops are already built-in
:eusa_naughty: No, Vito. This macro build a runtime loop.
More variants of for loops (https://www.jj2007.eu/MasmBasicQuickReference.htm#Mb1185):
For_ fct=1.5 To 2.0 Step 0.1 ; counter is a float, and therefore needs to be
Print Str$(fct), Spc2$ ; previously defined in .data? or with SetGlobals
Next
For_ each esi in My$() ; loop through elements of an array
PrintLine Str$(ForNextCounter), Tb$, esi ; print the counter and each element
Next
Print masm32rt.inc with line numbers:
include \masm32\MasmBasic\MasmBasic.inc
Init
Recall "\Masm32\include\masm32rt.inc", i$()
For_ each esi in i$(): <PrintLine Str$(ForNextCounter), Tb$, esi>
EndOfCode
(of course, simple nested integer loops also work fine...)
Hi HSE,
To be more specific, I am trying to get work the syntax below :
level=1
@CatStr(<Sample>,level) CATSTR <test>,level
The FOR macro allowing nested constructs is a bit complicated. There are some differences between the macro engines of Masm and Poasm.
Hi Vortex,
Perhaps that work.. but, because apparently don't exist expansion ("%"), you don't know :biggrin:
Hi HSE,
As I said, Poasm and Masm have some differences. Poasm does not need the expansion symbol, you can check the code in the first posting of this thread :
@CatStr(<Cnd>,ForCounter)= _end
@CatStr(<ForLoop>,ForCounter) :
Hi Vortex,
Quote from: Vortex on June 11, 2023, 05:58:50 AM
Poasm does not need the expansion symbol
:biggrin: Just don't have.
I think is necesary to force expansion in .ECHO:
@CatStr(<Sample>,level) CATSTR <test>,level
.ECHO @CatStr(<Sample>,level)
Hi HSE,
That .Echo example is already mentioned in Pelles Forum. I am sorry but this would not work as expected :
.386
.model flat,stdcall
option casemap:none
ExitProcess PROTO :DWORD
printf PROTO C :DWORD,:VARARG
includelib \PellesC\lib\Win\kernel32.lib
includelib msvcrt.lib
level=1
@CatStr(<Sample>,level) CATSTR <test>,level
.echo @CatStr(<Sample>,level)
.echo Sample1
.data
string db 'Hello world!'
.code
start:
invoke ExitProcess,0
END start
The result is :
"Sample1"
Sample1
If you insert the expansion symbol which is not supported by Poasm :
@CatStr(<Sample>,%level) CATSTR <test>,%level
.echo @CatStr(<Sample>,%level)
.echo Sample1
Output :
E:\PellesC\test>\PellesC\bin\poasm/AItest2 Test.asm
E:\PellesC\test\Test.asm(13): error: Invalid use of '%'.
E:\PellesC\test\Test.asm(13): fatal error: Invalid use of '1'.
The Masm32 equivalent:
include \masm32\include\masm32rt.inc
level=123
if 1 ; works fine
tmp$ CATSTR <Sample equ ">, <Sample>, %level, <">
tmp$
elseif 1 ; assembles but prints garbage
% @CatStr(<Sample equ ">, <Sample>, %level, <">)
else ; assembles but prints garbage
@CatStr(Sample equ ">, <Sample>, %level, <")
endif
echo S1=[Sample]
% echo S1=[Sample]
.code
string db Sample, 13, 10, 0
start:
print offset string
invoke ExitProcess, 0
END start
Hi Vortex,
Quote from: Vortex on June 11, 2023, 07:36:48 PM
That .Echo example is already mentioned in Pelles Forum. I am sorry but this would not work as expected :
I readed that yesterday :thumbsup:.
Also some diferences between Andreas and Pelles in 2005 or so. Apparently POASM is a dead branch. Sorry, I don't know that before :sad:
HSE
Hi HSE,
No worries. Poasm has some differences but it it's a very good assembler. Many thanks to Pelle. I am trying to test various macro constructs and these small example are helping to find the issues.