assembly - Why is ASLX required when reading values from INT array -


trying better understanding of working integer arrays , came across issue.

q: when printing elements of array , don't use aslx unexpected results, when use aslx expected results. how aslx effect result?

food:.word   0                 .word   1                 .word   1             .word   0  main:ldx     3,i         ; = 3      stx     i,d  for: cpx     0,i         ; >= 0      brlt    endfor      deco    i,d      charo   ' ',i      aslx                ; if remove 256 instead of expected value      deco    food,x   ; food[i]      charo   '\n',i      ldx     i,d      subx    1,i      stx     i,d      br       endfor:  stop       .end 

thanks

asl, or arithmetic shift left, shifts of bits of number left. 0001 becomes 0010, 0100, , on. equivalent multiplying number two.

when use aslx command, double index register. when working integer array because integers take 2 bytes, , index register measured in single bytes.

in other words, if increment/decrement index register 1, end "between" integers, such reading last byte of 1 , first byte of another. that's why strange results if don't aslx.

another option might make more clear can increment/decrement index register two. won't have shifting, since stay aligned array of integers.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -