Write a 68000 assembly program to divide an 8bit unsigned nu
Solution
Following program divides an 8-bit unsigned number in memory location
0040H by another 8-bit unsigned number in the memory location 0041H and stores the quotient in
memory location 0042H and the remainder in memory location 0043H. Initially accumulator A is
cleared and dividend is loaded into accumulator B. During the division, the quotient replaces the
dividend in accumulator B as the dividend is shifted left to accumulator A. At the end, remainder is
found in accumulator A and quotient in accumulator B.
LDX #8 ; load number of bits of the divisor into index register
CLRA
LDAB 40H ; load dividend to accumulator B
DIVIDE: ASLB ; shift left dividend-quotient.
ROLA
CMPA 41H ; compare accumulator A and divisor
BCS CHKCNT ; branch if accumulator A is smaller than divisor
SUBA 41H ; subtract divisor from accumulator A
INCB ; increment quotient
CHKCNT: DEX ; decrement counter
BNE DIVIDE
STAB 42H ; store quotient
STAA 43H ; store remainder
SWI ; end program
Now I am going to show how to avoid Rotate and Shift operations:
Arithmetic Shift Left (ASLB)
STAB 60H
ADDB 60H; B=B+B = 2B, i,e shift left
SImilarly ROLB can be devised using only ASLB, Heres how.
ROLB:
ASLB; shift left by 1 place
ASLB; shift left 2 places
ASLB; 3 places
ASLB; 4 places
ASLB; 5 places
ASLB; 6 places
ASLB; 7 places
ASLB; shift left 8 places thus the LSB of the initial number is now the carry. Which is the same as ROLB.
Use the above mentioned program for division, but instead of ASLB or ROLB use custom subroutines discussed above to do Shift and Rotate functions.
