damingo
damingo

Reputation: 1

MARIE, multiply 2 numbers and divide final result by 2

/len = length, hei = height
/get and store input
input
store LEN
input 
store HEI
/start of loop
/load in the value of len
LOOP, load LEN
/add len to num
add NUM
/store the value in num
Store NUM
/load in hei deduct 1 and store back to hei
load HEI
subt ONE
store HEI
/skip jump if the value in the ac is 0 
skipcond 400
jump LOOP
/output
LOOP1, load NUM
subt TWO
store NUM
load NUM
output
skipcond 400
jump LOOP1
load NUM
/end the program
halt

LEN, DEC 0
HEI, DEC 0
ONE, DEC 1
NUM, DEC 0
TWO, DEC 2

I am attempting to make a program that calculates the area of a triangle. I've managed to get the multiplication part out of the way, however the division part is where I'm struggling. Any help would be appreciated.

I have attempted to make a second loop in which the final product would continually be subtracted by 2, however the output would just subtract 2 multiple times without getting the correct answer. For example: `

/len = 3, heigh = 4
/output would be:
/10
/8
/6
/4
/2
/0

Like I said before, any help would be appreciated.

Upvotes: 0

Views: 136

Answers (1)

Tim Roberts
Tim Roberts

Reputation: 54767

Change your loop to track and return the quotient

LOOP1, load NUM
subt TWO
store NUM
load QUO     <--
add ONE      <--
store QUO    <--
load NUM
output
skipcond 400
jump LOOP1
load QUO     <--
/end the program
halt

and add:

QUO, DEC 0

Upvotes: 1

Related Questions