【发布时间】:2017-11-15 09:02:48
【问题描述】:
对于像这样的代码:
;; Data definitions go here
.section .data
n1: .byte 12
n2: .byte 34
n3: .byte 21
n4: .byte 10
result: .space 1
;; Code definition goes here
.section .text
.global main
main:
push R17
ldi R26, lo8(n1) ; Loading the address of n1 in X
ldi R27, hi8(n1)
ld R24, X+ ; Load n1 in R24 and increase address
ld R17, X+ ; Load n2 in R17 and increase address
add R24, R17 ; R4 = n1 + n2
ld R17, X+ ; Load n3 in R17 and increase address
add R24, R17 ; R4 = n1 + n2 + n3
ld R17, X+ ; Load n4 in R17 and increase address
add R24, R17 ; Final result in R24 = n1 + n2 + n3 + n4
;; At this point R27:R26 contains the address of result
st X, R24 ; Store the result
;; The result of this function is returned in R25:R24
clr R25 ; So that R25:R24 has the result in 16 bits.
pop R17
ret
.end
1) 即使我们使用 R18 代替 R17 并移除弹出和推送 R17,结果是否相同?
2) 另外,只是做 clr R25 将 R25 连接到 R24? (因此制作 R25:R24?)
3) 此外,当执行如下指令操作时:
ADD R17, R18, ADD 是指令,R17 & R18 是寄存器吗?它们存储在 AVR 架构中的什么位置?
4) 最后,为什么将结果保存在 R25:R24 中,而不只是返回 R24 的值(包含 n1 + n2 + n3 + n4)?
我对汇编语言真的很陌生...请告诉我...任何帮助都会很棒!谢谢
【问题讨论】:
标签: assembly computer-science avr