user3534700
user3534700

Reputation: 11

ASM Assembly code to create first 16 Fibonaaci numbers

I'm looking to create the first 16 fibonacci numbers in ASM assembly code and store them in my microprocessor starting from location 0x300 I have

ldi r16, 0  #load register 16 with 0
ldi r17, 1
add r17, r16  
mov r18, r17
sts 0x300, r18  #store first number in 0x300
mov r16, r17
mov r17, r18
rjmp loop

My issues are how do I stop after 16 numbers & how to store each number in 0x301, 0x301...0x315 I am unclear as what to put after mov r17, r18 to increment 0x300 to 0x301 and enable count

Upvotes: 1

Views: 1694

Answers (1)

Jarek
Jarek

Reputation: 11

@stop after 16 try to add a counter

   ldi r20,16 #loop counter
start:
...#your loop body
dec r20
brne start

@how to store each number in 0x301, Read about "indirect addressing" There is a X indirect register:

X,Y,Z: Indirect Address Register (X=R27:R26, Y=R29:R28 and Z=R31:R30) so you should put your address in X, and use "st X+,Rr"

clr r26 #this is lower 00 from 0x300
ldi r27,3 #this is higher 3 from 0x300 and here you've got X set to 0x300
...#some of your code
st x+,r18 #where r18 got data to be stroed in memory. x will be increased automaticly

Upvotes: 1

Related Questions