Hello everyone,

I just started recently with the Learn ASM in 28 Days Tutorial, and I've understood most of the basic stuff (binary, hex, base ten, basic commands, ROM calls, etc.) but I'm having a problem understanding what registers are and how they work.

Help? Please formulate your answer in the easiest possible way...I'm already having trouble with this Very Happy

Registers are your basic unit of data storage in asm. Basically, if you want to be doing something to data, you'll be using a register. If you're familiar with other programming languages, just think of them like a fixed set of variables. You use variables to hold data, and you use registers to hold data. Sometimes you need to hold more data, and then you use actual data sections, but you use the registers to point to the data (and hold bits of it as you go).

There are also some special registers, namely PC and SP. PC (program counter) holds the current location in the code where you're executing. So after each line of code it's incremented. Jumping modifies this value to point to a specific line. SP (stack pointer) is the current location in the stack, so when you push this is changed, and when you pop it's changed back to where it was before the push.
Thanks Very Happy
So where would you store data ? Is it stored in specific memory addresses or just databytes (db.) as a lookup table ?
ti83head wrote:
So where would you store data ? Is it stored in specific memory addresses or just databytes (db.) as a lookup table ?

You can do either. The most common choice is to store data in the "safe" locations in RAM, eg. on the TI-83+, "appbackupscreen". A quick example of this:

#define var1 appbackupscreen
#define var2 appbackupscreen+1

 ld a,19
 ld (var1),a
 ld a,63
 ld (var2),a

This loads the register A with those values, and then saves them to the memory locations that are defined above. Noting that the register A is an 8-bit register, so to save it only requires 1 byte of RAM space.

The other .db method you mentioned is also an option, although this means permanently allocated memory, as the .db definitions take up space in your program (sometimes this has specific uses):

 ld a,10
 ld (var3),a
 ld a,11
 ld (var4),a

var3: .db 0  ; empty byte for storage
var4: .db 0

Hope that makes sense - I'm a terrible teacher! Smile
Hardly a terrible teacher! Just to clarify something that people are often confused about: those #define lines aren't reserving RAM for you. Appbackupscreen is 768 bytes, and it remains 768 bytes no matter how much of it you use. All that the #define lines do is give locations within those 768 bytes other names, so you can refer to then directly. If you #define two different variables at the same address, they'd be the same variable (or always have the same value, if that's easier to think about).
Thats really easy to understand - thanks !
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum