Following in the footsteps of the others learning asm, I decided to create a topic for questions.

1) Using .db or .dw to define a variable, can you give it a name? How would you do that.

.db var_name, value
Yay, I'm glad you started your own assembly learning thread! You can indeed, but that's not how you do it. If you want temporary storage for the life of the program (but don't care where the data goes when your program ends) you should use SafeRAM. For example, SafeRAM1 (assuming you're coding for Doors CS) is at AppBackupScreen, so you could do:


Code:
tankX .equ AppBackupScreen ;1 byte
tankY .equ tankX+1 ;1 byte
score .equ tankY+1 ; 2 bytes
level .equ score+2 ;1 byte
Notice the relationship between the byte length of each "variable" and the +X for the next item. Also, this makes it that you can move the whole batch to a different SafeRAM area just by changing the first line.

If you want storage that stays constant between different runs of your program, so that you could store something like a high score, Doors CS does intelligent writeback, so you could have this near the end of your program:

Code:
HighScore:
    .dw 0     ;a 2-byte high score
HighScoreLevel:
    .db 0      ;a 1-byte area, perhaps storing the highest level reached
HighScoreName:
    .db 0,0,0,0,0,0,0,0,0   ;allow 8 bytes for the player name, plus zero term
Yup. Thanks. I already get the difference between .db (inserts a byte) and .dw (inserts a word). And Axe follows the conventions for jumping the offset by two when storing a word. So, thus far this has been easier than expected. Also, I've seen this:

.db $61,$0A stores as 0A61
.dw $610A stores as 610A

I'm at a loss on this. Does this mean that the .dw directive makes it not store in little endian?
No, because that's backwards.

.db $61,$0A stores $61,$0A
.dw $610A stores $0A,$61
Oh. I see. Now on a more technical note, where does the calculator store active interrupts? Active hooks? And flags?
ACagliano wrote:
Oh. I see. Now on a more technical note, where does the calculator store active interrupts? Active hooks? And flags?
Interrupts are shoved into any piece of memory you can find for them. For example, Doors CS has a CALCnet interrupt stub in RAM that calls a larger interrupt routine in Flash. The pointer to the interrupt is partially stored in the 'i' register. Hooks are also in either RAM or Flash; the page and address of each hook is kept in a bunch of RAM areas of four bytes each. Flags are stored at (iy+N); iy is fixed to point to $89F0.
I think I got this

A Good Multiplication loop?

Code:
ld a, product1
ld c, product2

ld b, c

MultLoop:

add a, c
dec b
jr b, MultLoop


A Good Division Loop?

Code:
ld a, divisor
ld c, dividend

ld b,0

DivLoop:

 sub A,C
 jr c,DivEnd
 inc B
 jr DivLoop

DivEnd:
 add a,c
 ret


Are these correct?[/code]

Code:
MultLoop:

add a, c
dec b
jr b, MultLoop
That's not how jr [flag],[label] works. There are several flags that you care about, including z[ero], nz[not zero], c[arry], nc[no carry], pe[parity even], po[parity odd], etc. You actually mean jr nz: you want to jump only if b is not zero. Nevertheless, here's the correct way to do that:


Code:
    ld a, multiplier
    ld c, multiplicand // product = multiplier * multiplicand

    ld b, c
;HAVE TO DEC B here!
    dec b

MultLoop:
    add a, c
    djnz MultLoop  ;faster way to do dec b \ jr nz[label]
Didn't look at your division routine yet.
Ah. Ok. I was wondering what the z and nz and the others meant. On that note, is there such a thing as

if c
if c=n

in asm, or are u limited to things like jr z
Second statement is correct, you have to use the jr or jp command but you can link conditionals:

Code:

ld a,some number
cp 100  ;checks if a=100
jr z,label if a=100
cp 50  ;checks if a=50
jr nz,label ;if a>50

I think this is right ***glances at KermM
Calcman, your code is incorrect, cp 50 \ jr nz,Label will jump to Label only if a is not equal to 50, not just if a is greater than 50.
I forgot what is greater than, is it c?
jr nc,label is what you want. C would be set if you tried to compare a smaller number with a larger number.
So, wait, let me get this straight.

jr z, label ; jumps if zero
jr nz, label ; jumps if non-zero
jr c ; jumps if comparing larger to smaller
jr nc ; jumps if comparing smaller to larger

anything else?
jr has a disadvantage though, it can only jump forward 129 bytes or backwards 126 bytes (as if that is easy to find out), but a similiar function is jp if jr cannot reach it, jp can jump to any label even outside of program so you have to be careful and use a label nowhere else.
Well there are more flags, pe, m,po and p. I normally don't use those though.
A JR statement is smaller than a JP statement, and if your JR statement jumps more than it is able to in your source your compiler will notify you.
And I know a lot of people are using Mimas, so one thing you could do, rather than figure out if it should be jr or jp, is use jq. jq is an instruction Mimas added that will automatically choose between jr and jp depending on how far the jump is. If it is too far, jp, else, jr.
That's handy and great to know. Calcman, jump relative (jr) will go up to 127 bytes forward, or 128 backwards. pe and po are mainly useful for parity checking and interrupt-related functionality. m and p are minus and plus, but you can generally fake them with c and nc; m and p have the disadvantage of only working with jp and not jr.
Guys, I'm going to attempt a program (as a prank) that will monitor keypresses and, if a select few keys are pressed, display "Moron" on the last line of the Screen. This must continue to run after the program exits. The only help I need is: Where in memory can I put such an interrupt? And how do I write the start of the interrupt into memory?

Here's what I have:


Code:
.nolist
#include   "ti83plus.inc"
.list
.org   $9D93
.db    t2ByteTok, tAsmCmp

   b_call(_ClrLCDFull)
   
   
Install:      ; How the hell do I install the darn thing?
   
   
Interrupt:                   ; This will be the start of the interrupt itself
   b_call(_getCSC)
   jr nz,Display
   ret
   
Display:
   ld a,0
   ld (CurCol),a
   ld b,7
   ld (CurRow),b   
   ld hl,msg
   b_call(_PutS)
   ret
   
msg:
.db "Moron",0
.end
.end   
This wouldn't be an interrupt, it would be either a Raw Key or getCSC hook.
  
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 4
» 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