写的比较累赘。。。
data segment
msg1 DB "Please input first string:",'$'
string1 DB 100,0,100 dup('?')
msg2 DB "Please input second string:",'$'
string2 DB 100,0,100 dup('?')
msg3 DB "Please input third string:",'$'
string3 DB 100,0,100 dup('?')
msg4 db 0ah,0dh
result DW '?','$'
Data ends
Stack segment para stack
db20h dup(0)
Stack ends
code segment
Assume Cs:code,Ss:stack,ds:Data
Start:mov ax,data
mov ds,ax
mov es,ax
;处理第1个字符串
lea dx,msg1
mov ah,09h
int 21h
lea dx,string1
mov ah,0ah
int 21h
xor bx,bx
lea dx,msg4
mov ah,09h
int 21h
;处理第二个字符串
lea dx,msg2
mov ah,09h
int 21h
lea dx,string2
mov ah,0ah
int 21h
lea dx,msg4
mov ah,09h
int 21h
;处理第三个字符串
lea dx,msg2
mov ah,09h
int 21h
lea dx,string3
mov ah,0ah
int 21h
lea dx,msg4
mov ah,09h
int 21h
;第一个与第二个开始比较
mov bl,string1+1
cmp bl,string2+1
ja lop1
jb lop2
jmp lop3
lop1:mov cl,string2+1
jmp lop3
lop2:mov cl,string1+1
jmp lop3
lop3:mov cl,bl
cld
lea di,string2+2
lea si,string1+2
repz cmpsb
ja mat1
jb mat2
mat1: ;1比2大的情况 ,2与3再比较
;嵌套
mov bl,string2+1
cmp bl,string3+1
ja lop4
jb lop5
jmp lop6
lop4:mov cl,string3+1
jmp lop6
lop5:mov cl,string2+1
jmp lop6
lop6:mov cl,bl
cld
lea di,string3+2
lea si,string2+2
repz cmpsb
ja mat4
jb mat5
;嵌套第2层
mat4:
;------1比2大,2比3大,ASCII码排序是1>2>3
mov result,'3'
lea dx,result
mov ah,09h
int 21h
mov result,'2'
lea dx,result
mov ah,09h
int 21h
mov result,'1'
lea dx,result
mov ah,09h
int 21h
jmp exit
mat5:
;1比2大,2比3小,1和3还需比较
;第一个与第三个开始比较
mov bl,string1+1
cmp bl,string3+1
ja lop7
jb lop8
jmp lop9
lop7:mov cl,string3+1
jmp lop9
lop8:mov cl,string1+1
jmp lop9
lop9:mov cl,bl
cld
lea di,string3+2
lea si,string1+2
repz cmpsb
;ja mat7
jb mat8
;------1比2大,2比3小,1比3大
;ASCII码排序是1>3>2
;mat7:
mov result,'3'
lea dx,result
mov ah,09h
int 21h
mov result,'1'
lea dx,result
mov ah,09h
int 21h
mov result,'2'
lea dx,result
mov ah,09h
int 21h
jmp exit
mat8:
;------1比2大,2比3小,1比3小
;ASCII码排序是3>1>2
mov result,'2'
lea dx,result
mov ah,09h
int 21h
mov result,'1'
lea dx,result
mov ah,09h
int 21h
mov result,'3'
lea dx,result
mov ah,09h
int 21h
jmp exit
;嵌套第2层
;嵌套
mat2:
;1比2小的情况。1再与3比较
mov bl,string1+1
cmp bl,string3+1
ja lop10
jb lop11
jmp lop12
lop10:mov cl,string3+1
jmp lop12
lop11:mov cl,string1+1
jmp lop12
lop12:mov cl,bl
cld
lea di,string3+2
lea si,string1+2
repz cmpsb
ja mat10
jb mat11
mat10:
;------1比3大的情况
;ASCII码排序是2>1>3
mov result,'2'
lea dx,result
mov ah,09h
int 21h
mov result,'3'
lea dx,result
mov ah,09h
int 21h
mov result,'1'
lea dx,result
mov ah,09h
int 21h
jmp exit
mat11:
;1比2小,1比3小,2和3再比较
mov bl,string2+1
cmp bl,string3+1
ja lop13
jb lop14
jmp lop15
lop13:mov cl,string3+1
jmp lop15
lop14:mov cl,string2+1
jmp lop15
lop15:mov cl,bl
cld
lea di,string3+2
lea si,string2+2
repz cmpsb
ja mat13
jb mat14
mat13:
;-----1比2小,1比3小,2比3大
;ASCII码排序是2>3>1
mov result,'1'
lea dx,result
mov ah,09h
int 21h
mov result,'3'
lea dx,result
mov ah,09h
int 21h
mov result,'2'
lea dx,result
mov ah,09h
int 21h
jmp exit
mat14:
;-----1比2小,1比3小,2比3小
;ASCII码排序是3>2>1
mov result,'1'
lea dx,result
mov ah,09h
int 21h
mov result,'2'
lea dx,result
mov ah,09h
int 21h
mov result,'3'
lea dx,result
mov ah,09h
int 21h
jmp exit
mat3:mov result,'0'
exit:mov ah,4ch
int 21h
code ends
end start
1201



被折叠的 条评论
为什么被折叠?



