MARIE Assembler

Thread Starter

alanspike

Joined Dec 2, 2009
1
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.

SUBROUTINE

LOAD X
JNS PROC
STORE X
JNS PROC
JNS PROC
STORE X
HALT
PROC, DEC 0
ADD FIVE
JUMPI PROC
X, DEC 3
FIVE, DEC 5
MULTIPLICATION

LOAD X
STORE Z
JUMP counter

Loop, LOAD Z
ADD X
STORE Z
JUMP counter

counter, LOAD Y
SUBT M
STORE Y
Skipcond 400
Jump Loop

LOAD X
output
Halt

X, hex 20A
Y, hex F
M, hex 1
Z, hex 0
 
Last edited:

SgtWookie

Joined Jul 17, 2007
22,230
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.

Rich (BB code):
/		Subroutine
/
         LOAD     X           / Retrieve X from variable list
         JNS      PROC        / Store the program counter in PROC
         STORE    X           / Store accumulator in X
         JNS      PROC        / Store the program counter in PROC
         JNS      PROC        / Do it again; beats X-box right?
         STORE    X           / And let's make sure X is really, really stored.
         HALT                 / Screeching halt, right here.  Stop, do not pass GO, no $200.
PROC,    DEC      0           / Let's throw some data in the middle of the program.
         ADD      FIVE        / How on earth are we supposed to get here?
         JUMPI    PROC        / OK, let's jump to an address that has data.  Kaboom!
X,       DEC      3           / More data storage.  At least we didn't crash into it.
FIVE,    DEC      5           / Decimal 5
/			
/				MULTIPLICATION 
/ 
         LOAD     X           / There's that pesky X again.  How'd we get here?
         STORE    Z           / Let's store it in Z, just for the heck of it.
         JUMP     counter     / Off we go!
 
Loop,	 LOAD     Z           / Get Z.  It used to be X.  Or something.
         ADD      X           / OK, now AC = Z + X
         STORE    Z           / Whatever it is, put it back.
         JUMP     counter     / Let's jump one entire instruction ahead.
 
counter, LOAD     Y           / Let's load the mysterious Y varible...
         SUBT     M           / ...and subtract the mysterious "M" from it...
         STORE    Y           / ... then remember what the result was.
         Skipcond 400         / If the AC is 0, skip the next instruction.
         Jump     Loop        / If the AC was not 0, GOTO Loop
 
         LOAD     X           / Out of the loop - let's get X again.
         output               / Display AC contents on console
         Halt                 / End execution
/
/      Variables
/ 
X,       hex      20A
Y,       hex      F 
M,       hex      1 
Z,       hex      0
 
Top