83.6k views
1 vote
Write the following code segment in MARIE assembly language. (Hint: Turn the for loop into a while loop). Sum = 0; for X=1 to 10 do Sum = Sum + X Your MARIE program should output the results of SUM to the output window of MARIE.

User Stafox
by
6.5k points

1 Answer

5 votes

By Using the Load and Store commands, we first set the variable Sum in this code to 0. Afterwards, we store the variable X with its initial value (which is 1) loaded into the AC.

A "code segment" in computing is an object file or the corresponding area of the virtual address space of the program that contains executable instructions. Other names for it include text fragments and plain text.

ORG 100

Initialize Sum to 0 after loading 0; save Sum.

Load 1 and Load X with 1 before storing X.

Loop, Load X, then insert X into AC

Add the sum Sum + X + Add

Store Sum / Keep the outcome in Sum.

Add X, then increment it by 1

Retailer X / Save the updated X value.

Load X Deduct 10; Identify X's equality or difference from 10

400 Skipcond / If X = 10, skip the following instruction.

Loop Jump / Return to the loop's beginning if X is less than 10.

Summation; Displaying the final sum value

User Gedas Kutka
by
7.7k points