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

📄 11.asm.asm

📁 这是个汇编语言写的课程设计
💻 ASM
字号:
vardata segment
        filename        db      'ttttt.txt',00
vardata ends
condata segment
        names   db      10      dup(?)
        age     db      ?,?
        mess_n  db      0dh,0ah,'       name:   $'
        mess_a  db      0dh,0ah,'       age:    $'
        str     db      0dh,0ah
                db      '1: print list     [L]',0dh,0ah
                db      '2: insert new ele [I]',0dh,0ah
                db      '3: quit           [q]',0dh,0ah
                db      '$'
condata ends

code segment
        assume cs:code,ds:vardata,es:condata
main    proc    far
start:
        mov     ax,     condata
        mov     es,     ax
        mov     ax,     vardata
        mov     ds,     ax
        push    ds
;--------------print command hint-------------------
        mov     ax,     es
        mov     ds,     ax
        mov     dx,     offset str
        mov     ah,     9h
        int     21h
        pop     ds
;----------------intepret command------------------
cmp_l:  mov     ah,     01h
        int     21h
        cmp     al,     'l'
        jnz     cmp_i
        call    list_all
        jmp     start
cmp_i:
        cmp     al,     'i'
        jnz     cmp_q
        call    insert
        jmp     start
cmp_q:
        cmp     al,     'q'
        jnz     cmp_l
        
exit:
        mov     ax,     4c00h
        int     21h
main    endp
list_all proc near
        call    open_create     ;open or create file
        push    ds
        mov     ax,     es
        mov     ds,     ax
loop_rd:
        mov     ah,     3fh    ;read record from file to memory
        mov     dx,     offset  names
        mov     cx,     12
        mov     bx,     si
        int     21h
        cmp     ax,     0
        je      read_finish    ;read to the end,then finish


;--------------------print      the     record----------

        mov     dx,     offset  mess_n  ;print the name
        mov     ah,     9
        int     21h

        mov     bx,     0
go_on:
        mov     dl,     names[bx]
        mov     ah,     2h
        int     21h

        inc     bx
        cmp     bx,     10
        jl      go_on
                                                
        mov     dx,     offset  mess_a      ;print the age
        mov     ah,     9
        int     21h

        mov     dl,     age[0]
        mov     ah,     2
        int     21h

        mov     dl,     age[1]
        mov     ah,     2
        int     21h
        jmp     loop_rd   ;     a record finished ,then to read the next
read_finish:
        call    closef
        pop     ds
        ret
list_all endp
insert  proc    near
        call    open_create            ; open of create file
        push    ds
        mov     ax,     es
        mov     ds,     ax
        mov     dx,     offset  mess_n
        mov     ah,     9h
        int     21h
        mov     bx,     0
init:                                 ;memory initialize
        mov     names[bx],0
        inc     bx
        cmp     bx,     12
        jl      init
        mov     bx,     0
lp:                         ;accept keyboard input(name)
        mov     ah,     1
        int     21h
        cmp     al,     0dh ;whether it is carriage return
        jz      i_end
        cmp     al,     0ah ;whether it is line feed
        jz      i_end
        mov     names[bx],al
        inc     bx
        cmp     bx,     12
        jl      lp
i_end:
        cmp     al,     0dh ;trim surplus char
        jz      inext
        cmp     al,     0ah
        jz      inext
        mov     ah,     1
        int     21h
        jmp     i_end
inext:
        mov     dx,     offset      mess_a
        mov     ah,     9h
        int     21h
        mov     bx,     0
lp2:    mov     ah,     1h
        int     21h
        cmp     al,     0dh
        jz      ii_end
        cmp     al,     0ah
        jz      ii_end
        mov     age[bx],al
        inc     bx
        cmp     bx,     1
        jle     lp2
ii_end:
        cmp     al,     0dh
        jz      iexit
        cmp     al,     0ah
        jz      iexit
        mov     ah,     1
        int     21h
        jmp     ii_end
iexit:                         ;move the file pointer to the end of file
        
        mov     ah,     42h
        mov     al,     2
        mov     bx,     si
        mov     cx,     0
        mov     dx,     0
        int     21h

        mov     ah,     40h  ;write the record to file
        mov     bx,     si
        mov     cx,     12
        mov     dx,     offset  names
        int     21h

back:
        call    closef
        pop     ds
        ret
insert  endp
open_create     proc    near
        push    ds
        mov     ax,     seg     filename
        mov     ds,     ax
        mov     ah,     3dh  ;open the file
        mov     dx,     offset filename
        mov     al,     2h
        int     21h
        jnc     ok
        mov     ah,     3ch     ;if not exit,create it
        mov     dx,     offset filename
        mov     cx,     00
        int     21h

ok:
        mov     si,     ax
        pop     ds
        ret
open_create     endp
closef  proc    near
        mov     bx,     si
        mov     ah,     3eh
        int     21h
        ret
closef  endp
code    ends
end     start

⌨️ 快捷键说明

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