Reputation: 1151
I'm learning assembly using the MARIE program but I can't figure out hot to do this question from the book:
Divide one number by another and store the quotient and the remainder in two different memory locations.
This is what I have so far, what am I doing wrong? FYI there is no divide or multiplication built into the program so I have to do it using a loop but I guess I'm missing something.
The program can be had here http://computerscience.jbpub.com/ecoa/2e/downloads/MarieSim-v1.3.01.zip
ORG 100
Input / Enter a number
Store X / Saves the number
Input / Enter a number
Store Y / Saves the number
Load Zero / Move 0 into AC
Store Z / Set Z to 0
If, Load Z / Load Z
Skipcond 400 / If AC=0 (Z=0), skip the next instruction
Jump Endif / Jump to Endif if X is not greater than 1
Then, Load X
Subt Y / X - Y
Store X / X = X - Y
Endif, Load Z / Load Z into AC
Add One / Add 1 to Z
Store Z / Z = Z + 1
Output / Print to screen
Halt / Terminate program
X, Dec 0 / X has starting value
Y, Dec 0 / Y has starting value
Z, Dec 0
One, Dec 1 / Use as a constant
Zero, Dec 0 / Use as a constant
END
Upvotes: 1
Views: 10002
Reputation: 1
////Divide Positive numbers/ A have to be biger then B///by: E
ORG 100
Input /Input A value
Store A
Input /Input B value
Store B
If, Load A
Skipcond 800
Jump EndIf
Then, Load A
Subt B
Store A
Load C
Add One
Store C
Jump If
EndIf, Load C
Halt, Output
C, DEC 0
A, DEC 0
B, DEC 0
One, DEC 1
Upvotes: -1
Reputation: 2585
If you want to divide using repeated subtraction, your program had better have some form of a loop.
The way your program is structured, it will run straight onto the Halt
instruction after subtracting Y from X only once, and Z will end up being one.
It would be best to manually go through the code and execute each step on a piece of paper, then you'll see where you go wrong. And BTW, the comment on the Jump Endif
is wrong, it's not X but Z you are checking upon.
You may want to modify your code, and then your question if it still presents problems.
Upvotes: 2