REP @_Done,#9 syntax question
What does @ do In PASM ? I have been accessing an address with:' MOV addressDone,#Done.
Looking at the following code:
DAT
ORG 0
S0_REP DRVH #P0 'P0 on program running
MOV AddressDone,#_Done
debug("--------------------------------------")
debug("before REP ",udec(D_REP),udec(S_REP),udec(ResultAddOne),udec(AddressDone))
REP @_Done,S_REP
ADD ResultAddOne,#1
_Done debug("after REP ",udec(D_REP),udec(S_Rep),udec(ResultAddOne),udec(AddressDone))
debug("--------------------------------------")
_Loop1 NOP
JMP #_Loop1 'remember # imediate
ResultAddOne long 0
AddressDone long 0
S_REP long 9
If @_Done is changed to #_Done it doesn't work so @ doesn't mean address what does it mean in this context. Help!
Regards and Thanks
Bob (WRD)
Comments
The @address syntax when used with REP allows the assembler to calculate how many instructions are contained in the REP block.
Is this the only instruction in PASM that uses @syntax and is this calculation stored in the HUB Memory it doesn't appear to be in the cog memory?
Is there some documentation stating the usage?
Thanks for Response
Regards
Bob (WRD)
the REP instruction needs (the number of ins to repeat)-1 so the calculation is done by the compiler and the result is stored in the rep instruction generated.
Since instruction counting and adjusting is tedious, Chip added this syntax to look a bit alike the P1 syntax, consider the pair of labels
xxx and
xxx_ret
which also create a instruction when you write CALL xxx and the compiler writes a JMPRET instruction for you.
So you can use rep without any label, but it is more tedious.
That it is @ again its just another quirk with @, Chip likes the character, somehow.
The @ ins and the friends @@ and @@@ are usually a Spin-thing but often used in DAT sections thus also valid for assembler.
So in the case of REP the @ has a complete different meaning as it usually has, it is NOT the HUB address of that label, just a hint for the compiler to help you counting.
With Spin2 and the relative addressing using @ to fetch a HUB address from assembler is a challenge in itself, I was not yet to master.
Enjoy!
Mike
I have to admit I also was puzzled as to why # wasn't used. I wasn't particularly into Spin so never said anything at the time.
Please put code in a code block by using three consecutive backquote/backtick characters at the start and end. You can do this for a block of code and within a sentence, e.g.
If
@_Done
is changed to#_Done
it doesn't work so@
doesn't mean address what does it mean in this context.You can see what character to use by clicking on Quote.
I think Bob is asking if there's a reason why Chip didn't just use # instead of throwing in yet another variation of @. That's how I read it anyway.
Yes from Bob. It just seems to be little more intuitive because it is immediate value to calculate number of instructions in between instruction and the remaining code.
Regards
Bob (WRD)
#
is used for the number of instructions to repeat. This can also be #LABEL (mostly with a constant as label). So the Assembler needs a way to distinguish between #constant and #address. Chip made it easy and used a special character for that. Maybe the assembler does not know if a label comes from a constant or a cog address at the time it has to do the calculation.Andy
Okay, I think I see. But branching instructions have the same conflict. A JMP #label is going to use the symbol's address rather than its content. I'd be happy for REP to fit in that category. And I'd be happy to convert my existing code to suit the change too.
the jmp ins uses the address (with #) or the content of the Label without.
the rep ins needs the offset (in ins) of the address of the label from the address of the rep ins.
so it does not fit in the same category and a different symbol was needed for the compiler.
sort of
Mike
Offset is same as address. There is relative branchings too, even JMP has relative capability. REP really is a branching instruction now I think about it.