DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Assembly (http://www.daniweb.com/forums/forum125.html)
-   -   Division in Assembly? (http://www.daniweb.com/forums/thread190426.html)

Rameses May 4th, 2009 8:22 pm
Division in Assembly?
 
How can I perform Division in Marie Assembly Language? The functions available in Marie programming are for Addition and Subtraction. Any help will be appreciated.

sysop_fb May 5th, 2009 2:35 pm
Re: Division in Assembly?
 
Quote:

Originally Posted by Rameses (Post 861952)
How can I perform Division in Marie Assembly Language? The functions available in Marie programming are for Addition and Subtraction. Any help will be appreciated.

You can do division using subtraction.
60 / 3 if I subtract 3 from 60 it will take 20 times before 60 < 3

Rameses May 6th, 2009 12:34 am
Re: Division in Assembly?
 
Quote:

Originally Posted by sysop_fb (Post 862616)
You can do division using subtraction.
60 / 3 if I subtract 3 from 60 it will take 20 times before 60 < 3

I was able to do multiplication:Input /Input A value
Store A
Input /Input B value
Store B
Loop, Load A
Skipcond 800 If AC > 0, continue loop
Jump Endloop
Subt One
Store A
Load C
Subt B
Store C
Jump Loop
Endloop, Load C
Output
Halt
C, DEC 0
A, DEC 0
B, DEC 0
One, DEC 1

Division doesn't seems to be working for me. Is there something I could change in multiplication code to make division work? Multiplication is repeated adding, similar to Division, repeated subtraction.

sysop_fb May 6th, 2009 2:29 am
Re: Division in Assembly?
 
Psuedocode

a = 60
b = 3
divide a b


divide a b:
c=0
while a isn't less then b
a = a - b
c = c + 1

Rameses May 7th, 2009 5:45 pm
Re: Division in Assembly?
 
Quote:

Originally Posted by sysop_fb (Post 863072)
Psuedocode

a = 60
b = 3
divide a b


divide a b:
c=0
while a isn't less then b
a = a - b
c = c + 1

ORG 100
Input
Store X
Input
Store Y
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
Halt / Terminate program
X, Dec 0 / X has starting value, not given in problem
Y, Dec 0 / Y has starting value, not given in problem
Z, Dec 0
One, Dec 1 / Use as a constant
Zero, Dec 0 / Use as a constant
END

What am I missing?

Rameses May 7th, 2009 8:13 pm
Re: Division in Assembly?
 
Quote:

Originally Posted by Rameses (Post 864264)
ORG 100
Input
Store X
Input
Store Y
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
Halt / Terminate program
X, Dec 0 / X has starting value, not given in problem
Y, Dec 0 / Y has starting value, not given in problem
Z, Dec 0
One, Dec 1 / Use as a constant
Zero, Dec 0 / Use as a constant
END

What am I missing?

Nevermind, I got it. Thanks a ton! :)


All times are GMT -4. The time now is 9:55 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC