how to get label in rept to work
Hi,
I try to assemble the following:
rept 16
···· jmp MyLabel%
···· nop
MyLabel%
endr
but it says label already defined. Ive tried a few combinations but can't get anything to work.
I hoped it would assemble as:
··· jmp MyLabel0
···· nop
MyLabel0··
···· jmp MyLabel1
···· nop
MyLabel1
etc...
Thanks
I try to assemble the following:
rept 16
···· jmp MyLabel%
···· nop
MyLabel%
endr
but it says label already defined. Ive tried a few combinations but can't get anything to work.
I hoped it would assemble as:
··· jmp MyLabel0
···· nop
MyLabel0··
···· jmp MyLabel1
···· nop
MyLabel1
etc...
Thanks
Comments
Given that your desired resulting code...
etc, etc
...is identical to this:
etc, etc
...you could skip the whole label stuff. What exactly is the point of this code. Your "nop" could be any single byte of gibberish since it will never get executed anyway. In addition, since you apparently need only 16 copies of this code, you could cut and paste it in about 30 seconds rather than trying to figure out how to get a macro to do it.
Thanks,
PeterM
Sorry it was only an example for clarity, my real code does much more and I didn't want to manually work the nn in $+nn since this is prone to error if I alter the code. Copying it 16 times doesn't help readability and I then have to change 16 places if I alter the code.· If I have to I will do one of these but I would have thought there must be a proper solution as in other compilers, I just can't find it in the documentation.
Best regards
Mark
Having said that, I've been able to do some fairly cool things with macros in the past:
http://www.sxlist.com/techref/new/letter/news0403.htm starts from the beginning, but may point out some things that will help reguarding local and global scope in macro labels. E.g. try local variables rather than global.
http://www.sxlist.com/techref/ubicom/inst/macro.htm links to that and other interesting macro related things.
Let us know what you find.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
---
James Newton, Host of SXList.com
james at sxlist,com 1-619-652-0593 fax:1-208-279-8767
SX FAQ / Code / Tutorials / Documentation:
http://www.sxlist.com Pick faster!
The problem is that the assembler gives up on pass 1 because it hasn't expanded the "%" into a number yet. Because of the unexpanded "%", SASM looks in the symbol table to verify that there is no other symbols with the same name, finds the exact same symbol and flags it as an error. This is one of those, "Is it a bug or a feature?" kind of situations. You want the assembler to prevent duplaictae names (feature), but you want it to recognize that the "%" means you have to wait until pass two to figure out if there is a duplicate (bug ).
The fix requires changes to the SASM source code. I'm pretty sure there's no way to "trick" the assembler into doing what you want it to do.
Thanks,
PeterM
I played with it a bit more and realized it's really a feature and not a bug. The problem is that the percent sign is a perfectly legitimate character to use in a label. For example, a label like this...
L%a%b%b%e%l%
...is just a label. For SASM to handle it differently inside a repeat could have some unintended side effects. Specifically, any code that counted on "%" being a regular character for labels in or out of repeats would suddenly stop assembling correctly if SASM was changed to handle "%" differently inside of repeats. Now, how many people use "%" in their label names? Not a clue. I would assume a small number, but I imagine they would be really annoyed when the next version of the IDE stopped assembling their code. Not sure what the best solution would be for this.
Thanks,
PeterM
Thanks, I will do it the manual way ($+nn) and just put a comment to check it if I alter the code. In general I am happy with the SX environment compared to other assemblers/compilers.
Best regards
Mark
_myjumptable macro
· local loc
· jmp loc
· nop
loc
endm
rept 16
· _myjumptable
endr
(Thanks James, for pointing us again to the power of·macros)
regards peter
Nice work! I'm not a real user of macros with the SX (sorry James) so I had to check the manual to see what was going on with your code. Clever stuff. Apparently, the fine folks who originally wrote SASM must have encountered a similar circumstance to Mark. Here's what the manual says (and for those who want to play along at home, it's on page 63) :
The syntax for the LOCAL directive is
LOCAL <label>[noparse][[/noparse], <label>]…
It declares the labels named after the directive as private symbols. Private symbols are available only
inside a macro body. These symbols are private to each invocation of the particular macro and cannot
be referenced outside of the macro body.
The private symbol is used within a macro body just like any other label. Each time the macro is
invoked, SASM will assign each private symbol a unique name of the form ??0001, ??0002, ??0003, and
so forth. The unique name will appear in the listing file in place of all uses of the text of the private
symbol.
All LOCAL directives must appear immediately after the MACRO directive and before the first actual
line of the macro body.
Cool.
Thanks,
PeterM
Thanks very much, I never would have figured that out. Ill give it a go.
Mark