学生信息管理系统汇编实现

写这个东西,没有别的目的,只是想检测下这半个月来自己汇编的学习效果,也可以说自讨苦吃吧,想想自己汇编也只能算是刚刚入门吧。

这个课程设计是在看一个博客看到的,在完全没有看他的源码的情况下,一时突发奇想,没有多想,就开始写了。。。


课程设计要求如下:

    1> 要求对学生姓名、年龄、数学、英语成绩等信息进行管理;

     2> 界面友好,能支持插入、删除、查询、修改等基本操作;

     3> 用汇编实现。



当然在完成它的时候,不甘于仅实现这上面的要求,还在这要求之上新加了些功能,

读者看的时候可能会发现在一些 函数传参的时候,完全没有必要,因为参数是全局变量,在函数中可以直接用,没有必要额外传参,当然我这样做的目的只是为是体验高级语言下的传参的真正实现,更彻底的理解高级语言,这也是学汇编的原因。

我用的汇编器是visual studio里面的ML,链接器是masm615里面的,因为masm615里面的汇编器有些不足,还有这份代码要编译链接通过的话,还需要一个库文件,irvine32.lib和irvine32.inc 若是需要的朋友可以联系我(我也会上传源码文件,可以自行下载 ),

下面是实现的源码(可能比较乱,没来得及优化。):


title Students infomation manage program  (StuInfoMag.asm)

comment !
        this program is useing for manage student infomation.
		it provide the function of inputing , insert , searvch , 
		 delete the student's infomation 
		(include name , age , math scores)......
                                              ------programer:life_still
                                              ------2012.3.27 22:39
        !
		
include irvine32.inc
includelib irvine32.lib
includelib kernel32.lib
includelib user32.lib

;===========================operation const=================================
invalid_operation  equ   0
insert_std      equ      1
delete_std      equ      2
modify_std      equ      3
query_std       equ      4
count_std       equ      5
Print_all       equ      6
list_name       equ      7
exit_sym        equ      8
Rstart          equ      9
store_to_file   equ      10
name_length = 15
;===========================================================================

;=========================user define data struct============================
Info Struct
     nname byte name_length+1 dup (0)  ; student's name
	 number dword 0 ; number
     Age  byte 0     ; student's age
	 e_mark byte 0   ; english mark
	 m_mark byte 0   ; math_mark
	 c_mark byte 0   ; chinese_mark
Info ends

ListNode struct
    stu Info <>
	NextPtr dword 0
ListNode ends

.data
interface_str byte 0dh,0ah
               byte "================================================================================",0dh,0ah
               byte "                            Student Management System                ",0dh,0ah
			   byte "                          Softwre promgramer: life_syill             ",0dh,0ah
			   byte "--------------------------------------------------------------------------------",0dh,0ah
			   byte "                               Operation Table                     ",0dh,0ah
			   byte "                              ------------------                   " ,0dh,0ah
			   byte "                             1.Insert Student Info                " ,0dh,0ah
			   byte "                             2.Delete Student Info                " ,0dh,0ah
			   byte "                             3.Modify Student Info                ",0dh,0ah
			   byte "                             4.Query  Student Info                ",0dh,0ah
			   byte "                             5.Count  Student Num                 ",0dh,0ah
			   byte "                             6.Print  All     Info                ",0dh,0ah
			   byte "                             7.List   Student Name                ",0dh,0ah
               byte "                             8.Exit         System 			   ",0dh,0ah
			   byte "                             9.Restart      system                ",0dh,0ah
			   byte "                             10.store data to file                ",0dh,0ah
               byte "================================================================================",0dh,0ah ,0

interface_strlen dword ($-interface_str)
str1 byte "please chose the operation acordding the operation table:",0
str2 byte "invalid operation code,please chose again....",0
str3 byte "failed to get the process memery heap handle.exit system....",0

str_name byte "student's name :",0
str_number byte "student's number: ",0
str_math byte "math scores:",0
str_English byte "English Scores:",0
str_chinese byte "chineese scores:",0

    str_1 byte "input the name:",0
	str_2 byte "Input the age:" ,0
	str_3 byte "Input the math mark:",0
	str_4 byte "Input the english mark:",0
	str_5 byte "Input the chinese mark:",0
	str_6 byte "Input the student's number:",0
	
str_q1 byte '===================Qury student information===================',0
str_d3 byte "=====================Delete Student's data====================",0
str_m1 byte "=====================Modify student's info======================",0

operation_index dword 0       ; operation code
Isvalid_operation byte 0        ; judge whether the inputing is valid operation code
Isfound dword 0                 ; judge whether found the student with the number when qury the student

;=============core data space==============
PLISTNODE TYPEDEF PTR ListNode
listHead ListNode < <> ,0>   ;list header
prePnode DWORD offset listHead     ; point to the previous Node
pcurrent DWORD 0                 ;point to the current Node user operation
hHeap dword 0    ; memery heap handle
stu_count dword 0
filename byte 40 dup(0)
hFile dword 0
;==========================================

.code
_main proc
;=========
    call GetProcessHeap     ;Get the process default memeery heap
                                ;	handle for alloc memery when insert student
	mov hHeap ,eax
	
	cmp eax ,INVALID_HANDLE_VALUE
	jne start
	
    mov edx ,offset str3
    call WriteString
    jmp quit 
	
;==========	
start:
    mov eax ,28
	call SetTextColor
    call clrscr
    push offset interface_str  
    call showface_chose 	; display the operation table and read the user input of operation index

operate:
	push offset str1
	call WaitingForOperate
	call compare_operation	 ;compare operation according user inputing 
	                                         ;and return the Isvalid_operation true or false	
											 
	cmp Isvalid_operation ,invalid_operation
	je invalid_opt
	
	cmp operation_index ,insert_std
	je Insert ;;;
    cmp operation_index ,delete_std 
	je Delete ;;;
	cmp operation_index ,modify_std 
	je Modify ;;;
	cmp operation_index ,query_std 
	je Qury ;;;
	cmp operation_index ,count_std
	je count ;;;
	cmp operation_index ,Print_all 
	je Print ;;;
	cmp operation_index ,list_name
	je Listname ;;;
	cmp operation_index ,exit_sym
	je Exitsym  ;;;
	cmp operation_index ,Rstart
	je Restart ;;;
	cmp operation_index ,store_to_file
	je Store_file
	jmp operate
	
invalid_opt:
     mov edx ,offset str2
	 call WriteString               ;display errcor operation infomation
	 jmp operate
	
;==============================================================function Call=========================================================================================	
insert:                                           
    call InsertStu                                    
	jmp operate
;=======
count:
    call Count_stu
	jmp operate
;======

Qury:
    push offset str_q1
    push offset listhead
	push stu_count
    call Qury_stu
	jmp operate
;=======
listname:
    push offset listHead
	push stu_count
    call _list_name
	jmp operate

;========
print:
     push offset ListHead
	 push stu_count
	 call _Print_all
	 jmp operate
;========
delete:
     call _delete
     jmp operate
;======
Modify:
     push offset Listhead
	 push stu_count
	 call _Modify
	 jmp operate
Restart:
    push offset listhead
	push stu_count
	call freememHeap
	jmp start
	
store_file:
     push offset listhead
	 push stu_count
     call _Store_data_to_file
     jmp operate
	
Exitsym:
    push offset listHead
    push stu_count
    call freeMemHeap
;===========
quit:	
	exit
_main endp
;==================================================================Function to implement==================================================================================
showface_chose proc
   push ebp
   mov ebp ,esp
   push edx
   mov edx ,[ebp+8]
   call WriteString
   pop edx
   pop ebp
   ret 4
showface_chose endp
;=======================
;=======================
WaitingForOperate proc
     push ebp
	 mov ebp ,esp
	 push edx
	 mov edx ,[ebp+8]
	 call WriteString
	 call ReadInt
	 mov operation_index ,eax
	 pop edx
	 pop ebp
	 ret 4
WaitingForOperate endp

;=======================
compare_operation proc
    push ebp
	mov ebp ,esp
	push eax
	
    mov eax ,operation_index
	
	cmp eax ,1
	jb quit
	cmp eax ,10
	ja quit
	mov Isvalid_operation ,1
	jmp rtn
quit:
    mov Isvalid_operation ,0
rtn:
	pop eax
	pop ebp
    ret 
compare_operation endp
;===========================
InsertStu proc
.data
    str_I1 byte "====================Insert New Student======================",0
