MARIE Assembler

Discussion in 'Homework Help' started by alanspike, Dec 2, 2009.

  1. alanspike

    Thread Starter New Member

    Dec 2, 2009
    1
    0
    Hey guys, I'm working on an assignment and have been given this really difficult question to solve. Basically, I'm using the MARIE language, and have been asked to create a subroutine which simulates a binary shift left operation of data stored in the accumulator.

    To an extent I understand that a binary shift operation can be exampled as:
    001010 (shift left) 010100
    001010 (shift right) 000101

    I just have no idea how to implement this as a MARIE program. I've been theorising that considering MARIE coding runs on a hexadecimal/decimal system then I could possibly multiply the AC number by 10/16 to move the digits along... but I'm not sure.

    If any of you guys could explain this to me ill be very appreciative.

    This is what I was given as information on subroutines. As well as a hexadecimal multiplication program I developed.

     
    Last edited: Dec 2, 2009
  2. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    I've re-formatted your code (with some effort) as you used the Quote feature instead of the Code feature.

    In the future when posting program code, please use the "Go Advanced" button, and then click the "#" symbol on the toolbar above the text box.

    I've added some comments to your code, which you should think about.

    I spent some years programming large mainframe computers; some of it in Assembler. Comments in Assembler are a must, and must be updated when program changes are made. Comments make the intent of the program much easier to understand, and easier to determine where problems might lie.

    In Assembler, neatness counts.

    Code ( (Unknown Language)):
    1. /       Subroutine
    2. /
    3.          LOAD     X           / Retrieve X from variable list
    4.          JNS      PROC        / Store the program counter in PROC
    5.          STORE    X           / Store accumulator in X
    6.          JNS      PROC        / Store the program counter in PROC
    7.          JNS      PROC        / Do it again; beats X-box right?
    8.          STORE    X           / And let's make sure X is really, really stored.
    9.          HALT                 / Screeching halt, right here.  Stop, do not pass GO, no $200.
    10. PROC,    DEC      0           / Let's throw some data in the middle of the program.
    11.          ADD      FIVE        / How on earth are we supposed to get here?
    12.          JUMPI    PROC        / OK, let's jump to an address that has data.  Kaboom!
    13. X,       DEC      3           / More data storage.  At least we didn't crash into it.
    14. FIVE,    DEC      5           / Decimal 5
    15. /          
    16. /               MULTIPLICATION
    17. /
    18.          LOAD     X           / There's that pesky X again.  How'd we get here?
    19.          STORE    Z           / Let's store it in Z, just for the heck of it.
    20.          JUMP     counter     / Off we go!
    21.  
    22. Loop,    LOAD     Z           / Get Z.  It used to be X.  Or something.
    23.          ADD      X           / OK, now AC = Z + X
    24.          STORE    Z           / Whatever it is, put it back.
    25.          JUMP     counter     / Let's jump one entire instruction ahead.
    26.  
    27. counter, LOAD     Y           / Let's load the mysterious Y varible...
    28.          SUBT     M           / ...and subtract the mysterious "M" from it...
    29.          STORE    Y           / ... then remember what the result was.
    30.          Skipcond 400         / If the AC is 0, skip the next instruction.
    31.          Jump     Loop        / If the AC was not 0, GOTO Loop
    32.  
    33.          LOAD     X           / Out of the loop - let's get X again.
    34.          output               / Display AC contents on console
    35.          Halt                 / End execution
    36. /
    37. /      Variables
    38. /
    39. X,       hex      20A
    40. Y,       hex      F
    41. M,       hex      1
    42. Z,       hex      0
    43.  
     
Loading...