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

📄 cjgl.asm

📁 用汇编语言编写的学生成绩管理系统,实现学生记录的插入 删出 显示等
💻 ASM
📖 第 1 页 / 共 2 页
字号:
        pop bx 
        add bx,ax 
        mov dx,stustored 
  sub dx,1 ;dx:i,即循环次数 


l1:     mov swapped,0 
  sub bx,32;第一次指向倒数第二项,以后每跑一趟前移一项 
        mov endaddr,bx 
        push bx 
  lea si,studentx;si:j,j=0 
  
   

l2:     mov cx,6 ;置循环计数值 
        mov di,si 
        add di,32 ;di->后项,目标 si->前项,源 
        mov bx,di 
        mov ax,si 
        repe cmpsb ;源-目标,即前项如果大于后项,交换; 
        jbe s3
        exchange ax,bx 

s3:     mov si,ax 
  add si,32;j++ 
        cmp si,endaddr 
        jbe l2 ;是否已到循环表尾,如果没到继续循环 
        pop bx 
        cmp swapped,0 ;如果有交换,继续下一趟 
        je qsort 
        dec dx 
        jnz l1  
qsort:  pop cx 
  pop dx 
  pop bx 
  pop ax 
  pop di 
  pop si 
  ret 
name_sort endp 
input       proc       near 
;void input()   通过键盘输入一条item并保存在内存studentx表中   
   push ax 
   push dx 
    
              call near ptr       clear   ;清理屏幕 
              call near ptr       cursor   ;设置光标 
              cmp       stustored,29 
              ja        i1 
              mov       ah,09 
              lea       dx,msg02;display prompt 
              int       21h 
    iloop:    cmp       stustored,29 
              ja        i1 
              call near ptr       inputname  ;输入学生姓名 
              cmp       namelen,0 
              je       i2 
              call near ptr       inputnum  ;输入学生学号 
              call near ptr       inputsxsz  ;输入成绩 
              call near ptr       inputkxwh 
              call near ptr       inputsx 
              call near ptr       inputzh
              call near ptr       inputcjpm 
              call near ptr       inputjl
              call near ptr       stor;往内存表中写入一项 
              jmp       iloop 
              mov   saveflag,0 
              jmp       i2  
    i1:       mov       ah,9 
              lea       dx,msg20;'There are more than 30 students.' 
              int       21h 
    i2:       showmsg back;'Press any key to back.' 
    i3:        
              mov       saveflag,0     
              pop dx 
              pop ax             
              ret 
input        endp 
inputname   proc       near 
;void inputname()   输入学生姓名 
   push ax 
            push dx 
            push bx 
            push cx 
             
            showmsg   03 
            mov        ah,0ah 
            lea        dx,namepar 
            int        21h 
            crlfm 
            mov        bh,0 
            mov        bl,namelen 
            mov        cx,7 
            sub        cx,bx 
    n10:    mov        namefld[bx],20h;空余部分用空格填充 
            inc        bx 
            loop       n10 
             
            pop cx 
            pop bx 
            pop dx 
            pop ax 
            ret   
inputname   endp 
inputnum   proc        near  
;void inputnum()   输入学生学号 
            push ax 
            push dx 
            push bx 
             push cx 

            showmsg   04 
            mov        ah,0ah 
            lea        dx,numpar 
            int        21h 
            crlfm 
            mov        bh,0 
            mov        bl,numlen 
            mov        cx,9 
            sub        cx,bx 
    n20:    mov        numfld[bx],20h;空余部分用空格填充 
            inc        bx 
            loop       n20 
             
            pop cx 
            pop bx 
            pop dx 
            pop ax 
            ret   
inputnum     endp    
;----------------------------------------------------------------------     
inputsxsz      proc     near   
   push ax 
            push dx 
            push bx 
            push cx 
             
            showmsg 05 
            mov        ah,0ah 
            lea        dx,sxszpar 
            int        21h 
            crlfm 
            mov        bh,0 
            mov        bl,sxszlen 
            mov        cx,4 
            sub        cx,bx 
    n21:    mov        sxszfld[bx],20h;空余部分用空格填充 
            inc        bx 
            loop       n21 
              
            pop cx 
            pop bx 
            pop dx 
            pop ax 
            ret   
inputsxsz    endp 
inputkxwh      proc     near 
;void inputsco()  输入学生成绩 
   push ax 
            push dx 
            push bx 
            push cx 
             
            showmsg 051 
            mov        ah,0ah 
            lea        dx,kxwhpar 
            int        21h 
            crlfm 
            mov        bh,0 
            mov        bl,kxwhlen 
            mov        cx,4 
            sub        cx,bx 
    n22:    mov        kxwhfld[bx],20h;空余部分用空格填充 
            inc        bx 
            loop       n22
              
            pop cx 
            pop bx 
            pop dx 
            pop ax 
            ret   
