食野苹

两个字节数据的加法、乘法

 

data segment

ad1 db 10h
ad2 db 10h
sum db ?
data ends

code segment
assume cs:code,ds:data
main:
mov ax,data
mov ds,ax

mov al,ad1
add al,ad2
mov sum,al
mov bl,al
mov cl,4
shr al,cl ;take upper 4 bits
and al,0fh
add al,30h

mov dl, al
mov ah, 2
int 21h

mov al, bl
and al, 0fh;take lower 4 bits
add al,30h; Asicii code need to add 48d
mov dl, al
mov ah, 2
int 21h


mov ah,4Ch;终止当前程序并返回调用程序
int 21h

code ends
end main

 

若用乘法则:

data segment

ad1 dw 10h
ad2 dw 40h
sum dw ?
data ends

code segment
assume cs:code,ds:data
main:
mov ax,data
mov ds,ax

mov ax,ad1
mul ad2

mov sum,ax
mov bx,ax
mov cl,8
shr ax,cl ;take upper 4 bits
and ax,000fh
add ax,30h

mov dl, al
mov ah, 2
int 21h


mov  ax,sum
mov cl,4
shr ax,cl ;take middle 4 bits
and ax,000fh
add ax,30h

mov dl, al
mov ah, 2
int 21h

mov  ax,sum
and ax,000fh ;take upper 4 bits
add ax,30h

mov dl, al
mov ah, 2
int 21h

mov ah,4Ch;终止当前程序并返回调用程序
int 21h

code ends
end main

 此计算结果为400

 

posted on 2011-07-27 15:58  nyc1893  阅读(974)  评论(0编辑  收藏  举报