Hello!

I'm trying to get into learning assembly for my TI84+CE calculator for a project I've wanted to do since high school. I know C and have a basic understanding of how low level computing works (I know binary, how registers work, roughly what the stack does, etc). I've picked up a tutorial I found on the website (https://github.com/CE-Programming/asm-docs), downloaded the docs, and am currently working through the tutorials. I've gotten to tutorial 3 with taking keypad input, and am going through the commands to see what's wrong with a slight modification. However, I've gotten to a line of self-modifying code.
Code:
xPos := $ - 3
. The tutorial identifies it, but doesn't explain what self-modifying code means. I've tried googling examples, but everything I get is just a solution for another problem and not an explanation. Does anyone know what it does? Does the $ reference position?

The only part I understand is that := means that the variable (xPos) is being defined as $-3. But again, beyond that I have no clue. Sorry if this is an easy problem who's solution is super obvious!
$ basically refers to the current instruction's position. Since the last 3 bytes of a ld hl,Mmn instruction are the bytes to store in hl, the address of those 3 bytes is the address of the instruction after the ld hl, but minus three bytes. Storing data to that location will change what bytes are loaded into hl.
So, for example, if you had the code:

Code:
routine:
ld hl, 0
xPos := $-3
ret

smc:
ld de,042h
ld (xPos),de
ret

the ld hl,0 would assemble to the bytes 21000000 in memory. After you call the smc routine, the ld hl,0 instruction gets changed in memory from 21000000 to 21420000, which turns it into a ld hl,042h instruction instead. Calling routine afterwards would set hl to 042h instead of 0.
  
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

 

Advertisement