📄 仓库管理系统.asm
字号:
DATAS SEGMENT
; 测试时用字符串
test_insert db 'chose insert: ','$'
test_list db 'chose list: ','$'
test_modify db 'chose modify: ','$'
test_delete db 'chose delete: ','$'
test_search db 'chose search: ','$'
; 创建字符串常量
menu_title0 db ' Homework 3 ',0ah,0dh,'$'
menu_title db ' PART STOCKPILE MANAGEMENT SYSTEM',0ah,0dh,'$'
menu_menu db ' MENU ',0ah,0dh,'$'
menu_select db ' INSERT (i) PLEASE SELECT:',0ah,0dh,'$'
menu_ID db ' LIST (l) part ID:',0ah,0dh,'$'
menu_name db ' MODIFY (m) part Name:',0ah,0dh,'$'
menu_price db ' DELETE (d) price:',0ah,0dh,'$'
menu_amount db ' SEARCH (s) amount:',0ah,0dh,'$'
menu_totalprice db ' totalPrice:',0ah,0dh,'$'
menu_MIN db ' MIN:',0ah,0dh,'$'
menu_exit db ' EXIT (e)',0ah,0dh,'$'
menu_ db '----------------------------------------------------------',0ah,0dh,'$'
menu_list db ' ID---Name-------P---A---T---MIN ',0ah,0dh,'$'
fname db "D:\part.txt",0 ;制定存取文件的路径
;创建新文件
CreateNewFile MACRO PATHNAM,FILEHANDLE
LOCAL QUIT
PUSH BX
PUSH CX
PUSH DX
MOV AH,3CH ; 3C-创建新文件
MOV CX,0
LEA DX,PATHNAM
INT 21H
MOV FILEHANDLE,AX ;保存文件标记
MOV AL,0
JMP QUIT
QUIT:
POP DX
POP CX
POP BX
ENDM
;定义缓存区
buffer_full DB 25 dup(?)
buffer_id_name DB 15 dup(?)
buffer_else DB 10 dup(0)
;buffeer db 0ah,0dh,'$'
handle dw ?
del DB 25 dup(' ')
;x db ?
DATAS ENDS
;定义库存结构体
PART STRUC
partID DB 3 DUP(?)
partName DB 12 DUP(?)
price DW ?
number DW ?
totalPrice DD ?
min DW ?
PART ENDS
;定义宏
display MACRO addrs ;显示字符串
LEA dx,addrs
MOV ah,9
INT 21h
ENDM
setting1 MACRO x ;设置光标位置
mov ah,2
mov dh,x
mov dl,36
mov bh,0
int 10h
ENDM
setting2 MACRO ;设置光标位置
mov ah,2
mov dh,15
mov dl,0
mov bh,0
int 10h
ENDM
setting3 MACRO ;设置光标位置
mov ah,2
mov dh,4
mov dl,42
mov bh,0
int 10h
ENDM
clearFULL MACRO ;全屏幕显示设置
mov al,0
mov cl,0
mov ch,0
mov dh,24
mov dl,100
mov bh,1fh
mov ah,6
int 10h
ENDM
clearLEFT MACRO ;左屏幕显示设置
mov al,0
mov bh,1fh
mov ch,4
mov cl,36
mov dh,10
mov dl,79
mov ah,6
int 10h
ENDM
clearBOTTOM MACRO ;下屏幕设置
mov al,0
mov bh,1fh
mov ch,14
mov cl,0
mov dh,24
mov dl,79
int 10h
ENDM
clearWINDOW MACRO ;清空窗口
mov al,0
mov bh,3ah
mov ch,3
mov cl,1
mov dh,12
mov dl,14
int 10h
ENDM
clearTITLE MACRO ;清空标题
mov al,2
mov bh,4bh
mov ch,0
mov cl,9
mov dh,0
mov dl,40
int 10h
ENDM
newline MACRO ;产生一个新行
push ax
push dx
mov dl,0dh
mov ah,2
int 21h
mov dl,0ah
mov ah,2
int 21h
pop dx
pop ax
ENDM
display_record MACRO addrs
local iloop,w10,w2,jloop
push bx
push cx
mov bx,0
iloop: ; 循环3次输出ID号
mov dl,addrs[bx]
mov ah,2
int 21h
inc bx
cmp bx,3
jl iloop
mov cx,2
w2: ; 打印2空格
mov dl,' '
mov ah,2
int 21h
loop w2
jloop: ; 循环12次输出Name
mov dl,addrs[bx]
mov ah,2
int 21h
inc bx
cmp bx,15
jl jloop
mov cx,2
w10: ; 循环2次 输出单价和数目
mov dl,' '
mov ah,2
int 21h
mov dl,' '
mov ah,2
int 21h
mov dl,addrs[bx]
mov ah,2
int 21h
inc bx
mov dl,addrs[bx]
mov ah,2
int 21h
inc bx
loop w10
; 输出总价
mov dl,' '
mov ah,2
int 21h
mov dl,' '
mov ah,2
int 21h
mov dl,addrs[bx]
mov ah,2
int 21h
inc bx
mov dl,addrs[bx]
mov ah,2
int 21h
inc bx
mov dl,addrs[bx]
mov ah,2
int 21h
inc bx
mov dl,addrs[bx]
mov ah,2
int 21h
inc bx
mov dl,' '
mov ah,2
int 21h
mov dl,' '
mov ah,2
int 21h
; 输出库存下限
mov dl,addrs[bx]
mov ah,2
int 21h
inc bx
mov dl,addrs[bx]
mov ah,2
int 21h
newline
pop cx
pop bx
ENDM
input MACRO addrs,count2
local zeroit,lp,input_end,exit
push bx
push ax
mov bx,0
zeroit:
mov addrs[bx],' '
inc bx
cmp bx,15
jl zeroit
mov bx,0
lp:
mov ah,1
int 21h
cmp al,0ah
jz input_end
cmp al,0dh
jz input_end
mov addrs[bx],al
inc bx
cmp bx,count2
jl lp
input_end:
cmp al,0dh ;输入结束
jz exit
cmp al,0ah
jz exit
mov ah,7
int 21h
jmp input_end
exit: ;结束
pop ax
pop bx
ENDM
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:DATAS
START:
MOV AX,DATAS
MOV DS,AX
mov ah,1
mov al,3
int 10h
FILE_HANDLE DW ?
clearFULL ;显示界面
clearWINDOW
clearTITLE
display menu_title0
display menu_title
display menu_
display menu_menu
display menu_select
display menu_ID
display menu_name
display menu_price
display menu_amount
display menu_totalprice
display menu_MIN
display menu_exit
newline
display menu_
setting3
; 创建新文件
CreateNewFile fname,handle
; 用户按菜单选择 执行相应的功能
choose_insert:
mov ah,7 ; 无回显用户输入
int 21h
cmp al,'i'
jnz choose_modify
call insert
; 测试通过
;MOV AH,9
;LEA DX,test_insert
;INT 21H
jmp choose_insert
choose_modify:
cmp al,'m'
jnz choose_delete
call modify
; 测试通过
;MOV AH,9
;LEA DX,test_modify
;INT 21H
jmp choose_insert
choose_delete:
cmp al,'d'
jnz choose_search
call delete
; 测试通过
;MOV AH,9
;LEA DX,test_delete
;INT 21H
jmp choose_insert
choose_search:
cmp al,'s'
jnz choose_list
call search
; 测试通过
;MOV AH,9
;LEA DX,test_search
;INT 21H
jmp choose_insert
choose_list:
cmp al,'l'
jnz choose_exit
call list
; 测试通过
;MOV AH,9
;LEA DX,test_list
;INT 21H
jmp choose_insert
choose_exit:
cmp al,'e'
jz exit
jmp choose_insert
exit:
mov ah,4ch
int 21h
ret
; 插入函数
insert proc near
push ax
push bx
push cx
push dx
mov dx,offset fname
mov al,2 ; 读写访问
mov ah,3dh ; 打开文件
int 21h
mov bx,ax
clearLEFT
setting1 5
call get_rec
mov cx,0 ;将文件指针移向文件末尾
mov dx,0
mov al,2
mov ah,42h
int 21h
mov cx,25
mov dx,offset buffer_full
mov ah,40h ;写文件
int 21h
mov ah,3eh
int 21h
setting3
pop dx
pop cx
pop bx
pop ax
ret
insert endp
get_rec proc near
push ax
push bx
input buffer_id_name, 3 ; 读入3个到小缓冲
mov bx,0
mov cx,3
continue:
mov al,buffer_id_name[bx] ; 复制到大缓冲
mov buffer_full[bx],al
inc bx
loop continue
setting1 6
input buffer_id_name, 12 ; 读入12个到小缓冲
mov cx,12
continue2:
mov al,buffer_id_name[bx-3] ; 复制到大缓冲
mov buffer_full[bx],al
inc bx
loop continue2
setting1 7
input buffer_id_name,2 ; 读入2个到小缓冲并复制到大缓冲
mov al,buffer_id_name
mov buffer_full[bx],al
inc bx
mov al,buffer_id_name + 1
mov buffer_full[bx],al
inc bx
setting1 8
input buffer_id_name,2 ; 读入2个到小缓冲并复制到大缓冲
mov al,buffer_id_name
mov buffer_full[bx],al
inc bx
mov al,buffer_id_name + 1
mov buffer_full[bx],al
inc bx
setting1 9
input buffer_id_name,4 ; 读入4个到小缓冲并复制到大缓冲
mov al,buffer_id_name
mov buffer_full[bx],al
inc bx
mov al,buffer_id_name + 1
mov buffer_full[bx],al
inc bx
mov al,buffer_id_name + 2
mov buffer_full[bx],al
inc bx
mov al,buffer_id_name + 3
mov buffer_full[bx],al
inc bx
setting1 10
input buffer_id_name,2 ; 读入2个到小缓冲并复制到大缓冲
mov al,buffer_id_name
mov buffer_full[bx],al
inc bx
mov al,buffer_id_name + 1
mov buffer_full[bx],al
inc bx
pop bx
pop ax
ret
get_rec endp
; 查询函数
search proc near
push ax
push bx
push cx
push dx
clearLEFT
clearBOTTOM
mov dx,offset fname
mov al,2 ; 读写访问
mov ah,3dh ; 打开文件
int 21h
mov bx,ax
setting2
input buffer_full,3
lea dx,menu_list
mov ah,9 ; 显示字符串
int 21h
b:
mov ah,3fh ; 读文件
mov cx,25
mov dx,offset buffer_id_name
int 21h
lea si,buffer_id_name
lea di,buffer_full
mov cx,3
ee:
mov al,byte ptr[si]
cmp al,byte ptr[di]
jnz b
inc si
inc di
loop ee
display_record buffer_id_name
mov ah,3eh
int 21h
pop dx
pop cx
pop bx
pop ax
ret
search endp
;列表函数
list proc near
push ax
push bx
push cx
push dx
clearLEFT
clearBOTTOM
setting2
display menu_list
mov dx,offset fname
mov al,2
mov ah,3dh ; 打开文件
int 21h
mov bx,ax
again:
mov dx,offset buffer_full
mov cx,25
mov ah,3fh
int 21h
cmp ax,0
jz p
display_record buffer_full
jmp again
p:
mov ah,3eh ; 关闭文件
int 21h
setting3
pop dx
pop cx
pop bx
pop ax
ret
list endp
;修改文件函数
modify proc near
push ax
push bx
push cx
push dx
clearLEFT
setting1 5
mov dx,offset fname
mov al,2
mov ah,3dh
int 21h
mov bx,ax
mov handle,ax
call get_rec
read:
mov dx,offset buffer_id_name
mov cx,25
mov ah,3fh
int 21h
lea si,buffer_id_name
lea di,buffer_full
mov cx,3
c5:
mov dl,byte ptr[si]
cmp dl,byte ptr[di]
jnz read
inc si
inc di
loop c5
mov bx,handle
mov ah,42h ; 移动文件指针
mov al,1 ; 从当前位置移动
mov cx,0ffffh
mov dx,-25
int 21h
mov cx,25
mov dx,offset buffer_full
mov ah,40h ; 写文件
int 21h
mov ah,3eh
int 21h
pop dx
pop cx
pop bx
pop ax
ret
modify endp
;删除函数
delete proc near
push ax
push bx
push cx
push dx
clearLEFT
setting1 5
mov dx,offset fname
mov al,2
mov ah,3dh
int 21h
mov bx,ax
mov handle,ax
input buffer_full,3
read5:
mov dx,offset buffer_id_name
mov cx,25
mov ah,3fh
int 21h
lea si,buffer_id_name
lea di,buffer_full
mov cx,3
c6:
mov dl,byte ptr[si]
cmp dl,byte ptr[di]
jnz read5
inc si
inc di
loop c6
mov bx,handle
mov ah,42h
mov al,1
mov cx,0ffffh
mov dx,-25
int 21h
mov cx,25
mov dx,offset del
mov ah,40h
int 21h
mov ah,3eh
int 21h
setting3
pop dx
pop cx
pop bx
pop ax
ret
delete endp
MOV AH,4CH
INT 21H
CODES ENDS
END START
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -