在粗略的看过string instruction之后, 综合了先前所有看过的,写了个测试palindrome的程序,再次让大脑到达兴奋点,现在终于可以让大脑轻松一下了。呵呵~~~ 源码如下:
.model small
.stack 300h
.data
str1 byte 255 dup(?)
str2 byte 255 dup(?)
s1 byte "Please input a string:"
s2 byte "Palindrome matched "
s3 byte "Palindrome unmatched"
count word ?
len word ?
flag byte ?
.code
.startup
mov ax,@data
mov ds,ax
mov es,ax
mov flag,0
Main Proc
lea bx,s1
mov cx,lengthof s1
add cx,bx
mov ah,2
Call printOut
mov si,offset str1
mov ah,8
Call getStr1
Call CopyToStr2
Call Reverse
Call Check
mov ah,2
Call PrintNL
cmp flag,1
je Matched
lea bx,s3
mov cx,lengthof s3
add cx,bx
mov ah,2
Call printOut
.exit
Matched:lea bx,s2
mov cx,lengthof s2
add cx,bx
mov ah,2
Call printOut
.exit
Main EndP
printOut Proc
loop4:cmp bx,cx
je finish4
mov dl,byte ptr[bx]
int 21h
inc bx
jmp loop4
finish4:ret
printOut EndP
getStr1 Proc
loop1:mov ah,8
int 21h
cmp al,13
je finish1
mov [si],al
mov ah,2
mov dl,[si]
int 21h
inc si
inc len
jmp loop1
finish1:mov [si],0
ret
getStr1 EndP
printNL Proc
mov dl,10
int 21h
mov dl,13
int 21h
ret
printNL EndP
CopyToStr2 Proc
cld
mov cx,0
mov cx,len
mov si,offset str1
mov di,offset str2
rep movsb
ret
CopyToStr2 EndP
Reverse Proc
mov si,offset str1
mov di,offset str2
mov ax,0
mov ax,len
mov dx,0
loop5:push ds:[si]
inc count
inc si
cmp count,ax
jl loop5
loop6:pop es:[di]
dec count
inc di
cmp count,0
jg loop6
ret
Reverse EndP
Check Proc
mov cx,len
mov si,offset str1
mov di,offset str2
rep cmpsb
je setFlag1
jne setFlag2
setFlag1:mov flag,1
ret
setFlag2:mov flag,0
ret
Check EndP
end
本文地址:http://com.8s8s.com/it/it21756.htm