Calculator Community > ASM

Help with loops?

(1/2) > >>

joshuarpl:
I think I learned that jr F1 is to loop an assembly program, but how do you loop an assembly program but have the option to press CLEAR to quit?

Xeda112358:
A simple way is to do something like:

--- Code: ---loop:
  bcall(_GetCSC)
  cp 15     ; check [clear]
  jr nz,loop
  ret

--- End code ---
But if you want the more complicated (and less energy efficient :P) way:

--- Code: ---  di   ;disables interrupts since the OS will mess with port 1
  ld a,$FD ;we'll be polling for keys [ENTER] up to [CLEAR]
  out (1),a
loop:
  in a,(1)
  and $40 ;checks bit 6 which corresponds to clear. Set if not pressed, reset if pressed
  jr nz,loop
  ret

--- End code ---
But my preferred way is:

--- Code: ---  ei     ;keep OS interrupts active
loop:
  halt    ;
  ld a,(kbdScanCode)
  cp 15
  jr nz,loop
  ret

--- End code ---

joshuarpl:
Found my own way!
Hex

--- Code: ---:AsmPrgm
:EF1840
:FE0F
:C8
:18F1
:C9
--- End code ---

Assembly

--- Code: ---bcall $4018
cp 0F
ret z
jr F1
ret
--- End code ---

Didn't try your code, but still, thanks for helping me out a little bit.
Also, I tested it on my physical TI-84+ and Wabbitemu, and they both act the same, they both work.

Sue Doenim:

--- Quote from: joshuarpl on March 24, 2019, 11:51:19 pm ---Found my own way!
Hex

--- Code: ---:AsmPrgm
:EF1840
:FE0F
:C8
:18F1
:C9
--- End code ---

Assembly

--- Code: ---bcall $4018
cp 0F
ret z
jr F1
ret
--- End code ---

Didn't try your code, but still, thanks for helping me out a little bit.
Also, I tested it on my physical TI-84+ and Wabbitemu, and they both act the same, they both work.

--- End quote ---
Note that jr $F1 will only work if the opcode is always at the exact same spot in the program (i.e. 7 bytes into the program).  Also, it kinda seems to me like you're trying to do coding on-calc/without a computer.  If that's the case, I would advise using Mimas.  It's a really nice app where you can write and compile ASM programs on-calc, and it's definitely much better than working in raw hex.

Xeda112358:
Actually, jp points to a fixed location whereas jr is relative. So in this case, jr $F1 (18F1) just states that it will jump back 15 bytes from the end of the instruction.

Navigation

[0] Message Index

[#] Next page

Go to full version