0

I im learning avr assembler and would like to ask how can i read specific value from array? Here is my code that works very well and it stores digit array into SRAM...now how for example i could read value 6 from digit array?

.include    "m328pdef.inc"

.DSEG
        digit:  .Byte 9         ; Segment Digit
.CSEG
.ORG    0x0000
rjmp    _Reset

_Reset:
        ldi     yl,byte1(RAMEND)
        out     SPL,yl
        ldi     yh,byte2(RAMEND)
        out     SPL+1,yh
        sbiw    yl,32

    ; Digit Store To SRAM
    ldi     XH, HIGH(digit)
    ldi     XL, Low(digit)
    ldi     R16, 0x3F           ; Digit 0
    st      X+, R16
    ldi     R16, 0x06           ; Digit 1
    st      X+, R16
    ldi     R16, 0x5B           ; Digit 2
    st      X+, R16
    ldi     R16, 0x4F           ; Digit 3
    st      X+, R16
    ldi     R16, 0x66           ; Digit 4
    st      X+, R16
    ldi     R16, 0x6D           ; Digit 5
    st      X+, R16
    ldi     R16, 0x7D           ; Digit 6
    st      X+, R16
    ldi     R16, 0x07           ; Digit 7
    st      X+, R16
    ldi     R16, 0x7F           ; Digit 8
    st      X+, R16
    ldi     R16, 0x6F           ; Digit 9
    st      X+, R16

    ; Digit Read From SRAM
    ldi     XH, HIGH(digit)     ; load X = address of digit array
    ldi     XL, Low(digit)      ; ...high Byte also

    add     XH, R24             ; add the array index
    Adc     XL, R25             ; ...And add 0 To propagate the carry
    ld      R26, X              

rjmp _Reset

So in this example in simulator i need to get for read value 6 in my digit array it should get me value: 0x7D, if i would like to read value 9 in array i need to get 0x6F.

I success write array to SRAM and reading is only first index (0x3F) so how can i specifiy what index in array to read?

Thanks

Igor Petev
  • 597
  • 2
  • 6
  • 24
  • You didn't set `r24/25` to anything. Other than that, it looks about right. – Jester Apr 06 '18 at 21:10
  • Could you please write example how to set for example value 6 in digit array? I im begginer and don't know how to set that... – Igor Petev Apr 06 '18 at 21:11

1 Answers1

1

I just added HIGH and LOW into R24 and R25 and now is working..in simulator i see value read from array:

ldi     XH, HIGH(digit)     ; load X = address of digit array
ldi     XL, Low(digit)      ; ...high Byte also

ldi     R24, HIGH(6)        ; Read index 6 value from digit array High Byte
ldi     R25, Low(6)         ; Read index 6 value from digit array Low Byte

add     XH, R24             ; add the array index
Adc     XL, R25             ; ...And add 0 To propagate the carry
ld      R26, X              
Igor Petev
  • 597
  • 2
  • 6
  • 24