flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > force evaluation |
Author |
|
LocoDelAssembly 08 May 2006, 22:04
Code: macro MakeName name, i { match index, i \{ name \# index = '?' \} } index equ 0 MakeName _, index display _0 I don't remember why match is needed but works Note I use equ instead of =, you need to use equ because the # works at preprossesing time (where "=" works at assembly time) Hope this helps and someone explain us why match is needed |
|||
08 May 2006, 22:04 |
|
Smile 08 May 2006, 22:39
"index equ 0" - constant expression, and not work in my case
Code: index = 0 ; <- dinamic expression MakeName _, index+1 i use this construction to access stored variables, have i another way? Code: macro stack name { common name#.sp = 0 ; stack pointer macro name#.push arg \{ index = name#.sp name#.item#index = arg name#.sp = index + 1 \} macro name#.pop arg \{ index = name#.sp if index > 0 arg = name#.item#index name#.sp = index - 1 else display `name # ' - stack is empty' end if \} } stack s s.push 1 s.pop x display x+0x30 main problem - resolve unique names Code: name#.item#index ; always s.itemindex |
|||
08 May 2006, 22:39 |
|
LocoDelAssembly 08 May 2006, 23:03
Check this http://board.flatassembler.net/topic.php?p=29109#29109
To decrement if there is no other way you can get it by doing Code: restore counter restore counter I think you can use equates with your problem but I have no time to do it now. I'll try later if you still having problems Regards [edit]Works but not checked if it does all that is intended Code: macro stack name { common name#.sp = 0 ; stack pointer index equ 0 macro name#.push arg \{ match current,index ; this we need to get value of index before preprocessing \\{ name\\#.item\\#current = arg rept 2 i:current \\\{ index equ i \\\} ; this increases the index \\} name#.sp = index \} macro name#.pop arg \{ if index > 0 restore index restore index name#.sp = index match current,index ; this we need to get value of index before preprocessing \\{ arg = name\\#.item\\#current \\} else display `name # ' - stack is empty' err end if \} } stack test irp item, 'H', 'e', 'l', 'l', 'o' {test.push item} rept 5 n:0 { display test.item # n } display 13, 10 rept 5 n:0 { test.pop char display char } |
|||
08 May 2006, 23:03 |
|
Smile 09 May 2006, 08:26
locodelassembly
Thank |
|||
09 May 2006, 08:26 |
|
LocoDelAssembly 09 May 2006, 13:37
I forgot to say something, don't use things like
Code: repeat test.sp test.pop item end repeat See why: Code: repeat test.sp test.pop var display var ; Five o's will be displayed end repeat Preprocesed as: Code: repeat test.sp ;test.pop var if 5>0 ;restore index ;restore index test.sp=4 ;match current,4 ;{ ; var=test#.item#current ;} var=test.item4 else display 'test - stack is empty' err end if display var end repeat As you can see, index is decremented only once (since repeat doesn't repeats "restore index" nor concatenates again with # since that is at preprossesing stage). As a rule, always make sure that push and pop gets expanded every time it's used (like REPT does). |
|||
09 May 2006, 13:37 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.