题目要求:
给出三个有符号数,编写一个比较相等关系的程序:
(1) 如果这三个数都不相等,则显示0;
(2) 如果这三个数中有两个数相等,则显示1;
(3) 如果这三个数都相等,则显示2;
答案:
DATAS SEGMENT
;此处输入数据段代码
num1 = 1
num2 = 0
num3 = -2
result db 'aThe result is:','0','$'
DATAS ENDS
STACKS SEGMENT
;此处输入堆栈段代码
STACKS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
mov al,num1
mov ah,num2
mov bl,num3
cmp al,ah
je r1
cmp ah,bl
je r2
cmp al,bl
je r3
mov result[0],'0'
jmp done
r1:cmp ah,bl
je r11
mov result[0],'1'
jmp done
r2:mov result[0],'1'
jmp done
r3:mov result[0],'1'
jmp done
r11:mov result[0],'2'
jmp done
done: mov dx,offset result
MOV AH,09h
INT 21H
MOV AH,4CH
INT 21H
CODES ENDS
END START
思路解析:先画出程序流程图,根据程序流程图控制跳转即可