How do I subtract two "numbers" in LC3?

4.3k Views Asked by At
LD  R0, NUM1
NOT R0, R0
ADD R0, R0, #1
LD  R1, NUM2
ADD R1, R0, R1
OUT
BRn BIG

Hi, I am trying to compare NUM1 with NUM2. Assume NUM1 is less than NUM2, then my R1 should be a negative number. My current algorithm is not working, and I want to branch out if I get a negative number. Any help would be appreciated!

1

There are 1 best solutions below

0
On

Pretty sure you've got that backwards. First you load NUM1 and 2s-comp it, so you have -NUM1. Then you add to it NUM2, leaving you with NUM2-NUM1. If NUM1 < NUM2, R1 will be greater than zero.