inputkxwh    endp 
inputsx      proc     near 
;void inputsco()  输入学生成绩 
   push ax 
            push dx 
            push bx 
            push cx 
             
            showmsg 052 
            mov        ah,0ah 
            lea        dx,sxpar 
            int        21h 
            crlfm 
            mov        bh,0 
            mov        bl,sxlen 
            mov        cx,4 
            sub        cx,bx 
    n23:    mov        sxfld[bx],20h;空余部分用空格填充 
            inc        bx 
            loop       n23
              
            pop cx 
            pop bx 
            pop dx 
            pop ax 
            ret   
inputsx   endp 
inputzh      proc     near 
;void inputsco()  输入学生成绩 
   push ax 
            push dx 
            push bx 
            push cx 
             
            showmsg 053 
            mov        ah,0ah 
            lea        dx,zhpar 
            int        21h 
            crlfm 
            mov        bh,0 
            mov        bl,zhlen 
            mov        cx,4 
            sub        cx,bx 
    n24:    mov        zhfld[bx],20h;空余部分用空格填充 
            inc        bx 
            loop       n24 
              
            pop cx 
            pop bx 
            pop dx 
            pop ax 
            ret   
inputzh    endp 
inputcjpm      proc     near 
;void inputsco()  输入学生成绩 
   push ax 
            push dx 
            push bx 
            push cx 
             
            showmsg 054 
            mov        ah,0ah 
            lea        dx,cjpmpar 
            int        21h 
            crlfm 
            mov        bh,0 
            mov        bl,cjpmlen 
            mov        cx,4 
            sub        cx,bx 
    n25:    mov        cjpmfld[bx],20h;空余部分用空格填充 
            inc        bx 
            loop       n25 
              
            pop cx 
            pop bx 
            pop dx 
            pop ax 
            ret   
inputcjpm    endp 
inputjl      proc     near 
;void inputsco()  输入学生成绩 
   push ax 
            push dx 
            push bx 
            push cx
           
            lea dx,jlpar
            mov dx,stustored
            crlfm 
            mov        bh,0 
            mov        bl,jllen 
            mov        cx,4 
            sub        cx,bx 
    n26:    mov       jlfld[bx],20h;空余部分用空格填充 
            inc        bx 
            loop       n26
              
            pop cx 
            pop bx 
            pop dx 
            pop ax 
            ret   
inputjl   endp 
stor          proc      near 
;void stor() stor one item to studnetx tab from input buffer area 
 push ax 
 push bx 
 push dx 
 push di 
 push si 
 push cx 
  
 cmp namelen,0 
 je qsto           
 cld 
 mov       ax,stustored 
 mov       bl,32
 mul       bl 
 lea       dx,studentx 
 mov       stu,dx 
 add       stu,ax 
 mov       di,stu 
 lea       si,namefld 
 mov       cx,6 
 rep       movsb 
 lea       si,numfld 
 mov       cx,8 
 rep       movsb 
 lea       si,sxszfld 
 mov       cx,3 
 rep       movsb
 lea       si,kxwhfld
mov       cx,3  
 rep       movsb
lea       si,sxfld 
mov       cx,3 
 rep       movsb
lea       si,zhfld 
mov       cx,3 
 rep       movsb
mov       cx,3 
 lea       si,cjpmfld 
 rep       movsb
mov       cx,3 
 lea       si,jlfld 
 rep       movsb
 inc       stustored 

qsto:    
 pop cx 
 pop si 
 pop di 
 pop dx 
 pop bx 
 pop ax 
 ret 
stor          endp 
quit proc near 
 ;quit program     
  cmp saveflag,0 
  je  qforsav 
  jmp qsys 
 qforsav: 
  call clear 
  call cursor 
  showmsg qsave 
  mov ah,1 
  int 21h 
  cmp al,'y' 
  je savit 
  jmp qsys 
 savit: 
   call save 
      mov ah,3eh;close file 
      mov bx,filehandle 
      int 21h   
 qsys:      
     mov ax,4c00h 
     int 21h 
     ret 
quit endp 
save        proc       near   ;将内存studnetx表中全部学生信息写入到磁盘文件 
;void save() 
   push cx 
   push ax 
    
            mov        errcde,0 
            call       near ptr clear 
            call       near ptr cursor 
            call       near ptr creath 
            cmp        errcde,0 
            jne        s2 
   sloop:   mov        cx,stustored;一次循环写入一条学生信息 
            cmp        stusaved,cx 
            je         sexit;注意!这里是je而不是ja(调试发现)! ?? 
            call near ptr        writh 
            cmp        errcde,0 
            jne        sexit 
            jmp        sloop 
   sexit:   call near ptr        clseh 
            mov        saveflag,1 
            showmsg    07 
   s2:    showmsg    exit 
            anykey 
            mov        stusaved,0 
          
         pop ax 
         pop cx 
         ret 
save        endp 
creath        proc     near   ;创建磁盘文件并获得句柄 
;void creath() 
    push ax 
    push cx 
    push dx 
    
              showmsg  21 
              call near ptr     get_path 
              crlfm 
              mov      ah,3ch;3ch:建立文件 
              mov      cx,0 
              lea      dx,pathnam 
              int      21h ;03-6-10 20:42 
              jc       a1 
              mov      filehandle,ax 
              pop dx 
              pop cx 
              pop ax 
              ret 
       a1:    lea      dx,opnmsg 
              call     errm 
               
              pop dx 
              pop cx 
              pop ax 
              ret 
creath       endp
 
writh        proc    near  ;将一条item写入到磁盘文件 
             mov     ax,stusaved 
             mov     bl,32 
             mul     bl 
             lea     dx,studentx             
             add     dx,ax;dx指向第一条未保存的item的首地址 
             mov     ah,40h 
             mov     bx,filehandle 
             mov     cx,32;cx:写入的字节数 
             int     21h 
             inc     stusaved 
             jnc     d1 
             lea     dx,wrtmsg;出错处理 
             call near ptr     errm 
       d1:   ret 
writh        endp  
  
  
del_in proc near 
 call clear 
    call cursor 
 call delete_in 
 ret 
del_in endp  

delete_in proc near 
;void delete_in() 
 push ax 
 push dx 
  
 call print 
 crlfm 
 mov ah,9 
 lea dx,msg_delnamin 
 int 21h 
 

 call near ptr  inputname 
    call near ptr  del 
     
    cmp ax,-1 
    je qdel 
    showmsg deled 
qdel: 
    pop dx 
    pop ax 
    ret 
delete_in endp

del proc near 
;int del() 返回-1或1 
 push bx 
 push di 
 push si 
 push cx 

 lea bx,studentx 
 push bx 
 mov bx,1;search(studentx,name) 
 push bx 
 call near ptr  search 
 showmsg printtitle
call near ptr  printline
  cmp ax,-1;先找到被删除项 
 je nomatch 
 mov di,ax 
 mov si,di 
 add si,32;si:j,di:i 
  
 mov cx,stustored;被删除项后面元素前移 
 sub cx,cur_i 
movit: 
 movitem di,si 
 mov di,si;si:j+1 ,di:j 
 mov dx,di 
 add dx,32 
 mov si,dx 
 loop movit 
 mov ax,1 
 mov saveflag,0 
 sub stustored,1 
  
  
nomatch: 
 pop cx 
 pop si 
 pop di 
 pop bx 
 ret 
del endp 

search proc near 
;int search(int begin_addr,int type) 在表中顺序查找输入的名字,返回地址或-1 
  push bp 
  mov bp,sp 
  push di                   
  push bx 
  push si 
  push cx 
  push dx 
   
        mov di,[bp+6]           ;把查找首地址放入di 
        mov dx,stustored           ;名字的个数放dh 
  mov bx,[bp+4];bx:type 
  mov bp,di 
  cmp bx,1 
  je snam 
  cmp bx,2 
  je snum 
  mov cx,3 
  mov bx,cx;dl:保存字符串比较长度 
  lea ax,scofld 
  jmp loop1 
snam: mov cx,6 
  mov bx,cx 
  lea ax,namefld 
  jmp loop1 
snum: mov cx,8 
  mov bx,cx 
  lea ax,numfld   
         
loop1:              
  mov si,ax 
  mov cx,bx 
        repe cmpsb               ;连续查找匹配名字 
        je  found                ;找到跳转found 
        add bp,32              ;把查找转到下一个名字 
        mov di,bp 
        dec dh 
        jnz loop1                ;循环查找 

  mov ax,-1 
  showmsg noext 
        jmp qsearch 

found:  mov ax,bp 
  mov dx,stustored 
  sub dx,bx 
  mov cur_i,dx 

qsearch:pop dx 
  pop cx 
  pop si 
  pop bx 
  pop di 
        pop bp 
        ret 4 
search endp   
code ends 
end start 

⌨️ 快捷键说明

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