[英]I'm writing AVR assembly in atmel, but “call” instruction doesn't work
I'm using Atmel Studio 6.2 to write some assembly code for Atmega328p. 我正在使用Atmel Studio 6.2为Atmega328p编写一些汇编代码。
However, the call
instruction for subroutine doesn't work when I use simulator and step-by-step execute the program. 但是,当我使用模拟器并逐步执行程序时,子例程的
call
指令不起作用。 It completely ignores the call
instruction and goes on to the next line. 它完全忽略了
call
指令,并转到下一行。
In order to test the call
instruction I wrote a simple program, which looks as follows: 为了测试
call
指令,我编写了一个简单的程序,该程序如下所示:
.include "m328pdef.inc"
ldi R16, 11
call hello_world
mov R1, R0
nop
hello_world:
mov R0, R16
ret
But even this doesn't work! 但是,即使这样也不行! It just goes on to execute
mov R1, R0
. 它只是继续执行
mov R1, R0
。 What might be the reason? 可能是什么原因? It's so annoying when
call
doesn't work! call
不起作用时真令人讨厌!
.include "m328pdef.inc"
ldi r16,11
ldi r17,0
ldi r18,1
rcall hello_world
mov r16,r17
nop
hello world:
mov r16,r18
ret
I am using r16,r17, and r18 because its general use registers, only use it for debugging. 我使用r16,r17和r18是因为它的通用寄存器仅用于调试。
here is the step by step explanation: 这是分步说明:
1. load immediate value "11" to r16 1.将立即值“ 11”加载到r16
2. load immediate value "0" to r17 2.将立即值“ 0”加载到r17
3. load immediate value "1" to r18 3.将立即值“ 1”加载到r18
4. call hello_world label. 4.调用hello_world标签。 push address into stack
将地址压入堆栈
5. move value from r18 (1) to r16, so r16 value is 1 5.将值从r18(1)移至r16,因此r16值为1
6. ret, pop the address, and goes back 6.退出,弹出地址,然后返回
7. move value from r17 (0) to r16, r16 value is 0 7.将值从r17(0)移至r16,r16的值为0
If you run the program at once instead of step-by-step, you wont know the difference. 如果您一次而不是一步一步地运行程序,您将不知道它们之间的区别。
Hope this help 希望这个帮助
You have to define stack http://www.avr-tutorials.com/assembly/writing-assembly-subroutines-avr-microcontroller 您必须定义堆栈http://www.avr-tutorials.com/assembly/writing-assembly-subroutines-avr-microcontroller
;Initialize the microcontroller stack pointer
LDI R16, low(RAMEND)
OUT SPL, R16
LDI R16, high(RAMEND)
OUT SPH, R16
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.