Marie code

Discussion in 'Homework Help' started by JoGo, Nov 23, 2009.

  1. JoGo

    Thread Starter New Member

    Nov 17, 2009
    2
    0
    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
     
  2. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    OK, for starters - here's your pseudocode, re-formatted:
    Code ( (Unknown Language)):
    1.  
    2. / Pseudocode:
    3. M = 1;
    4. N = 1;
    5. while M < 16 {
    6.    M = M + N:
    7.    N = N + 1;
    8. } end while
    Your program, reformatted:
    Code ( (Unknown Language)):
    1.  
    2.          Org 100       / This starts the program at address 100
    3.          Load N        / Load N into the AC
    4.          Add One       / Increment
    5.          Store Next    / Store this address as out Next pointer
    6.          Load M        / Load M into the AC
    7.          Add N         / Add N to M
    8.          Store Ctr     / Store this value in Ctr to control looping
    9. Loop,    Load Sum      / Load the Sum into AC
    10.          AddI Next     /Add the value pointed to by location Next
    11.          Store Sum     / Store this Sum
    12.          Load Next     / load Next
    13.          Add One       / Increment by one to point to next address address
    14.          Store Next    / Store in our pointer Next
    15.          Load Ctr      / Load the loop control variable
    16.          Add Next      / Add the value pointed to by location Next
    17.          Store Ctr     / Store thie new value in loop control variable
    18.          Skipcond 000  / if control variable < 16 then skip next instruction
    19.          Jump Loop     / Otherwise, go to Loop
    20.          Halt          / Terminate Program
    21. M,       Dec 1  / M = 1
    22. N,       Dec 1  / N = 1
    23. One,     Dec 1  / Used to Increment or Decrement
    24. Next,    Hex 0  / A pointer to the next number to add
    25. Ctr,     Hex 0  / The loop control variable
    26. 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.
     
  3. Wendy

    Moderator

    Mar 24, 2008
    20,764
    2,534
    What is the VBulliten command to post code like that?
     
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Code ( (Unknown Language)):
    1.  [URL]http://forum.allaboutcircuits.com/misc.php?do=bbcode#code[/URL]
     
Loading...