Author Topic: Simple question about the "$" pointer in TASM  (Read 4450 times)

0 Members and 1 Guest are viewing this topic.

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Simple question about the "$" pointer in TASM
« 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

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Simple question about the "$" pointer in TASM
« Reply #1 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 $.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Simple question about the "$" pointer in TASM
« Reply #2 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. ;)
« Last Edit: August 13, 2010, 04:27:29 am by Runer112 »

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Simple question about the "$" pointer in TASM
« Reply #3 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.
« Last Edit: August 13, 2010, 12:22:34 pm by calcdude84se »
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: Simple question about the "$" pointer in TASM
« Reply #4 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))
« Last Edit: August 13, 2010, 01:15:41 pm by Hot_Dog »

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Simple question about the "$" pointer in TASM
« Reply #5 on: August 13, 2010, 01:27:39 pm »
That's in Spasm only. My example was for Brass ;D
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Simple question about the "$" pointer in TASM
« Reply #6 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.

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Simple question about the "$" pointer in TASM
« Reply #7 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?
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Simple question about the "$" pointer in TASM
« Reply #8 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. ;)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Simple question about the "$" pointer in TASM
« Reply #9 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.)
Now active at https://discord.gg/cuZcfcF (CodeWalrus server)

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Simple question about the "$" pointer in TASM
« Reply #10 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.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Simple question about the "$" pointer in TASM
« Reply #11 on: August 14, 2010, 01:23:45 pm »
Aaah ok ^^
Now active at https://discord.gg/cuZcfcF (CodeWalrus server)

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Simple question about the "$" pointer in TASM
« Reply #12 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).
« Last Edit: August 14, 2010, 01:40:24 pm by Runer112 »