汇编语言中有关寄存器的问题

时间:2017-11-15 09:02:48

标签: assembly computer-science avr

代码如下:

;; 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,是一条指令,R17& R18寄存器?它们在哪里存储在AVR架构中?

4)最后,为什么将结果保存在R25:R24中,而不仅仅是返回R24的值(包含n1 + n2 + n3 + n4)?

我对汇编语言真的很陌生......请赐教我...任何帮助都会很棒!感谢

1 个答案:

答案 0 :(得分:0)

  1. 是的,但据推测,R18也必须根据调用惯例保存
  2. 那只是零延伸。
  3. 是。它们是cpu的内部,但也映射到SRAM存储器地址范围0-31。
  4. 大概是因为预期函数会返回16位值。请注意,执行16位添加也会更好。
相关问题