So far i have made a code that add 2 numbers but they are single digits.
.orig x3000
lea r0, string1
puts
getc
out
add r1, r0, 0
ld r0, minus48
add r1, r1, r0
lea r0, string1 ;input one
puts
LOOP
getc
out
add r2, r0, 0
ld r0, minus48
add r2, r2, r0
add r3, r1, r2
out
OUTSIDE
lea r0, string2 ;input two
puts
ld r0, plus48
add r0, r3, r0
out
HALT
plus48 .FILL 48
minus48 .FILL -48
string1 .stringz "\nPlease enter a number: "
string2 .stringz "\nSum is: "
.end
and this works fine however I've been trying to make the number input store more then 1 digit and this is what I've done:
.orig x3000
lea r0, string1 ;input one
puts
LOOP
getc
out
add r1, r0, 0
brz OUTSIDE
ld r0, minus48
add r1, r1, r0
out
brnzp LOOP
lea r0, string1
puts
getc
out
add r2, r0, 0
ld r0, minus48
add r2, r2, r0
add r3, r1, r2
out
OUTSIDE
lea r0, string2 ;input two
puts
ld r0, plus48
add r0, r3, r0
out
HALT
plus48 .FILL 48
minus48 .FILL -48
string1 .stringz "\nPlease enter a number: "
string2 .stringz "\nSum is: "
.end
I have tried to use a loop so I can input more then single digits and the sum can calculate up to 9999. But my loop outputs weird characters but it doesn't run like I want it, LC3 is pretty confusing like it took me forever to get the addition of single digits, so help will be very much appreciated.