10 septembrie 2010

Inmultirea a doua numere fara semn pe 32 biti, cu rezultat pe 64 biti

; inmultirea a 2 nr fara semn, pe 32 biti, cu rez. pe 64 biti
; algoritm
; (DX, AX)*
; (CX, BX) =
; (BX * AX) +
; (BX * DX) +
; (CX * AX) +
; (CX * DX) =
; (DX, CX, BX, AX)

dseg segment para public 'data'
deinmultit dd 123h
inmultitor dd 456h
produs dq ?
dseg ends

cseg segment para public 'code'
assume cs:scseg, ds:dseg
start:
mov ax, dseg
mov ds, ax
;creez registri in fct de deinmultit si inmultitor
mov dx, word ptr deinmultit[2]
mov ax, word ptr deinmultit
mov bx, word ptr inmultitor
mov cx, word ptr inmultitor[2]
call procedura
;refacere rezultat
mov word ptr produs, ax
mov word ptr produs[2], bx
mov word ptr produs[4], cx
mov word ptr produs[6], dx
mov ax, 4c00h
int 21h
public procedura
procedura proc
push dx
push ax
push dx
; (DX, AX) = AX * BX
mul bx
mov word ptr rezultat[0],ax
mov word ptr rezultat[2],dx
; (DX, AX) = BX * DX
pop ax ; ax = dx
mul bx
add word ptr rezultat[2], ax
adc word ptr rezultat[4], dx ; cu eventual transport
; (DX, AX) = CX * AX
pop ax ; ax = ax dinainte
mul cx
add word ptr rezultat[2], ax
adc word ptr rezultat[4], dx ; cu eventual transport
; (DX, AX) = CX * DX
pop ax ; ax = dx
mul cx
add word ptr rezultat[4], ax
adc word ptr rezultat[6], dx
; refacere registri
mov ax, word ptr rezultat[0]
mov bx, word ptr rezultat[2]
mov cx, word ptr rezultat[4]
mov dx, word ptr rezultat[6]
procedura ends
cseg ends

sseg segment para stack 'stack'
dw 128 dup(?)
sseg ends

end start

Niciun comentariu: