Infinite loop when doing DIV instruction
ivan-avalos opened this issue · comments
Iván Ávalos commented
I'm not sure whether this is an issue with my code or an issue with emu2. Either way, I'll report it.
Here's the procedure where this gets triggered:
capturar_dec proc
mov dx, 0
mov cx, 10000
bucle:
cmp cx, 1
je terminar
;; Capturar caracter
mov ah, 01h
int 21h
;; Validar caracter
cmp al, '0'
jl terminar_error
cmp al, '9'
jg terminar_error
;; Recalcular base en CX
push ax
mov ax, cx
mov bl, 10
div bl
mov ah, 0
mov cx, ax
pop ax
;; Convertir caracter
mov ah, 0
and al, 0fh ; aplicar masking a AL para convertir a número
;; Multiplicar por base
push dx
mov bx, cx
mul bx ; multiplicar AX * CX, resultado en DX:AX
pop dx
add dx, ax ; acumulamos parte baja (AX) en DX como resultado
jmp bucle
terminar:
ret
terminar_error:
;; Imprimir mensaje de error
mov ah, 09h
lea dx, msgerr
int 21h
;; Terminar con código de error
mov ah, 4ch
mov al, 1
int 21h
capturar_dec endp
Iván Ávalos commented
It also happens with DOSBOX, so it's not emu2's fault.
Iván Ávalos commented
Seems like this is the issue, for those curious about it: https://stackguides.com/questions/69573665/division-word-with-byte
dmsc commented
Yes, you are dividing "AX" by "BL", and the result is overflowing, so the exception handler is called. As you did not install an exception handler, you get stuck in an infinite loop.
Have Fun!