⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kcsj2.asm

📁 我用汇编语言编写的程序 能够实现文件的复制删除读出显示等功能
💻 ASM
字号:
include kcsj.mac
.model small
.386
.stack 200h
public prog2
.data
menu db 30 dup(' '),'1.Creat file and input scores',0ah,0dh
     db 30 dup(' '),'2.Compute data',0ah,0dh
     db 30 dup(' '),'3.Display data',0ah,0dh
     db 30 dup(' '),'4.The end',0ah,0dh
     db 30 dup(' '),'Please select one(1~4):','$'
ask1 db 0ah,0dh,'Input file name to create:$'
ask2 db 0ah,0dh,'Input name of student:$'
ask3 db 0ah,0dh,'Input five scores of student:$'
ask4 db 0ah,0dh,'Input dest file name:$'
ask5 db 0ah,0dh,'Input source file name:$'
area db 20,?,20 dup(' ')
er1 db 0ah,0dh,'Can not creat file!$'
er2 db 0ah,0dh,'Can not write file!$'
endcode db 0
handel db 20 dup(?)
code1 dw ?
code2 dw ?     
end1 db 0
buf db 20,?,20 dup(?)
flag db 60 dup(0)
aveg db 20h,2 dup('0')
     db '.'
     db 2 dup('0')
tot db 20h,3 dup('0')
msg db 0ah,0dh,'file has been closed!',0ah,0dh,'$'
cr db 0dh,0ah
space db 5 dup(' ')
tab db 0ah,0dh,'NAME      SC1 SC2 SC3 SC4 SC5',0ah,0dh,'$'

.code
KS2:
prog2 proc far
 init
 call mainshow
 L0:mov ah,1
    int 21h
    cmp al,'1'
    je rot1
    cmp al,'2'
    je rot2
    cmp al,'3'
    je rot3
    jmp ext
rot1:call numin    ;建立成绩文档
     mov end1,0
     call mainshow
     jmp L0
rot2:call compute  ;计算总分和平均分
     call mainshow
     jmp L0
rot3:call show     ;显示成绩报表
     call mainshow
     jmp L0
ext:ret
prog2 endp
    
numin proc near
scroll 0         ;清屏
cursor 0,0       ;置光标位置为(0,0)
strdisp ask1
call in_name     ;输入文件名
add dx,2
mov ah,3ch
mov cx,0         ;建立文件
int 21h
jc error1
mov bx,ax
lea si,flag
again:strdisp ask2
      call strin
      cmp end1,1
      jz exit1
      call wrt
      cmp endcode,1
      je error2
      add ax,5
      mov [si],al
      inc si      
      lea dx,space
      mov ax,5
      call wrt    ;姓名与分数间写入空格
      strdisp ask3
      call strin  
      call wrt
      add ax,2
      mov [si],al
      inc si
      lea dx,cr
      mov ax,2
      call wrt
      jmp again
error1:strdisp er1
       jmp exit
error2:strdisp er2
       jmp exit
exit1:mov end1,0
      mov ah,3eh
      int 21h
exit:ret
 numin endp

mainshow proc near
scroll 0
cursor 10,0
strdisp menu
ret
mainshow endp

wrt proc near
mov ah,0
mov cx,ax
mov ah,40h
int 21h
jnc quit
mov endcode,1
quit:ret
wrt endp

strin proc near  ;键入姓名、分数
push bx
lea di,buf+2
mov al,' '
mov cx,20
rep stosb
mov ah,0ah
lea dx,buf
int 21h
mov al,buf+1
add dx,2
cmp al,0
jnz past
mov end1,1
past:pop bx
     ret
strin endp

in_name proc near  ;键入文件名
lea dx,area
mov ah,0ah
int 21h  
lea bx,area+2
mov ah,0
mov al,area+1
add bx,ax
mov byte ptr [bx],0     
ret
in_name endp

storname proc near  ;保存文件名
cld
lea si,area+2
lea di,handel
mov cx,ax
add cx,1
rep movsb
ret
storname endp

strtonum proc near      ;字符串变分数并求和
mov si,0
lea di,area+2
here:mov bx,0
newchar:mov al,[di]  ;数字并转换为十进制
   cmp al,0dh
   jz g1
   sub al,30h
   jl goon
   cbw
   xchg ax,bx
   mov cx,10d
   mul cx
   xchg ax,bx
   add bx,ax
   inc di
   jmp newchar
 goon:add si,bx  
      inc di
      jmp here
   g1:add si,bx   
      ret     
strtonum endp

compute proc near
scroll 0
cursor 0,0
strdisp ask4  
call in_name
mov ah,0
call storname
mov ah,3ch   ;建立目标文件
mov cx,0
add dx,2
int 21h
jc eror
mov code1,ax  ;保存目标文件代号
strdisp ask5
call in_name
add dx,2
mov ah,3dh    ;打开原文件
mov al,0
int 21h
mov code2,ax  ;保存原文件代号
mov bx,code2
lea bp,flag
lop:
lea di,area+2
mov al,20h
mov cx,20     ;缓冲区用空格填充
rep stosb
mov ah,3fh    ;原文件读到缓冲区
lea dx,area+2
mov ch,0
mov cl,[bp]  
int 21h
inc bp
mov bx,code1  ;写到目标文件--名字
call wrt
lea di,area+2
mov al,20h
mov cx,20     ;缓冲区用空格填充
rep stosb
mov bx,code2
mov ah,3fh
mov ch,0
mov cl,[bp] 
lea dx,area+2       ;继续读原文件
int 21h  
sub ax,2  
mov bx,code1          
call wrt            ;将分写到目标文件
call strtonum       ;将字符变为分数并求和 
mov ax,si
push ax
lea bx,tot+1
mov di,2
call numtoch1        ;将总分数换成字符串
mov ax,4
lea dx,tot 
mov bx,code1            
call wrt            ;总分写到目标文件
pop ax
call aver           ;分数求平均数 
lea bx,aveg+1
mov di,4
call numtoch2        ;将平均分数换成字符串
mov ax,6
mov bx,code1
lea dx,aveg         ;再将平均分写到目标文件bx=code1   
call wrt
lea dx,cr
mov ax,2
mov bx,code1
call wrt
inc bp
cmp byte ptr[bp],0        ;flag!=0,or data out
je over
mov bx,code2
jmp lop              ;再读姓名与分数             
over:           
   mov bx,code2
   call fclose   ;关闭原文件与目标文件   
   mov bx,code1
   call fclose
   strdisp msg
   mov ah,3dh    ;打开目标文件
   lea dx,handel
   mov al,0
   int 21h  
   mov bx,ax
   call fred      ;读目标文件(按记录读)并显示到屏幕上 
   mov bx,code1
   call fclose 
   mov ah,7
   int 21h 
   ret 
eror:strdisp er1
     mov endcode,0
     ret
compute endp

numtoch1 proc near
mov dl,10
ag1:div dl
   add ah,'0'
   mov [bx][di],ah
   mov ah,0
   dec di
   cmp di,0
   jae ag1
   ret
numtoch1 endp     

numtoch2 proc near
mov dl,10
ag2:div dl
   add ah,'0'
   cmp byte ptr[bx][di],'.'
   jne pass
   dec di
pass:mov [bx][di],ah
     mov ah,0
     dec di
     cmp di,0
     jae ag2
     ret
numtoch2 endp     

aver proc near
push cx
push dx
mov dx,0
mov cx,100
mul cx
mov cx,5
div cx
pop dx
pop cx
ret
aver endp

fclose proc near
mov ah,3eh
int 21h
ret
fclose endp

show proc near    ;报表 
   strdisp tab
   mov ah,3dh     ;打开目标文件
   lea dx,handel
   mov al,0
   int 21h  
   mov bx,ax
   call fred      ;读目标文件(按记录读)并显示到屏幕上 
   mov bx,code1
   call fclose 
   mov ah,7
   int 21h 
   ret 
show endp

fred proc near
cont:
mov ah,3fh
lea dx,area+2
mov cx,512
int 21h
cmp ax,0
jz r0
push bx
mov cx,ax
mov ah,40h
mov bx,1
int 21h
pop bx
jmp cont
r0:ret
fred endp
end KS2

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -