0
votes

I've just started an assembly line programming class and I'm having an issue with a problem, I'm adding 240 to 49 and I know it will overflow, my goal is to make Register 1 equal to 1 when these numbers overflow. I know that the carry flag is set when I add them but I'm unsure of how to use this flag to make r1 equal to 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 --*
1

1 Answers

0
votes

I'm sure there are smarter ways, but you can use brcs, branch if carry set:

add r0, r16
add r0, r17
add r0, r18
brcs carry ; Branch if carry set

carry: ldi r1, 0x1 ; Branch destination