.386
.model flat,stdcall
option casemap:none
include book1.inc
include msvcrt.inc
includelib msvcrt.lib
include kernel32.inc
includelib kernel32.lib
.const
g_szAddStr BYTE 'please add information',0ah,0dh,0
g_szOK BYTE 'delete succes',0ah,0dh,0
g_show_menu db "1. 添加数据", 0dh, 0ah,
"2. 查找数据", 0dh, 0ah,
"3. 修改数据", 0dh, 0ah,
"4. 删除数据", 0dh, 0ah,
"5. 显示数据", 0dh, 0ah,
"请输入选项: ", 0
g_AddStrInfo BYTE 'boy,input name and number please',0ah,0dh,0
g_FindStrInfo BYTE 'boy,input name what you will find',0ah,0dh,0
g_ModifyStrInfo BYTE 'boy,input name what you will modify',0ah,0dh,0
g_DeleteStrInfo BYTE 'boy,input name what you will delete',0ah,0dh,0
g_ShowStrInfo BYTE 'boy,this is all infomation',0ah,0dh,0
g_AddStr BYTE 'boy,you add sucess',0ah,0dh,0
g_FindStr BYTE 'boy,you find sucess',0ah,0dh,0
g_ModifyStr BYTE 'boy,you modify sucess',0ah,0dh,0
g_DeleteStr BYTE 'boy,you delete sucess',0ah,0dh,0
g_ShowStr BYTE 'boy,you find all infomation success',0ah,0dh,0
g_enter BYTE ' ',0ah,0dh,0
.code
ADD_USER proc
push eax
push ebx ;下面是用到该寄存器,先保存一下原来寄存器中的值
lea eax,g_szAddStr ;lea表示取第二个操作数的地址,放入第一个操作数中
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;调用函数
;1.通过push给函数传参(4字节)
;2.调用函数 这个调用c语言的库函数,所以要包含头文件
;include msvcrt.inc
;includelib msvcrt.lib
;库函数的格式为:crt_xxx
;3.c库函数的是由调用者平衡堆栈
;每个参数的大小为4字节,所以传入几个参数则在之后esp加回来
;add esp,[参数个数*4]
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
push eax ;push r/m32(imm32)可以是寄存器或内存或立即数
call crt_printf
add esp,4
;根据ecx的值找到下一个结构体名字数组的地址
lea esi,[g_stContacts] ;保存数据的结构体数组
mov ecx,g_nCount ;获取当前以插入的用户个数
mov eax,sizeof(CONTACTSSTRUCT) ;计算结构体大小(sizeof宏)
imul eax,ecx
add esi,eax
imul eax,ecx
lea eax,[esi+CONTACTSSTRUCT.szPhNumber]
lea edx,[esi+CONTACTSSTRUCT.szName]
push eax
push edx
push offset g_szScanfFormat
call crt_scanf
add esp,12
inc g_nCount
pop eax
pop ebx
ret
ADD_USER endp
;scanf("%s",&g_strTemContacts.szName);
;for(int i=0;i<g_nCount)
;{
;if(strcmp(g_strTemContacts.szName,g_stContacts[i].szName)==0)
;{
;printf("%s",g_strTemContacts.szName);
;printf("%d",g_stContacts[i].szPhNumber);
;break;
;}
;}
;
FindData proc
;1.输入数据
lea edi,[g_strTemContacts.szName]
push edi
push offset g_szScanName
call crt_scanf
add esp,8
;2.开始查询
mov ecx,0
CYCLE_MARK:
cmp ecx,g_nCount
jl _JIXU
ret
;2.1根据ecx的值找到下一个结构体名字数组的地址
_JIXU: lea esi,[g_stContacts]
lea edi,[g_strTemContacts.szName]
mov eax,sizeof(CONTACTSSTRUCT)
imul eax,ecx
add esi,eax
;2.2比较字符串
mov eax,ecx
mov ecx,6
repe cmpsd dword ptr[esi],dword ptr[edi]
je CARRIEDOUT_MAR
mov ecx,eax
inc ecx
jmp CYCLE_MARK
CARRIEDOUT_MAR:
;输出信息
mov ecx,eax
lea esi,[g_stContacts]
mov ebx,sizeof(CONTACTSSTRUCT)
imul ebx,ecx
add esi,ebx
lea eax,[esi+CONTACTSSTRUCT.szPhNumber]
push eax
push offset g_szScanName
call crt_printf
add esp,8
ret
FindData endp
;scanf("%s",&g_strTemContacts.szName);
;for(int i=0;i<g_nCount)
;{
;if(strcmp(g_strTemContacts.szName,g_stContacts[i].szName)==0)
;{
;scanf("%s",g_stContacts[i].szName);
;scanf("%d",g_stContacts[i].szPhNumber);
;break;
;}
;}
;
ModifyData proc
;因为修改信息的第一步也是先要将当前输入的信息在已保存的数组中查询
;1。输入数据
lea edi,[g_strTemContacts.szName]
push edi
push offset g_szScanName
call crt_scanf
add esp,8
;2.开始查询
mov ecx,0
CYCLE_MARK:
cmp ecx,g_nCount
jl _JIXU
ret
;2.1根据ecx的值找到下一个结构体名字数组的地址
_JIXU: lea esi,[g_stContacts]
lea edi,[g_strTemContacts.szName]
mov eax,sizeof(CONTACTSSTRUCT)
imul eax,ecx
add esi,eax
;2.2比较字符串
mov eax,ecx
mov ecx,6
repe cmpsd dword ptr[esi],dword ptr[edi]
je CARRIEDOUT_MARK
mov ecx,eax
inc ecx
jmp CYCLE_MARK
CARRIEDOUT_MARK:
;修改信息
mov ecx,eax
lea esi,[g_stContacts]
mov ebx,sizeof(CONTACTSSTRUCT)
imul ebx,ecx
add esi,ebx
lea ebx,[esi+CONTACTSSTRUCT.szName]
lea eax,[esi+CONTACTSSTRUCT.szPhNumber]
push eax
push ebx
push offset g_szScanfFormat
call crt_scanf
add esp,0ch
ret
ModifyData endp
;scanf("%s",&g_strTemContacts.szName);
;for(int i=0;i<g_nCount-1)
;{
;if(strcmp(g_strTemContacts.szName,g_stContacts[i].szName)==0)
;{
;g_stContacts[i].szName=g_stContacts[i+1].szName
;g_stContacts[i].szPhNumber=g_stContacts[i+1].szPhNumber
;g_stContacts[g_nCount-1].szName=0
;g_stContacts[g_nCount-1].szPhNumber=0
;break;
;}
;}
;
RemoveData proc
;1输入数据
lea edi,[g_strTemContacts.szName]
push edi
push offset g_szScanName
call crt_scanf
add esp,8
;2.开始查询
mov ecx,0
CYCLE_MARK:
cmp ecx,g_nCount
jl _JIXU
ret
;2.1.根据ecx的值找到下一个结构体名字数组的地址
_JIXU: lea esi,[g_stContacts]
lea edi,[g_strTemContacts.szName]
mov eax,sizeof(CONTACTSSTRUCT)
imul eax,ecx
add esi,eax
;2.2.比较字符串
mov eax,ecx
mov ecx,6
repe cmpsd dword ptr[esi],dword ptr [edi]
je CARRIEDOUT_MARK
mov ecx,eax
inc ecx
jmp CYCLE_MARK
CARRIEDOUT_MARK:
;删除
;将esi设置为当前要删除的结构体数组的首地址
mov ecx,eax
lea edi,[g_stContacts]
mov ebx,sizeof(CONTACTSSTRUCT)
imul ebx,ecx
add edi,ebx
mov esi,edi
mov ebx,sizeof(CONTACTSSTRUCT)
add esi,ebx
add ecx,1
mov eax,g_nCount
sub eax,ecx
mov ebx,sizeof(CONTACTSSTRUCT)
imul ebx,eax
mov ecx,ebx
rep movs BYTE ptr[edi],BYTE ptr[esi]
mov ebx,sizeof(CONTACTSSTRUCT)
push ebx
push 0
push edi
call crt_memset
add esp,12
dec g_nCount
push offset g_szOK
call crt_printf
add esp,4
push 2000
call Sleep
ret
RemoveData endp
ShowData proc
mov ecx,0
_LOOP: lea esi,[g_stContacts]
mov ebx,sizeof(CONTACTSSTRUCT)
imul ebx,ecx
add esi,ebx
push ecx
lea edx,[esi+CONTACTSSTRUCT.szPhNumber]
push edx
lea eax,[esi+CONTACTSSTRUCT.szName]
push eax
push offset g_szScanfFormat
call crt_printf
add esp,0ch
pop ecx
push ecx
push offset g_enter
call crt_printf
add esp,4
pop ecx
inc ecx
cmp ecx,g_nCount
jl _LOOP
ret
ShowData endp
PrintMenu proc
push offset g_show_menu
call crt_printf
add esp,4
ret
PrintMenu endp
entry:
BEGINTO:
call PrintMenu
lea eax, g_nSelect
;mov eax,0
;push offset g_nSelect
push eax
push offset g_szSelectFormat
call crt_scanf
add esp, 8
cmp g_nSelect,1
jne CHOOSE2
jmp CHOOSE1
CHOOSE1:
call ADD_USER
jmp BEGINTO
CHOOSE2:
cmp g_nSelect,2
jne CHOOSE3
call FindData
jmp BEGINTO
CHOOSE3:
cmp g_nSelect,3
jne CHOOSE4
call ModifyData
jmp BEGINTO
CHOOSE4:
cmp g_nSelect,4
jne CHOOSE5
call RemoveData
jmp BEGINTO
CHOOSE5:
cmp g_nSelect,5
jne _END
call ShowData
jmp BEGINTO
_END:
ret
end entry