AVR 工作室 - AVR 模拟器 2 携带标志问题



我刚刚开始一个装配线编程类,我遇到了一个问题,我将 240 添加到 49,我知道它会溢出,我的目标是在这些数字溢出时使寄存器 1 等于 1。我知道在添加它们时设置了进位标志,但我不确定如何使用此标志使 r1 等于 1。

 This program should calculate:
; R0 = R16 + R17 + R18
;
;--*1 Do not change anything between here and the line starting with *--
.cseg
    ldi r16, 0x30
    ldi r17, 0x31
    ldi r18, 0x32
;*--1 Do not change anything above this line to the --*
;***
; Your code goes here:
;
    add r0, r16
    add r0, r17
    add r0, r18

;****
;--*2 Do not change anything between here and the line starting with *--
done:   jmp done
;*--2 Do not change anything above this line to the --*

我相信有更聪明的方法,但你可以使用 brcs , 分支 如果携带集:

add r0, r16
add r0, r17
add r0, r18
brcs carry ; Branch if carry set
carry: ldi r1, 0x1 ; Branch destination

最新更新