I am trying to write a program that inputs a positive number less than 10 and outputs the sum of the first numbers. For example 5 would be 5+4+3+2+1. The commands are Stop, Load, Store, Add, Sum, Multiply, Divide, Input, Output, Branch, Branch if 0, and branch if not 0. Can anyone help me out here. I am kind of stuck. well what I have written is:
IN n
LD n
ADD sum
STO sum
LD n
SUB one
ADD sum
STO sum
BRGT haw
LD n
BR done
haw: OUT sum
done: STOP
DC n 4
DC sum 0
DC one 1
Well the way I see it working is you load some number n and add a sum of 0 and then store this sum as n+sum. Then you load n again and subtract 1 and store that as the new sum. But I need it to repeat this until n reaches 0. So how do I do this?
Ok so what i need to do is use the branch if 0 and branch if not 0. I think I have it? so:
IN n
LD n
ADD sum
STO sum
BR CAW
CAW: LD n
SUB ONE
STO n
BRGT HAW
BZ TAW
HAW: ADD SUM
STO SUM
BR CAW
TAW: OUT SUM
DC SUM 0
DC ONE 1
DC=Designated Constant, but what I need to repeat is the subtracting by one and adding the sum until n reaches 0. Branch if not zero is BRGT and branch if zero is BZ and branch is BR, LD is load. I know what I need to repeat but I don t know how you do this in assembly language.