.code
     pushad
	 mov eax ,30
	 call SetTextColor
	 mov edx ,offset str_I1
	 call WriteString
	 call Crlf
	 mov eax ,28
	 call SetTextColor
	 
     INVOKE HeapAlloc, hHeap ,HEAP_ZERO_MEMORY ,type ListNode
	 mov pcurrent ,eax
	 mov edi ,eax
	 
     mov edx , offset str_1	 
	 call WriteString
	 mov ecx ,name_length
	 mov edx , edi               ;offset (ListNode ptr[edi]).stu.nname
	 call ReadString
	 
	 mov edx ,offset str_6
	 call WriteString
	 call ReadInt
	 mov (ListNode ptr[edi]).stu.number , eax
	 
	 mov edx ,offset str_2
	 call WriteString
	 call ReadInt
	 mov (ListNode ptr[edi]).stu.age ,al
	 
	 mov edx ,offset str_3
	 call WriteString
	 call ReadInt
	 mov (ListNode ptr[edi]).stu.m_mark ,al
	 
	 mov edx ,offset str_4
	 call WriteString
	 call ReadInt
	 mov (ListNode ptr[edi]).stu.e_mark ,al
	 
	 mov edx ,offset str_5
	 call WriteString
	 call ReadInt
	 mov (ListNode ptr[edi]).stu.c_mark ,al
	 
	 call Crlf
	 call Crlf
	 
	 mov esi ,prePnode
	 mov (ListNode ptr[esi]).NextPtr ,edi
	 mov prePnode ,edi
	 inc stu_count
	 popad
     ret
insertStu endp
;===========================

FreeMemHeap proc
     push ebp
	 mov ebp ,esp
	 push ecx
	 push edi
	 
	 mov ecx ,[ebp+8]
	 cmp ecx ,0
	 jbe rt1
	 mov edi ,[ebp+12]
	 mov ecx ,[ebp+8]
lp01:
     push ecx
	 mov edi ,(ListNode ptr[edi]).NextPtr
     INVOKE HeapFree , hHeap ,1 ,edi
	 dec stu_count
	 pop ecx
	 loop lp01
rt1:
	 pop edi
	 pop ecx
	 pop ebp
	 ret 8
FreeMemHeap endp
;=============================
Count_Stu proc
.data
    
    str_c1 byte "the total of student number: ",0
	str_c2 byte "=================Count total student=======================",0
.code
    mov eax ,30
	call SetTextColor
	mov edx ,offset str_c2
	call WriteString
	call crlf
	mov eax ,28
	call SetTextColor
	
    mov edx ,offset str_c1
	call WriteString
	mov eax ,stu_count
	call WriteDec
	call Crlf
	ret
Count_Stu endp
;===========================
Qury_stu proc       ;reuurn the listNode adress in eax and the previous listnode adress in ebx if found and write the Isfound to judge whether found the data 
.data
	 str_q2 byte "Enter the student's number you want to qury:",0
	 str_q3 byte "Found student:",0dh,0ah,0
	 str_q5 byte "no student with the number: ",0
	 stu_number dword 0
.code
     push ebp
	 mov ebp,esp
	 push esi
	 push edx
	 
	 mov edx ,[ebp+16]
	 
	 mov eax ,30
	 call SetTextColor
	 call WriteString
	 call crlf
	 mov eax ,28
	 call SetTextColor
	 
	 mov edx ,offset str_q2
	 call WriteString
	 call ReadInt
	 mov stu_number ,eax
	 
	 mov ecx ,[ebp+8]
	 mov esi ,[ebp+12]
lp02:
     mov ebx ,esi
     mov esi ,(ListNode ptr[esi]).NextPtr
	 cmp eax , (ListNode ptr[esi]).stu.number
	 je ok_q1
	 loop lp02
	 jmp rt_q
	 
ok_q1:
     mov edx ,offset str_q3
	 call WriteString
	 call crlf
	 
	 mov edx ,offset str_name
	 call WriteString
	 mov edx ,esi
	 call WriteString
	 call Crlf
	 
	 mov edx ,offset str_number
	 call WriteString
	 mov eax ,(ListNode ptr[esi]).stu.number
	 call WriteDec
	 call Crlf
	 
	 mov edx ,offset str_math
	 call WriteString
	 movzx eax ,(ListNode ptr[esi]).stu.m_mark
	 call WriteDec
	 call Crlf
	 
	 mov edx ,offset str_english
	 call WriteString
	 movzx eax,(ListNode ptr[esi]).stu.e_mark
	 call WriteDec
	 call Crlf
	 
	 mov edx,offset str_chinese
	 call WriteString
	 movzx eax ,(ListNode ptr[esi]).stu.c_mark
	 call WriteDec
	 call Crlf
	 call crlf
	 call crlf
	 mov eax ,esi
	 mov Isfound ,1
	 jmp ed
	 
rt_q:
     mov edx ,offset str_q5
	 call WriteString
	 mov eax ,stu_number
	 call WriteDec
	 mov Isfound ,0
	 call Crlf
	 call crlf
	 call crlf
ed:	 
	 pop edx
	 pop esi
	 pop ebp
	 ret 12
qury_stu endp
;=====================

_list_name proc
.data
     str_l1 byte "there is no students in database.",0
	 str_l2 byte "==================List all student's name===================",0
.code
     push ebp
	 mov ebp,esp
	 push eax
	 push ecx
	 push edx
	 
	 mov eax ,30
	 call SetTextColor
	 mov edx ,offset str_l2
	 call WriteString
	 call Crlf
	 mov eax ,28
	 call SetTextColor
	 
	 mov edx,[ebp+12]
	 mov ecx,[ebp+8]
	 mov eax ,1
	 cmp ecx ,0
	 je rtl1
lpl1:
    call WriteDec
	inc eax
    mov edx,(ListNode ptr[edx]).NextPtr
    call WriteString 
    call crlf
	loop lpl1
	
	call Crlf
	call Crlf
	jmp edl1
rtl1:
    mov edx ,offset str_l1
	call WriteString
	call Crlf
	call crlf
edl1:
    pop edx
	pop ecx
	pop eax
	pop ebp    	
	ret 8
_list_name endp

;====================
_Print_all proc
.data

     str_p1 byte "=================Print all stu info=====================",0
	 str_p2 byte "student  ",0ah,0
	 str_p3 byte "---------------",0
	 str_p4 byte "there is no student in database.",0
.code
     push ebp
	 mov ebp ,esp
	 push eax
	 push ecx
	 push edi
	 push edx
	 
	 mov eax ,30
	 call SetTextColor
	 mov edx ,offset str_p1 
	 call WriteString
	 call Crlf
	 mov eax ,28
	 call SetTextColor
	 
	 mov ecx ,[ebp+8]
	 mov edi ,[ebp+12]
	 mov eax ,1
	 cmp ecx ,0
	 je rtp1
lpp1:
     push ecx
     mov edi,(ListNode ptr[edi]).NextPtr
	 
	 mov edx ,offset str_p2
	 call WriteString

	 
	 call WriteDec
	 inc eax 
	 call Crlf
	 
	 push eax
	 mov edx ,offset str_name
	 call WriteString
	 mov edx ,edi
	 call WriteString
	 call Crlf
	 
	 mov edx ,offset str_number
	 call WriteString
	 mov eax ,(ListNode ptr[edi]).stu.number
	 call WriteDec
	 call crlf
 
	 mov edx ,offset str_math
	 call WriteString
	 movzx eax ,(ListNode Ptr[edi]).stu.m_mark
	 call WriteDec
	 call Crlf
;=========================
	 jmp lpp13
lpp12:
     jmp lpp1
lpp13:
;=========================
	 mov edx ,offset str_english
	 call WriteString
	 movzx eax ,(ListNode ptr[edi]).stu.e_mark
	 call WriteDec
	 call Crlf
	 
	 mov edx ,offset str_chinese
	 call WriteString
	 movzx eax ,(ListNode ptr[edi]).stu.c_mark
	 call WriteDec
	 call Crlf
	 
	 mov edx ,offset str_p3
	 call WriteString
	 call Crlf
	 
	 pop eax
	 pop ecx
	 loop lpp12
	 call crlf
	 call crlf
	 jmp enp
rtp1:
     mov edx ,offset str_p4
	 call WriteString
	 call Crlf
	 call crlf
enp:  
     pop edx
	 pop edi
	 pop ecx
	 pop eax
	 pop ebp
	 ret 8
_print_all endp
;===================

_delete proc
.data
     ;str_d1 byte "Enter the student's number:",0
	 str_d2 byte " deleted the student.",0
	; 
	 str_num DWORD 0
.code
     push eax 
	 push edx
	 push ebx
	 push offset str_d3
     push offset listhead
	 push stu_count
	 call qury_stu
	 call Crlf
	 cmp Isfound ,0
	 je rtd1

	 mov edx,(ListNode ptr[eax]).NextPtr
     mov (ListNode ptr[ebx]).NextPtr,edx
	 INVOKE HeapFree ,hHeap ,1 ,eax
	 mov edx,offset str_d2
     call WriteString
	 call crlf
	 call crlf
	 call crlf
	 dec stu_count
