I need help on writing a program in vvm that can divide two numbers

1k Views Asked by At

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

2

There are 2 best solutions below

0
Peter Cordes On

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.

1
rkhb On

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