📄 cifa.asm
字号:
STSG SEGMENT STACK 'S'
STSG ENDS
data segment
handl1 word ?
handl2 word ?
pathna1 byte "C:\masm615\chengxu.txt",00h
pathna2 byte "C:\masm615\jieguo.txt",00h
openmsg byte "***open error***",'$'
readmsg byte "***read error***",'$'
wrtmsg byte "***write error***",'$'
str8 byte "The result:",'$'
str4 byte "Special indel ",'$' ;存储除字母数字外的字符
str5 byte "Number ",'$' ;存储数字
str6 byte "Indel ",'$' ;存储自定义标示符
str7 byte "Bliuzi ",'$' ;存储保留字
string byte 80 dup('?') ;存储输入的符号串
str2 byte 80 dup('?') ;存储没有空格的符号串
crlf byte 0dh,0ah,'$'
guyou1 byte "int",'$'
guyou2 byte "char",'$'
guyou3 byte "float",'$'
guyou4 byte "long",'$'
guyou5 byte "short",'$'
guyou6 byte "include",'$'
guyou7 byte "define",'$'
guyou8 byte "undef",'$'
guyou9 byte "ifdef",'$'
guyou11 byte "ifndef",'$'
guyou12 byte "endif",'$'
guyou13 byte "line",'$'
guyou14 byte "while",'$'
guyou15 byte "do",'$'
guyou16 byte "for",'$'
guyou17 byte "if",'$'
guyou18 byte "else",'$'
guyou19 byte "printf",'$'
guyou21 byte "scanf",'$'
guyou22 byte "void",'$'
guyou23 byte "main",'$'
guyou24 byte "return",'$'
guyou25 byte "double",'$'
guyou26 byte "struct",'$'
guyou27 byte "union",'$'
guyou28 byte "enum",'$'
guyou29 byte "unsigned",'$'
guyou31 byte "putchar",'$'
guyou32 byte "getchar",'$'
guyou33 byte "break",'$'
guyou34 byte "continue",'$'
guyou35 byte "strcat",'$'
guyou36 byte "puts",'$'
guyou37 byte "gets",'$'
guyou38 byte "strcpy",'$'
guyou39 byte "strcmp",'$'
guyou41 byte "strlen",'$'
guyou42 byte "typedef",'$'
guyou43 byte "FILE",'$'
guyou44 byte "fopen",'$'
guyou45 byte "fclose",'$'
guyou46 byte "fgetc",'$'
guyou47 byte "fputc",'$'
guyou48 byte "fscanf",'$'
guyou49 byte "fprintf",'$'
guyou51 byte "fread",'$'
guyou52 byte "fwrite",'$'
guyou53 byte "fgets",'$'
guyou54 byte "fputs",'$'
guyou55 byte "rewind",'$'
guyou56 byte "fseek",'$'
guyou57 byte "ftell",'$'
guyou58 byte "feof",'$'
guyou59 byte "case",'$'
guyou61 byte "const",'$'
guyou62 byte "default",'$'
guyou63 byte "auto",'$'
guyou64 byte "extern",'$'
guyou65 byte "goto",'$'
guyou66 byte "register",'$'
guyou67 byte "signed",'$'
guyou68 byte "sizeof",'$'
guyou69 byte "malloc",'$'
guyou71 byte "static",'$'
guyou72 byte "switch",'$'
guyou73 byte "volatile",'$'
guyou74 byte "NULL",'$'
guyou75 byte "EOF",'$'
str3 byte 80 dup(?) ;存储要输出的单位
c1 word ?
c2 word ?
c3 word ?
zjie byte '@'
flag byte 0
data ends
code segment
main proc far
assume cs:code,ds:data
mov ax,data
mov ds,ax
clc
mov c1,0
mov c2,0
mov c3,0
mov ah,3dh
mov al,010b
lea dx,pathna1
int 21h
jnc succe
lea dx,openmsg
mov ah,09h
int 21h
jmp error
succe:
mov handl1,ax
mov ah,42h;文件指针移到末尾,追加结束符'@'
mov al,2
mov bx,handl1
mov cx,0
mov dx,0
int 21h
jnc zhujia
lea dx,openmsg
mov ah,09h
int 21h
jmp error
zhujia:
mov ah,40h
mov bx,handl1
mov cx,1
lea dx,zjie
int 21h
jnc zhuch
lea dx,wrtmsg
mov ah,09h
int 21h
jmp error
zhuch:
mov ah,42h;文件指针回到文件首
mov al,0
mov bx,handl1
mov cx,0
mov dx,0
int 21h
mov dx,offset str8
mov ah,09h
int 21h
mov dx,offset crlf
mov ah,09h
int 21h
lea bp,str2
oo:
mov ah,3fh
mov bx,handl1
mov cx,80
lea dx,string
int 21h
jnc succe2
lea dx,readmsg
mov ah,09h
int 21h
jmp error
succe2:
mov bx,dx ;保存dx
;mov ah,3ch
; mov cx,0000h
; lea dx,pathna2
; int 21h
; jnc succe3
; lea dx,wrtmsg
; mov ah,09h
; int 21h
; jmp error
;succe3:
; mov handl2,ax
;写磁盘文件
and si,0000h
and di,0000h
mov cx,80;
L1:
cmp cx,0;
je weiwan;
mov al,[bx+si]
cmp al,'@'
je quit
cmp al,' '
je next
cmp al,9
je next
cmp al,10
je next
cmp al,13 ;每行结束时,先有13
je next
mov [bp+di],al
inc di
next:
dec cx;
inc si
jmp L1
jieshu:
push cx
mov bx,handl1 ;文件指针移到当前位置减去cx+1
mov cx,0
pop dx
sub dx,2
not dx
cmp dx,0
jge point
not cx
point:
mov al,1
mov ah,42h
int 21h
mov flag,1
jnc gg
lea dx,readmsg
mov ah,09h
int 21h
jmp error
weiwan:;=========
mov flag,1;
jmp gg
quit: ;去掉所有的空格,存入str2中
mov flag,0
gg:
mov cx,0
mov cx,di ;保存不是空格的字符的个数
mov si,cx
and si,00ffh
mov dx,'$'
mov [bx+si],dx ;为输入的字符串加入结束标志$
and di,0000h
and si,0000h
lea bx,str3
L2:
mov al,[bp+di]
cmp al,'_'
je zzimu
cmp al,61h
jl shuzi ;可能是数字
cmp al,7ah
jg qquit ;一定是 特殊字母
zzimu:
mov si,c1 ;开始处理字母开头的
mov [bx+si],al
inc c1
tet3:
inc di
dec cx
jne jixu3
mov ax,'$'
mov si,c1
mov [bx+si],ax
lea dx,str6
mov ah,09h
int 21h
mov dx,bx
mov ah,09h
int 21h
jmp eext
jixu3:
mov al,[bp+di]
cmp al,'_'
je bushu3
cmp al,30h
jl shuchu3
cmp al,7ah
jg shuchu3
cmp al,39h
jng bushu3
cmp al,61h
jnl bushu3
cmp al,5ah
jng ttt
jmp shuchu3
ttt:
cmp al,41h
jnl bushu3
shuchu3:
mov ax,'$'
mov si,c1
mov [bx+si],ax
lea dx,str6
mov ah,09h
int 21h
mov dx,bx
mov ah,09h
int 21h
mov dx,offset crlf
mov ah,09h
int 21h
and c1,0000h
jmp L2
bushu3:
mov si,c1
mov [bx+si],al
inc c1
mov ax,'$'
mov si,c1
mov [bx+si],ax
push di
lea si,guyou1;判断关键字
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou2
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou3
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou4
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou5
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou6
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou7
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou8
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou9
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou11
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou12
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou13
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou14
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou15
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou16
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou17
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou18
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou19
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou21
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou22
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou23
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou24
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou25
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou26
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou27
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou28
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou29
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou31;判断关键字
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou32
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou33
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou34
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou35
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou36
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou37
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou38
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou39
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou41;判断关键字
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou42
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou43
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou44
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou45
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou46
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou47
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou48
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou49
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou51;判断关键字
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou52
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou53
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou54
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou55
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou56
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou57
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou58
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou59
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou61;判断关键字
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou62
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou63
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou64
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou65
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou66
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou67
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou68
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou69
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou71
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou72
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou73
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou74
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
push di
lea si,guyou75
mov di,bx
call cmpstr
pop di
cmp dx,0
jne kk
jmp jj
kk:
lea dx,str7
mov ah,09h
int 21h
mov dx,bx
mov ah,09h
int 21h
and c1,0000h
mov dx,offset crlf
mov ah,09h
int 21h
inc di
dec cx
cmp cx,0
jng eext
jmp L2
jj:
jmp tet3
shuzi: ;处理数字开头的
cmp al,30h
jl qquit
cmp al,5ah
jg qquit
cmp al,41h
jnl zzimu
cmp al,3ah
jnl qquit
mov si,c2
mov [bx+si],al
inc c2
tet2:
inc di
dec cx
jne jixu2
mov ax,'$'
mov si,c2
mov [bx+si],ax
lea dx,str5
mov ah,09h
int 21h
mov dx,bx
mov ah,09h
int 21h
jmp eext
jixu2:
mov al,[bp+di]
cmp al,30h
jl shuchu2
cmp al,39h
jg shuchu2
mov si,c2
mov [bx+si],al
inc c2
jmp tet2
shuchu2:
mov ax,'$'
mov si,c2
mov [bx+si],ax
lea dx,str5
mov ah,09h
int 21h
mov dx,bx
mov ah,09h
int 21h
mov dx,offset crlf
mov ah,09h
int 21h
and c2,0000h
jmp L2
qquit: ;处理特殊字符
mov si,c3
mov [bx+si],al
inc c3
;====================================
tet:
inc di
dec cx
jne jixu
mov ax,'$'
mov si,c3
mov [bx+si],ax
lea dx,str4
mov ah,09h
int 21h
mov dx,bx
mov ah,09h
int 21h
jmp eext
jixu:
cmp al,';'
je shuchu
cmp al,'('
je shuchu
cmp al,')'
je shuchu
cmp al,']'
je shuchu
cmp al,'['
je shuchu
mov al,[bp+di]
cmp al,';'
je shuchu
cmp al,'('
je shuchu
cmp al,')'
je shuchu
cmp al,']'
je shuchu
cmp al,'['
je shuchu
cmp al,30h
jl bushu
cmp al,7ah
jg bushu
cmp al,61h
jnl shuchu
cmp al,39h
jng shuchu
bushu:
cmp c3,2
je shuchu
mov si,c3
mov [bx+si],al
inc c3
jmp tet
shuchu:;================================
mov ax,'$'
mov si,c3
mov [bx+si],ax
lea dx,str4
mov ah,09h
int 21h
mov dx,bx
mov ah,09h
int 21h
mov dx,offset crlf
mov ah,09h
int 21h
and c3,0000h
jmp L2
eext:
mov al,flag;
cmp al,1;=========
je oo
error:;=====
mov ah,3eh
mov bx,handl1
int 21h
mov ah,3eh
mov bx,handl2
int 21h
mov ax,4c00h
int 21h
main endp
cmpstr proc near ;比较两个符号串是否相等
push si
push di
push ax
mov dx,0
loop1: mov al,[si]
cmp al,[di]
jne no_eq
cmp al,'$'
je quitt
inc si
inc di
inc dx
jmp loop1
no_eq: mov dx,0
quitt:
pop ax
pop di
pop si
ret
cmpstr endp
code ends
end main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -