Función dividir de la librería matemática Math.
DIVI.ASM
; Copyright (C) 2013 José Ángel Moneo Fernández ; This program is free software: you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation, either version 3 of the License, or ; (at your option) any later version. ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; You should have received a copy of the GNU General Public License ; along with this program. If not, see <http://www.gnu.org/licenses/>.
;; solo divide por numeros menores de ffffh
include main.mac
_modelo exe
_code
rutina _divi dividendo,divisor,resultado
push bx
push dx
push cx
push si
push di
mov si,[bp].dividendo
mov di,[bp].resultado
mov bx,[bp].divisor
mov word ptr [di+2],0
mov word ptr [di],0
xor dx,dx
cmp word ptr [bx+2],0
jz normal
mov ax,[si+2]
cmp ax,[bx+2]
jb fin
mov cx,[bx+2]
div cx
mov [di],ax
comprueba:
mul word ptr [bx]
mov aux,ax
mov aux+2,dx
mov ax,[di]
mul word ptr [bx+2]
add aux+2,ax
mov ax,aux+2
cmp ax,[si+2]
ja no_cabe
jne fin
mov ax,aux
cmp ax,[si]
jbe fin
no_cabe:
dec word ptr [di]
mov ax,[di]
jmp comprueba
normal:
mov cx,[bx]
mov ax,[si+2]
div cx
mov [di+2],ax
mov ax,[si]
div cx
mov [di],ax
fin:
pop di
pop si
pop cx
pop dx
pop bx
pop bp
ret
_divi endp
_data
aux dw 0,0
_end
No hay comentarios:
Publicar un comentario
Si tienes algún comentario, duda o sugerencia, o si quieres aportar algún código creado a partir de las librerías expuestas aquí, por favor, indícamelo.