Marie code

Thread Starter

JoGo

Joined Nov 17, 2009
2
I have to write this in MARIE Assemble Code:

M = 1;
N = 1;
while M < 16
{ M = M + N:
N = N + 1;
} end while

This is what I have: Can you please make adjustments as needed. Thank You in Advance!!

Org 100 / This starts the program at address 100
Load N / Load N into the AC
Add One / Increment
Store Next / Store this address as out Next pointer
Load M / Load M into the AC
Add N / Add N to M
Store Ctr / Store this value in Ctr to control looping
Loop, Load Sum / Load the Sum into AC
AddI Next /Add the value pointed to by location Next
Store Sum / Store this Sum
Load Next / load Next
Add One / Increment by one to point to next address address
Store Next / Store in our pointer Next
Load Ctr / Load the loop control variable
Add Next / Add the value pointed to by location Next
Store Ctr / Store thie new value in loop control variable
Skipcond 000 / if control variable < 16 then skip next instruction
Jump Loop / Otherwise, go to Loop
Halt / Terminate Program
M, Dec 1 / M = 1
N, Dec 1 / N = 1
One, Dec 1 / Used to Increment or Decrement
Next, Hex 0 / A pointer to the next number to add
Ctr, Hex 0 / The loop control variable
Sum, Dec 0 / The sum
 

SgtWookie

Joined Jul 17, 2007
22,230
OK, for starters - here's your pseudocode, re-formatted:
Rich (BB code):
/ Pseudocode:
M = 1; 
N = 1; 
while M < 16 { 
   M = M + N: 
   N = N + 1; 
} end while
Your program, reformatted:
Rich (BB code):
         Org 100       / This starts the program at address 100
         Load N        / Load N into the AC
         Add One       / Increment
         Store Next    / Store this address as out Next pointer
         Load M        / Load M into the AC
         Add N         / Add N to M
         Store Ctr     / Store this value in Ctr to control looping
Loop,    Load Sum      / Load the Sum into AC
         AddI Next     /Add the value pointed to by location Next
         Store Sum     / Store this Sum
         Load Next     / load Next
         Add One       / Increment by one to point to next address address
         Store Next    / Store in our pointer Next
         Load Ctr      / Load the loop control variable
         Add Next      / Add the value pointed to by location Next
         Store Ctr     / Store thie new value in loop control variable
         Skipcond 000  / if control variable < 16 then skip next instruction
         Jump Loop     / Otherwise, go to Loop
         Halt          / Terminate Program
M,       Dec 1  / M = 1
N,       Dec 1  / N = 1
One,     Dec 1  / Used to Increment or Decrement
Next,    Hex 0  / A pointer to the next number to add
Ctr,     Hex 0  / The loop control variable
Sum,     Dec 0  / The sum
Can you honestly say that the program you wrote bears much resemblance to the pseudocode?

You're using Next and Ctr, but those really are a bit advanced for just two variables. If you were adding vectors/arrays, then it would make sense.

I can't do this for you, but I can nudge you in the right direction.
 
Top