Vistas de página en total

domingo, 26 de mayo de 2013

MULTIPLICAR


Función mult, que es parte de la librería Math y por lo tanto está declarada en la cabecera MATH.MAC
Esta función multiplica dos números, op1 y op2, y devuelve el resultado en res.
  Recuedo que definimos _data, aunque no lo usemos, para que la directiva propia _data no nos de error en el assume ds:_data. En el caso de usar modelo 'com' no hay problema porque la directiva _data no creará nada.

   La data la colocamos al final, para que sirva tanto para com como para exe. La directiva _data se encargará de crear el segmento de datos o dejar las definiciones de variables dentro del segmento de código.

MULT.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/>.

; codigo
include main.mac
_modelo exe _code
rutina _mult op1,op2,res

        push bx
        push dx
        push cx
        push si
        push di
        mov si,[bp].op1
        mov bx,[bp].op2
        mov di,[bp].res
        mov ax,[bx+2]
        push ax
        mov ax,[si]
        push ax
        mov ax,[si]
        mov cx,[bx]
        mul cx
        mov [di],ax
        push dx
        mov ax,[si+2]
        mul cx
        pop dx
        add ax,dx
        mov [di+2],ax
        pop ax
        pop cx
        mul cx
        add [di+2],ax
        pop di
        pop si
        pop cx
        pop dx
        pop bx
        pop bp
        ret
_mult endp
_data
_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.