帮忙解释“用16位乘法指令完成32位无符号数乘法”的程序

muxuchen   2008-12-14 10:05 楼主
看不懂“用16位乘法指令完成32位无符号数乘法”的程序,请路过的朋友能看得懂的帮忙解释每条指令所表达的含义。

ddata segment
N1 db 'Please input a number:',0dh,0ah,'$'
N2 db 'Please input another number:',0dh,0ah,'$'
N3 db 0dh,0ah,'$'
N4 db 'Your result is:$'
array1 db 8h dup (?)
array2 db 8h dup (?)
out1 dw 16 dup (?)
a1 dw 2 dup (?)
a2 dw 2 dup (?)
p1 dw 2 dup (?)
p2 dw 2 dup (?)
p3 dw 2 dup (?)
p4 dw 2 dup (?)
p5 dw 2 dup (?)
p6 dw 2 dup (?)
p7 dw 2 dup (?)
p8 dw 2 dup (?)
r dw 4 dup (?)

ddata ends

sstack segment stack 'stack'
dw 100h dup (?)
sstack ends

ccode segment
main proc far
assume cs:ccode,ds:ddata,ss:sstack

input1 proc near
mov si,0
mov cl,8
mov ch,0
in1: mov ah,01
int 21h
mov array1[si],al
inc si
loop in1
ret
input1 endp

input2 proc near
mov si,0
mov cl,8
mov ch,0
in2: mov ah,01
int 21h
mov array2[si],al
inc si
loop in2
ret
input2 endp


start: push ds
xor ax,ax
push ax

mov ax,ddata
mov ds,ax

mov dx,offset N1
mov ah,09h
int 21h

call input1

mov dx,offset N2
mov ah,09h
int 21h

mov dx,offset N3
mov ah,09h
int 21h

call input2

;exchange

mov si,0
mov di,3
mov cl,4
mov ch,0
ex1: mov ax,word ptr array1[si]
and ax,0f0fh
mov cl,4
shr al,cl
shl ax,cl
mov byte ptr a1+di,al
inc di
add si,2
loop ex1

mov si,0
mov di,3
mov cl,4
mov ch,0
ex2: mov ax,word ptr array2[si]
and ax,0f0fh
mov cl,4
shr al,cl
shl ax,cl
mov byte ptr a2+di,al
inc di
add si,2
loop ex2


;add
mov ax,a1
mov bx,a2
mul bx
mov p1,ax
mov p2,dx

mov ax,a1+2
mul bx
mov p3,ax
mov p4,dx

mov ax,a1
mov bx,a2+2
mul bx
mov p5,ax
mov p6,dx

mov ax,a1+2
mul bx
mov p7,ax
mov p8,dx

; 1 mov ax,p1
add r,ax
mov ax,p2
add r+2,ax

; 2 mov ax,p3
add r+2,ax
mov ax,p4
adc r+4,ax

; 3 mov ax,p5
add r+2,ax
mov ax,p6
adc r+4,ax

; 4 mov ax,p7
adc r+6,ax
mov ax,p8
adc r+8,ax

;output

mov dx,offset N4
mov ah,09h
int 21

mov si,8
mov di,0
ou : mov al,byte ptr r+[si]
xor ah,ah
mov cl,4
mov ch,0
shl ax,cl
shr al,cl

cmp ah,09h
ja go1
add ah,30h
go1: add ah,37h
cmp al,09h
ja go2
add al,30h
go2: add al,37h
mov out1[di],ax
dec si
add di,2
loop ou

main endp
ccode ends
end main




回复评论 (3)

帮顶
点赞  2008-12-14 10:33
帮顶
点赞  2008-12-14 10:33
mark
点赞  2008-12-14 10:36
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复