I need to create a simple function that calculates the surface of a rectangle(a simple a*b program). However the value of registers(including R0 and R1) have to remain intact after the function is called. My question is that do I have to use commands POP and PUSH?
start:
.include "m8def.inc"
.DEF var1= R16
.DEF var2= R17
.DEF surface= R18
.DEF temp= R19
rjmp main
surfacerectangle:
pop R20
pop R21
pop temp
add surface, var1
mul surface, var2
push temp
push R21
push R20
ret
main:
ldi temp, low(RAMEND)
out SPL, temp
ldi temp, high(RAMEND)
out SPH, temp
ldi var1, 3
ldi var2, 4
ldi surface, 0
push temp
rcall surfacerectangle
pop temp
end3:
nop
Here is my code that I made, however it dose not seem to work. Does anyone see the problem in my code? This was written in Atmel Studio 7.0 for ATmega8 microcontroller.