rtd1:	 
	 pop ebx
	 pop edx
	 pop eax
     ret
_delete endp
	 
;===================

_Modify proc
.data
     
	 str_m2 byte "Input The new data for the student:",0
	 str_m3 byte "OK!,the new data is stored to database.",0
.code
     push ebp
	 mov ebp,esp
	 push eax
	 push ecx
	 push esi
	 push edx
	 
	 push offset str_m1
	 push [ebp+12]
	 push [ebp+8]
	 call Qury_stu
	 
	 cmp Isfound ,0
	 je rtm1
	 
	 mov esi ,eax
	 mov edx ,offset str_m2
	 call WriteString
	 
	 mov edx ,offset str_1
	 call WriteString
	 mov edx ,esi
	 mov ecx ,name_length
	 call ReadString
	 
	 mov edx ,offset str_6
	 call WriteString
	 call ReadInt
	 mov (ListNode ptr[esi]).stu.number ,eax
	 
	 mov edx ,offset str_2
	 call WriteString
	 call ReadInt
	 mov (ListNode ptr[esi]).stu.age ,al
	 
	 mov edx ,offset str_3
	 call WriteString
	 call ReadInt
	 mov (ListNode ptr[esi]).stu.m_mark ,al
	 
	 mov edx ,offset str_4
	 call WriteString
	 call ReadInt
	 mov (ListNode ptr[esi]).stu.e_mark ,al
	 
	 mov edx ,offset str_5
	 call WriteString
	 call ReadInt
	 mov (ListNode ptr[esi]).stu.c_mark ,al
	 
	 mov edx,offset str_m3
	 call WriteString
	 call Crlf
	 call crlf
	 call crlf
rtm1:	 
	 pop edx
	 pop esi
	 pop ecx
	 pop eax
	 pop ebp
	 ret 8
_Modify endp

;===========================
_store_data_to_file proc
.data
     str_dt1 byte "======================Store data to file=====================",0
	 str_dt2 byte "Enter the file name(absolute path)to store data:",0
	 str_dt3 byte "failed to create file....",0
	 str_dt4 byte "OK ,succesed to store data to file",0

	 str_demo byte "this program is useing for manage student infomation.it provide the function of inputing , insert , searvch ,delete the student's infomation (include name , age , math scores......)------programer:life_still(钟)------2012.3.27 22:39 ",0
	demo_len dword ($-str_demo)
	
	str_dt_f1 byte "          ",0
	str_len_f1 dword ($-str_len_f1)

	 
.code
     push ebp
	 mov ebp ,esp
	 
     mov eax ,30
	 call SetTextColor
	 mov edx ,offset str_dt1
	 call WriteString
	 call crlf
	 mov eax ,28
	 call SettextColor
	 
	 mov edx ,offset str_dt2
	 call WriteString
	 
	 mov edx ,offset filename
	 mov ecx ,39
	 call ReadString
	 
	 mov edx ,offset filename
	 call CreateOutputFile
	 mov hfile ,eax
	 cmp eax ,INVALID_HANDLE_VALUE
	 je hfile_error
	 
	 mov eax ,hfile
	 mov edx ,offset interface_str
	 mov ecx ,interface_strlen
	 call WriteToFile
	 
	 mov eax ,hfile
	 mov edx ,offset str_demo
	 mov ecx ,demo_len
	 call writetofile

     mov ecx ,[ebp+8]
	 mov edi, [ebp+12]
	 cmp ecx ,0
	 je rt_dt
lp_dt:
     push ecx
	 push edi
	 mov edi ,(ListNode ptr[edi]).NextPtr
	 
	 mov eax ,hfile
	 mov ecx ,16
	 mov edx ,edi
	 call WriteTofile
	 
	 mov edx ,offset str_dt_f1
	 mov ecx ,str_len_f1
	 call WriteTofile
	 
	 pop edi
	 pop ecx
	 loop lp_dt
	 
	 call closefile
	 mov edx ,offset str_dt4
	 call WriteString
	 call crlf
	 call Crlf
	 call crlf
	 jmp rt_dt
	                           
hfile_error:
     mov edx ,offset str_dt3
	 call WriteString
	 call crlf
	 call crlf
	 call crlf
	 
rt_dt:
     pop ebp
	 ret 8
_store_data_to_file endp
end _main

	
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
下面是效果图:





















  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值