Some optimizations that pop (no pun intended) out:


Code:
.nolist
#include "ti83plus.inc"
.list
.org $9D93
.db t2ByteTok, tAsmCmp
   b_call(_ClrLCDFull) ; Clear Screen
   ld hl, $0000 ; Random coordinates to test printing location
   call numInput ; My Input Routine
   ret
numInput:
   ld (CurRow),hl
   ld hl, $0000
top:
   b_call(_GetKey); Get first key
   ld b, a ; // ------ Check within numeric range ------
   ld a, 152
   cp b
   jr c, top
   ld a, b
   cp 5
   jr z, finish ; // End input if enter pressed
   ld a, 141
   cp b
   jr nc, top ; // ------ End numeric check ------
   ld a, b
   sub 94
   b_call(_PutC) ; // this bcall automatically advances CurRow/CurCol
   sub 48
   ld d, h
   ld e, l
   add hl, hl
   add hl, hl
   add hl, de
   add hl, hl
   ld b, 0
   ld c, a
   add hl, bc
   jr top ; // Goto top
finish:
   ld de, $0504
   ld (CurRow), de
   b_call(_DispHL)
   ret
.end
.end
[/quote]
Jacobly's code won't work since _GetKey modifies HL.
Here's what i got:

Code:
numInput:
   ld (curRow),hl
   ld hl, $0000
   ld b,h      ;set b to 0
top:
   push hl      ;_GetKey modifies HL
      bcall(_GetKey); Get first key
   pop hl
   cp 5
    jr z, finish ; // End input if enter pressed
   sub 142      ;k0
    jr c,top
   cp 10      ;k9
    jr nc, top

   ld d, h
   ld e, l
   add hl, hl   ;x2
   add hl, hl   ;x4
   add hl, de   ;x5
   add hl, hl   ;HL x 10
   ld c, a
   add hl, bc

   add a,$30   ;convert number to ASCII

   bcall(_PutC) ; // this bcall automatically advances CurRow/CurCol
   jr top ; // Goto top
All the loading a into b and b into a and comparing b to a etc. was unnecessary, the value of a never changes so you can just compare an immediate value (a number) directly. Smile It's a nice code! How about making it into a full text input routine? Or, more challenging, using _GetCSC to input your numbers Smile

EDIT: Originally i had just posted "top:" but i realized i made a small change just above it (the ld b,h) so edited to include that. The main changes i made were removing the ld b,a stuff and subtracting 142 ($8E = k0) instead of comparing. It saves us from having to do an extra cp.

Also, in the future it might be worthwhile to either provide equates for the numbers or at least provide a comment as to what the number means. It'll help you remember later on and it'll help other people who read your code. It's a nice start, though!
Thanks for the help both of you Very Happy By using both ideas, i got down to 40 bytes for the routine, which I'm surprised at:

Can i change anything else after this to be better?


Code:
.nolist
#include "ti83plus.inc"
.list
.org $9D93
.db t2ByteTok, tAsmCmp
   b_call(_ClrLCDFull) ; Clear Screen
   ld hl, $0000 ; Random coordinates to test printing location
   call numInput ; My Input Routine
   ret
numInput:
   ld (CurRow),hl
   ld hl, $0000
top:
   push hl
   b_call(_GetKey); Get first key
   pop hl
   ; // ------ Check within numeric range ------
   cp 5
   jr z, finish ; // End input if enter pressed
   sub 142 ; Checking upper limit
   jr c, top
   cp 10 ; Checking lower limit
   jr nc, top ; // ------ End numeric check ------
   ld d, h ; // -- Multiply by 10 --
   ld e, l
   add hl, hl
   add hl, hl
   add hl, de
   add hl, hl
   ld b, 0 ; // Add (append) a to the end of the last digit
   ld c, a
   add hl, bc
   add a, $30
   b_call(_PutC) ; // Show the next number / Automatic CurRow and CurCol advancement
   jr top ; // Goto top
NumInputEnd:
finish:
   ld de, $0504
   ld (CurRow), de
   b_call(_DispHL)
   ret

.echo "The routine NumInput is "
.echo NumInputEnd - NumInput
.echo " bytes in size.\n"

.end
.end
Okay, So I moved onto day 13, and came across this code:


Code:

Or you can change the target of a JR or DJNZ.
    LD     A, B
    ADD    A, A
    LD     (Jump), A
Jump    .EQU    $+1
    JR     $00
    INC    IX    ; JR $00
    INC    IX    ; JR $02
    INC    IX    ; JR $04
    INC    IX    ; JR $06
    INC    IX    ; JR $08
    INC    IX    ; JR $0A


This is under the category of SMC (Self-Modifying Code). So Far I get that B is doubled, which is subsequently in register A. and I also got line 3, which is putting the value of A (Doubled B) into the location at which (Jump) points. However I don't get the equalization after that, and the rest that follows. Also, could someone please explain what is $ a bit more clearly, and that doing $+# or $-# is doing in case, and why I may need it.

Thanks in advance, and for all the help on the irc!
$ is the address of the current instruction. For example:

Code:
8000     LD     A, B
8001     ADD    A, A
8002     LD     (Jump), A
8005
     Jump    .EQU    $+1
8005     JR     $00
8007     INC    IX    ; JR $00
Here, $ points to the address $8005, or the first byte of the JR instruction. $+1 points to $8006, or the second byte of the JR instruction. $-1 would point to $8004, or the MSB of the label Jump. The first byte, at $8005, is the opcode. The second byte tells us how many bytes we want to jump. Each inc ix takes up two bytes, that's why we multiply by two. If b = 0, we'll load 0 into $8006 which will simply jump to the next instruction. If b = 1, 1+1=2 so we turn the JR $00 into JR $02, so it skips the first inc ix instruction. One thing to keep in mind is that the $ is processed before the instruction, so in:

Code:
8000    jr $
$ points to $8000. JR $ is essentially an infinite loop. If you want to jump to the next instruction, you need JR $+2 (because JR takes up two bytes).

If you want to look at it another way, you could see it as this:

Code:
8000     LD     A, B
8001     ADD    A, A
8002     LD     (Jump+1), A
8005 Jump:
8005     JR     $00
8007     INC    IX    ; JR $00
..or even:

Code:
8000     LD     A, B
8001     ADD    A, A
8002     LD     (Jump), A
8005 CUR_ADDR:
8005 Jump = CUR_ADDR+1
8005     JR     $00
8007     INC    IX    ; JR $00
  
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 3 of 3
» 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