设x是一个8位非符号数,且5<=x<=250,求y=x^2+8*x-30,不会超过字的范围,所以将结果保存为字即可
data segment
x db 10
y dw ?
data ends
code segment
assume cs:code,ds:data,ss:stk
main:
mov ax,data
mov ds,ax
mov al,x
mul al;求x*x,此时结果保存在ax中
mov cx,ax
mov bl,x
mov al,8
mul bl;求8*x,此时结果保存在ax中
add ax,cx
sub ax,30
mov y,ax
mov ah,4ch
int 21h
code ends
stk segment stack
dw 100h dup(0)
stk ends
end main
已知A,B,C,D均为16位符号数,求(A*D-(B-D)*C+50)/(A+B+20)商存入S1,余数存入s2
data segment
A dw 12ABh
B dw 0AB72h
C dw 53E9h
D dw 9E2Dh
S1 dw ?
S2 dw ?
data ends
code segment
assume cs:code,ds:data,ss:stk
main:
mov ax,data
mov ds,ax
mov ax,A
imul D
mov bx,dx
mov cx,ax
mov ax,B
sub ax,D
imul C
sub cx,ax;A*D-(B-D)*C的低十六位
sbb bx,dx;带进位减
add cx,50
adc bx,0;防止有进位
mov dx,bx
mov ax,cx
mov bx,A
add bx,B
add bx,20
idiv bx
mov s1,ax
mov s2,dx
mov ah,4ch
int 21h
code ends
stk segment stack
dw 100h dup(0)
stk ends
end main
A=5a85c2h,b=32h,求s1=A*B
data segment
A db 0C2h,85h,5Ah
B db 32h
S1 db 4 dup(0)
data ends
code segment
assume cs:code,ds:data,ss:stk
main:
mov ax,data
mov ds,ax
mov al,B
mul A;球的32h*c2h
mov s1,al
mov s1[1],ah
mov al,B
mul A[1];求85h*32h
add s1[1],al
adc s[2],ah;带进位加
mov al,b
mul A[2]
add s[2],al
adc s1[3],ah
mov ah,4ch
int 21h
code ends
stk segment stack
dw 100h dup(0)
stk ends
end main