Question

Write a MARIE program that sums the numbers from 1 to N (N(N + 1) /...

Write a MARIE program that sums the numbers from 1 to N (N(N + 1) / 2) using a loop and user input.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

    INPUT           /Read a number n. where n stores inot AC
   JNS FindSum          /Call FindSum by passing n
   OUTPUT               /Print the return value(sum)
   HALT           /Exit the program
FindSum, HEX 000             /Store the return address
   STORE n              /Save the passed value into n
LOOP,   SKIPCOND 800             /if n is 0, go to Return
   JUMP Return      
   /Do sum=sum+n
   LOAD sum             /AC=sum
   ADD n                /AC=sum+n
   STORE sum            /sum=AC
   /DO n=n-1
   LOAD n               /AC=n
   SUBT ONE             /AC=n-1
   STORE n              /n=AC
   JUMP LOOP            /Go to LOOP
Return, LOAD sum             /Send sum as return value
   JUMPI FindSum       /Return from FindSum
/Declare necessary variables
n,    DEC 0
sum, DEC 0
ONE, DEC 1

Below is the process to run it

Open MARIE Simulator

Open File editor

Write the program

Save the program as sumoneton.mas

Assemble the program

Now load the program(sumoneton.max)

Note: Set INPUT ,AC and OUTPUT display format as Dec (Decimal number)

Run the program

Input: enter n=5

Ouptut: sum=1+2+3+4+5= 15

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Write a MARIE program that sums the numbers from 1 to N (N(N + 1) /...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT