其他语言

本类阅读TOP10

·基于Solaris 开发环境的整体构思
·使用AutoMake轻松生成Makefile
·BCB数据库图像保存技术
·GNU中的Makefile
·射频芯片nRF401天线设计的分析
·iframe 的自适应高度
·BCB之Socket通信
·软件企业如何实施CMM
·入门系列--OpenGL最简单的入门
·WIN95中日志钩子(JournalRecord Hook)的使用

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
汇编综合应用(1) Test Palindrome

作者:未知 来源:月光软件站 加入时间:2005-6-5 月光软件站

在粗略的看过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




相关文章

相关软件