I'm working on a program which gets a number (for example, 42 ) then prints it to the screen using interrupt 21 with ah 2. My programs manages to split the number, but when I get a number like 60 my programs calls interrupt 0h because I'm dividing by 0
How can I overcome this?
This is the code:
PROC printNumber push bp push dx push bx push ax mov bp, sp mov ax, [bp + number] mov dx, 0 mov bx, 10 splitNumber: cmp ax, 0 jz exit div bx add dx, '0' mov ah, 2 int 21h jmp splitNumber exit: pop ax pop bx pop dx pop bp retn 2 ENDP printNumber Thanks! :D
div. Are you sure this works for42? Wouldn't the 2nd division run with dx:ax='2':4=0x32:04, leading to divide overflow? Or no,int 21h/ah=2returns the character printed in AL. spike.scu.edu.au/~barry/interrupts.html#ah02 So that's broken as well.div bl(8-bit operand size) writes AH and AL instead of DX and AX. Anyway, it prints the same number forever because (like I commented already),int 21hwith AL=2 copies DL to AL, overwriting the rest of the number. Use the debugger built-in to emu8086