Divide using Marie Simulator

5.8k Views Asked by At

I am having trouble figuring out the dividing for the Marie Sim. I do not want the -1, but it keeps showing the negative. I only want it up to 2. Any suggestions?

This is my code:

ORG 100
Input 
Store   x
Input   
Store   y
loop, load x
Subt    y
Store   x
Load    x
Output
Skipcond 0
Jump    loop
Load    x
Halt
x,  Dec     0 
y,  Dec     0 

Output: 11 8 5 2 -1

4

There are 4 best solutions below

0
On

Try this:

Input 
Store   x
Input   
Store   y
loop, load x
Subt    y
Store   x
Load    x
Output
Skipcond 400
Jump    loop
Load    x
Halt
x,  Dec     0 
y,  Dec     0
0
On

I noticed some of the above responses created infinite loops if the program encountered a remainder when dividing. I resolved this and my program outputs 2 decimal values the result and the remainder respectively.

This is a very old post but hopefully, this will be of use to any newcomers to Assembly.

STORE x
INPUT
STORE y

loop, Load x
If, Subt y
    Skipcond 000
    Jump Else
Then, Jump Endif
Else, Store x
    Load Counter
    Add One
    Store Counter
    Jump loop
Endif, Load Counter
Output
Load x
Output
HALT

x, Dec 0
y, Dec 0
Counter, Dec 0
One, Dec 1
0
On
ORG 100


input
store var1
input
store var2
loop, load var1

Subt var2

Store var1
Store remain


load qout
Add one
Store qout

Load remain
Subt var2
Skipcond 000
Jump loop


load qout
output

load remain
output

halt


var1, dec 0

var2, dec 0
one, dec 1
remain, dec 0
qout, dec 0
0
On

//The code below fixes your problem but creates an infinite loop whenever the division problem has a remainder.

ORG 100
INPUT
STORE x
INPUT
STORE y
loop, LOAD x
SUBT y
STORE x
SKIPCOND 000
OUTPUT
SKIPCOND 400
JUMP loop
HALT
x, Dec 0
y, Dec 0