turbomen
Newbie level 1
Please help me on AVR IV
It is the hardest question to me.
Using any resources available, but only 1 register for the entire program, do the following:
Create 3 single byte variables in SRAM called NUM1, NUM2 and NUM3. You may create no more variables.
Load the values $02 $04 and $06 into NUM1, NUM2 and NUM3 respectively.
Write a program that does the following in sequence:
Swap the contents of NUM1 and NUM2
Swap the contents of NUM1 and NUM3
Swap the contents of NUM2 and NUM3
But remember, you may use any resources available, but only 1 register may be used for the whole program!
The final result will have NUM1 = $06
NUM2 = $04
NUM3 = $02
The following is my work. Please help me on this.
It is the hardest question to me.
Using any resources available, but only 1 register for the entire program, do the following:
Create 3 single byte variables in SRAM called NUM1, NUM2 and NUM3. You may create no more variables.
Load the values $02 $04 and $06 into NUM1, NUM2 and NUM3 respectively.
Write a program that does the following in sequence:
Swap the contents of NUM1 and NUM2
Swap the contents of NUM1 and NUM3
Swap the contents of NUM2 and NUM3
But remember, you may use any resources available, but only 1 register may be used for the whole program!
The final result will have NUM1 = $06
NUM2 = $04
NUM3 = $02
The following is my work. Please help me on this.
Code:
;Program name: task4
;Author: Tony
;Date: 11 June 2009
;Purpose: To create 3 single byte variables in SRAM called NUM1, NUM2 and NUM3...
.include "8515def.inc" ;Include file contains all register addresses
ldi num2, high (RAMEND) ;high(RAMEND) is higher byte of $025F which is $02
out SPH num2 ;SPH loaded with $02
ldi num1, low (RAMEND) ;low (RAMEND) is lower byte
out SPL num1 ;SPL LOADED WITH $5F
Start
push num2 ;Push num2 to stack, same sp decrements again
Finish:
rjmp Finish ;End of program