sub ax,ax
push ax
mov ax,datarea
mov ds,ax
mov es,ax
begin:
mov cx, string2-string1
mov bx, mess1-string2
cmp bx,cx
jnz dispno
lea dx,addr
lea si,string1
lea di,string2
repe cmpsb
jne dispno
mov ah,9
lea dx,mess1
int 21h
ret
dispno:
mov ah, 9
lea dx, mess2
int 21h
ret
main endp
prognam ends
end start
3. 试编写程序,要求从键盘输入3个16进制数,并根据对3个数的比较显示如下信息:
(1)如果3个数都不相等则显示0;
(2)如果3个数中有2个数相等则显示2;
(3)如果3个数都相等则显示3。
答案:
data segment
array dw 3 dup(?)
data ends
code segment
main proc far
assume cs:code,ds:data
start:
push ds
sub ax,ax
push ax
mov ax,data
mov ds,ax
mov cx,3
lea si,array
begin:
push cx
mov cl,4
mov di,4
mov dl, ' '
mov ah,02
int 21h
mov dx,0
input:
mov ah,01
int 21h
and al,0fh
shl dx,cl
or dl,al
dec di
jne input
mov [si],dx
add si,2
pop cx
loop begin
comp:
lea si,array
mov dl,0
mov ax,[si]
mov bx,[si+2]
cmp ax,bx
jne next1
add dl,2
next1:
cmp [si+4],ax
jne next2
add dx,2
next2:
cmp [si+4],bx
jne num
add dl,2
num:
cmp dx,3
jl disp
mov dl,3
disp:
mov ah,2
add dl,30h
int 21h
ret
main endp
code ends
end start
4. 已知整数变量A和B,试编写完成下述操作的程序:
(1)若两个数中有一个是奇数,则将该奇数存入A中,偶数存入B中;
(2)若两个数均为奇数,则两数分别加1,并存回原变量;
(3)若两个数均为偶数,则两变量不变。
答案:
dseg segment
a dw ?
b dw ?
dseg ends
cseg segment
main proc far
assume cs:cseg,ds:dseg
start: push ds
sub ax,ax
push ax
mov ax,dseg
mov ds,ax
begin: mov ax,a
mov bx,b
xor ax,bx