DATAS SEGMENT
mess db 'please input 3 nums (0-9)',0dh,0ah,'$'
mess1 db 0dh,0ah, 'result:',0dh,0ah,'$'
buf db 5,0,0
buf1 db 3 dup(?)
res db 0
x db 0
DATAS ENDS
STACKS SEGMENT
;此处输入堆栈段代码
STACKS ENDS
input macro
mov dx,offset mess
mov ah,09h
int 21h
lea di,buf1
.while 1
.break .if x==3
mov ah,01h
int 21h
sub al,30h
mov [di],al
inc di
inc x
.endw
mov dx,offset mess1
mov ah,09h
int 21h
ENDM
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
MOV AX,DATAS
MOV DS,AX
input
lea si,buf1
call compare
cmp res,3
jnz l
dec res
l: mov dl,res
add dl,30h
mov ah,02h
int 21h
MOV AH,4CH
INT 21H
compare proc near
mov dh,[si]
mov dl,[si+1]
mov bl,[si+2]
cmp dh,dl
jnz l1
inc res
l1 : cmp dh,bl
jnz l2
inc res
l2:cmp dl,bl
jnz l3
inc res
l3:
ret
compare endp
CODES ENDS
END START
;注意全局变量的问题 问题出在了变量到3以后再去调用时没有赋值了 还是3所以不执行 切记 DATAS SEGMENT mess db 0dh,0ah, 'please input 3 nums (0-9)',0dh,0ah,'$' mess1 db 0dh,0ah, 'result:',0dh,0ah,'$' buf db 5,0,0 buf1 db 3 dup(?) res db 0 x db 0 DATAS ENDS STACKS SEGMENT ;此处输入堆栈段代码 STACKS ENDS input macro mov res,0 mov dx,offset mess mov ah,09h int 21h lea di,buf1 .while 1 .break .if x==3 mov ah,01h int 21h sub al,30h mov [di],al inc di inc x .endw mov dx,offset mess1 mov ah,09h int 21h ENDM CODES SEGMENT ASSUME CS:CODES,DS:DATAS,SS:STACKS START: MOV AX,DATAS MOV DS,AX .while 1 input mov x,0 lea si,buf1 call compare cmp res,3 jnz l dec res l: mov dl,res add dl,30h mov ah,02h int 21h .endw MOV AH,4CH INT 21H compare proc near mov dh,[si] mov dl,[si+1] mov bl,[si+2] cmp dh,dl jnz l1 inc res l1 : cmp dh,bl jnz l2 inc res l2:cmp dl,bl jnz l3 inc res l3: ret compare endp CODES ENDS END START