assembly x86(nasm)修改后的日常

data    segment
ENG         db    'SUNdayS Coming I Wanna Drive My Car,SUN,SUN$'        ;9,3
sun1        db    'SUN'
swcount        db    0ah,0dh,'single word number:',?,?,'$'
suncount    db    0ah,0dh,'SUN:',?,'$'
data    ends
code    segment
assume    cs:code,ds:data,es:data
start:
            mov    ax,data
            mov    ds,ax    
            mov    es,ax        
            lea dx,ENG        
            mov    ah,9                        
            int    21h
swcount1:                                        
            mov al,ENG[si]
            cmp al,'$'                    ;是$就停止遍历
            jz     output1
            cmp al,'A'
            jb  text1
            cmp al,'Z'
            ja     text1
text2:        cmp al,'S'                    ;是字母S就进入SUN的串比较
            jz  strcmp
            jmp next
text1:        cmp al,'a'
            jb     addswc
            cmp al,'z'
            jna next
addswc:        inc swcount[21]                ;不是字母字符就认为是单词之间的分隔,单词数加一
            jmp next
to:
            pop si
next:        inc si
            jmp swcount1
strcmp:
            push si                        ;保存si
            lea di,sun1
            lea si,ENG[si]
            mov cx,3
            repz cmpsb                    ;串比较,当前字符相同则继续循环
            jnz addcount
            inc suncount[6]
addcount:    jmp to
output1:    inc swcount[21]
            or swcount[21],00110000b    ;将数值转换为对应ascall码
            or suncount[6],00110000b
            lea dx,swcount    
            mov    ah,9                        
            int    21h                
            lea dx,suncount                        
            int    21h            
exit:        mov    ah,4ch                        
            int    21h
code    ends
end    start

问题不大。

posted @ 2019-06-09 14:32  Lancelot&  阅读(193)  评论(0编辑  收藏  举报