'Writing an LC3 Subtraction subroutine to subtract R3 from R2
I'm just starting to learn LC3. If we want to write a Subtraction subroutine which subtracts the value stored in some register, lets say we want to subtract the value stored in  R3 from R2 meaning that R2 - R3 and store the value back into R3. How is this done using LC3 subroutines?
SUBT    NOT R3, R3 ; Find the complement of R3
        ADD R4, R3, #1 ; Getting 2's complement, R4 = -R3
        ADD R3, R2, R4 ; R3 -> R2 + R4 = R2 - R3
        RET
So far I have this.
expected output:
009-001=008 
004-004=000 
008-002=006 
003-002=001 
001-000=001 
005-001=004 
009-003=006 
008-004=004 
000-000=000 
002-001=001 
Output received:
009-001=001
004-004=004
008-002=002
003-002=002
001-000=000
005-001=001
009-003=003
008-004=004
000-000=000
002-001=001
Call made:
BRz     C_MINUS
ADD     R0, R4, #-2
C_MINUS JSR     SUBT            ; '-'
BRnzp   C_end
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source | 
|---|
