Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: Runer112 on August 13, 2010, 01:40:04 am

Title: Simple question about the "$" pointer in TASM
Post by: Runer112 on August 13, 2010, 01:40:04 am
I believe that the symbol "$" when used alone represents a pointer to the current location in a program. However, I am not sure exactly how it would work in the middle of a line. Take the following code as a simple example:

Code: [Select]
loop:
dec c
jr nz, loop

If I wanted to replace loop with $ and an offset (so I can use this loop as a macro), would the "$" not account for the size of anything on the current line, in which case (I believe) I would need $ - 1? So the following code would be identical?

Code: [Select]
dec c
jr nz, $ - 1
Title: Re: Simple question about the "$" pointer in TASM
Post by: Quigibo on August 13, 2010, 02:14:28 am
That's correct, you have the right idea.  The only weird thing about it is that the actual machine code generated DOES account for the size of the line.  So if you look at the hex code and see that its moving back 3, just remember that's why so don't let it confuse you that what you write in the assembler looks different than the machine code.  The way you're doing it is correct for all the major assemblers.  I'm not sure if there are any assemblers that count the current line when using $.
Title: Re: Simple question about the "$" pointer in TASM
Post by: Runer112 on August 13, 2010, 04:26:45 am
Alright, thanks for the cofirmation. After trying it like 3 years ago and failing horribly, I've come back to take another stab at z80 assembly. I think having used Axe for a while kind of helped to step me into it (a great thing about Axe, it's a wonderful stepping stone to assembly). This time I tried to teach myself it, I knew a lot more and, instead of having to grasp both the whole new syntax and new concepts at once, I already had a lot of the concepts down. Perhaps in a short while I could even start helping with routines. ;)
Title: Re: Simple question about the "$" pointer in TASM
Post by: calcdude84se on August 13, 2010, 12:21:25 pm
In assemblers like Brass and Spasm, you can use specially named labels for local purposes.
For example, in Brass syntax, your above loop could be
Code: [Select]
-
    dec c
    jr nz,{-}
And you can use it again later in a similar manner, with no naming conflicts. Note that Spasm's syntax is different.
Depending on what you're doing, this could also be a good solution. (You will have to upgrade from TASM, though ;D)
Edit: Note that in Brass, you aren't required to put colons after your labels in most circumstances.
Title: Re: Simple question about the "$" pointer in TASM
Post by: Hot_Dog on August 13, 2010, 01:15:17 pm
Yeah, the trouble with using $ is if you all of a sudden have to add lines of code, you have to recount the number of bytes necessary.

I found the local labels very useful, as I was tired of trying to come up with names for each and every label.

By the way, calcdude84se, you can also go jr nz, -_ (jump to one underscore backwards))
Title: Re: Simple question about the "$" pointer in TASM
Post by: calcdude84se on August 13, 2010, 01:27:39 pm
That's in Spasm only. My example was for Brass ;D
Title: Re: Simple question about the "$" pointer in TASM
Post by: Runer112 on August 13, 2010, 03:28:10 pm
Oh, well I don't have to worry about the number of bytes changing or anything, because these are fixed macros. That's the main reason I wanted to steer clear from labels, just so I wouldn't have to worry about weird things like label names in macros or name conflicts or anything.
Title: Re: Simple question about the "$" pointer in TASM
Post by: calcdude84se on August 13, 2010, 03:32:38 pm
Oh, yeah, for macros you definitely want to use $. Using reusable labels can cause problems in such a circumstance.
What are you writing, btw?
Title: Re: Simple question about the "$" pointer in TASM
Post by: Runer112 on August 14, 2010, 12:49:18 pm
Oh, yeah, for macros you definitely want to use $. Using reusable labels can cause problems in such a circumstance.
What are you writing, btw?

It's nothing new, but I'm still trying to keep it under wraps a bit. ;)
Title: Re: Simple question about the "$" pointer in TASM
Post by: DJ Omnimaga on August 14, 2010, 12:55:45 pm
(This is off-topic, but I notice a lot of ASM questions lately from people who joined the Axe Parser programming contest. I just want to remind people that ASM/Axioms usage is against the contest rules, in case this is what they are planning to do.)
Title: Re: Simple question about the "$" pointer in TASM
Post by: Runer112 on August 14, 2010, 01:17:23 pm
No, I'm not planning that. What I'm working on isn't a game and could never be implemented into one.
Title: Re: Simple question about the "$" pointer in TASM
Post by: DJ Omnimaga on August 14, 2010, 01:23:45 pm
Aaah ok ^^
Title: Re: Simple question about the "$" pointer in TASM
Post by: Runer112 on August 14, 2010, 01:39:34 pm
If it could be implemented into a game, that would be sick. But I'm pretty sure that it couldn't, because this is very processor intensive and needs to be constantly running (much more quickly than any interrupt would allow).