i really need some help with this, im trying to write a program in vvm assembly language which will divide two number for example divide number A by number B
Asked
Active
Viewed 986 times
-3
-
3Can you show us what you have tried so far? – Michael Petch Dec 11 '15 at 03:54
2 Answers
1
Since vvm doesn't have a divide instruction in hardware, you're going to have to do it "manually". It doesn't even have right-shift or any boolean ops that would let you test the last bit.
However, adding a number to itself is a left-shift, so you can probably still make an algorithm that runs in log(n) time, rather than just repeated subtraction.

Peter Cordes
- 328,167
- 45
- 605
- 847
0
The easiest way for that really small machine is to repeatedly subtract the divisor from the dividend until the result becomes negative:
This example performs 12/4:
lda 90
brz 20
sub 91
sto 90
brp 10
jmp 20
*10
lda 92
add 93
sto 92
jmp 00
*20
lda 92
out
hlt
*90
dat 012
dat 004
dat 000
dat 001

rkhb
- 14,159
- 7
- 32
- 60
-
It's actually un-helpful to students to hand them a solution. I know this doesn't solve the general problem, but I think it's better to stick to English descriptions of things. A broad question gets a broad answer from me, rather than any code for a specific solution. [Open letter to students with homework problems](http://meta.programmers.stackexchange.com/questions/6166/open-letter-to-students-with-homework-problems). I answered, but also voted to close as too-broad, and downvoted for not showing an attempt. :/ – Peter Cordes Dec 11 '15 at 18:23