I've been trying to learn about micro controllers and assembly for more than a week now. as i learn more I'm trying to improve the code I've written. I had a code that would display numbers on 7 segment display and it worked as intended but I wanted to have shorter code so after I learned few things about storing data in sram i made something like this:
.equ startPtr = 0x0700 init: ldi r16,0b00111111 sts startPtr+0,r16 ldi r16,0b00000110 sts startPtr+1,r16 ldi r16,0b01011011 sts startPtr+2,r16 ldi r16,0b01001111 sts startPtr+3,r16 ldi r16,0b01100110 sts startPtr+4,r16 ldi r16,0b01101101 sts startPtr+5,r16 ldi r16,0b01111101 sts startPtr+6,r16 ldi r16,0b00000111 sts startPtr+7,r16 ldi r16,0b01111111 sts startPtr+8,r16 ldi r16,0b01101111 sts startPtr+9,r16 ret
basically I'm storing binary code for every number. I can load them whenever I want by typing lds r16,startPtr+[Number I Want To Display]. but I have to type the number by hand.
instead im trying to figure out if something like this is possible
ldi r20,3 lds r16,startPtr+r20
so i would just have variable for the number i want to display instead of making lots of "cpi" commands like i did here
cpi r20,0x00 breq zero cpi r20,0x01 breq one cpi r20,0x02 breq two cpi r20,0x03 breq three cpi r20,0x04 breq four cpi r20,0x05 breq five cpi r20,0x06 breq six cpi r20,0x07 breq seven cpi r20,0x08 breq eight cpi r20,0x09 breq nine