this code is supposed to take a binary string four digits long and process it
into a number storing the result in AH.It then takes reuslt in AH and converts it into
octal digits printing them each after an ASCII conversion using the octal function.
The problem comes that before calling the octal routine i make a call to the print
routine.That seems to cause the divide overflow error.When i remove the call to that print
routine everything works fine.what could really be problem because since am dealing
with nibble the largest digit i can convert is 0xF and since am dividing by 0x8, the result
should be able to fit in REG AL and the remainder in AH.

org 0100h
start:
xor ax,ax
xor bx,bx
xor cx,cx
xor dx,dx
mov si,prompt
call print

call input
mov dh,al

call input
mov dl,al

call input
mov ch,al

call input
mov cl,al

mov al,dh
mov bl,08h
call todec

mov al,dl
mov bl,04h
call todec

mov al,ch
mov bl,02h
call todec

mov al,cl
mov bl,01h
call todec

mov si,final
call print

xor cx,cx
call octal
mov si,ending
call print

jmp exit

error:
mov si,err
call print
jmp input

input:
mov ah,00h
int 16h
mov ah,0eh
int 10h
sub al,30h
cmp al,02h
jge error
ret

print:
lodsb
or al,al
jz done
mov ah,0eh
int 10h
jmp print
done:
ret

todec:
mul bl
add bh,al
ret

octal:
cmp bh,08h
jl stub
mov al,bh
mov bl,08h
rpt:
cmp al,08h
jl L
div bl
mov dl,ah
mov ah,0eh
add al,30h
int 10h
sub al,30h
mov al,dl
jmp rpt
L:
call result
ret

stub:
mov al,bh
call result
jmp exit

result:
mov ah,0eh
add al,30h
int 10h
ret

exit:
hlt

prompt db "Enter a 4-bit binary number e.g 1010 ",0Dh,0Ah,0
err db 0Dh,"Please enter a binary number(bit) 1 or 0",0Dh,0Ah,0
final db " ",0
ending db " in octal ",0Dh,0Ah,0

Posted on 2012-04-16 14:42:22 by ashken
"div" is a tricky instruction - all the operands aren't visible. "div bl" divides ax (not just al) by bl. If the result won't fit in al, this exception occurs. I think if you zero ah just before the "div bl", it'll solve your problem. (untested)

Best,
Frank

Posted on 2012-04-16 18:03:24 by fbkotler
right on spot Frank.you nailed the problem.
Posted on 2012-04-17 05:31:45 by ashken