1. .386
    2. .model flat,stdcall
    3. option casemap:none
    4. include book1.inc
    5. include msvcrt.inc
    6. includelib msvcrt.lib
    7. include kernel32.inc
    8. includelib kernel32.lib
    9. .const
    10. g_szAddStr BYTE 'please add information',0ah,0dh,0
    11. g_szOK BYTE 'delete succes',0ah,0dh,0
    12. g_show_menu db "1. 添加数据", 0dh, 0ah,
    13. "2. 查找数据", 0dh, 0ah,
    14. "3. 修改数据", 0dh, 0ah,
    15. "4. 删除数据", 0dh, 0ah,
    16. "5. 显示数据", 0dh, 0ah,
    17. "请输入选项: ", 0
    18. g_AddStrInfo BYTE 'boy,input name and number please',0ah,0dh,0
    19. g_FindStrInfo BYTE 'boy,input name what you will find',0ah,0dh,0
    20. g_ModifyStrInfo BYTE 'boy,input name what you will modify',0ah,0dh,0
    21. g_DeleteStrInfo BYTE 'boy,input name what you will delete',0ah,0dh,0
    22. g_ShowStrInfo BYTE 'boy,this is all infomation',0ah,0dh,0
    23. g_AddStr BYTE 'boy,you add sucess',0ah,0dh,0
    24. g_FindStr BYTE 'boy,you find sucess',0ah,0dh,0
    25. g_ModifyStr BYTE 'boy,you modify sucess',0ah,0dh,0
    26. g_DeleteStr BYTE 'boy,you delete sucess',0ah,0dh,0
    27. g_ShowStr BYTE 'boy,you find all infomation success',0ah,0dh,0
    28. g_enter BYTE ' ',0ah,0dh,0
    29. .code
    30. ADD_USER proc
    31. push eax
    32. push ebx ;下面是用到该寄存器,先保存一下原来寄存器中的值
    33. lea eax,g_szAddStr ;lea表示取第二个操作数的地址,放入第一个操作数中
    34. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    35. ;调用函数
    36. ;1.通过push给函数传参(4字节)
    37. ;2.调用函数 这个调用c语言的库函数,所以要包含头文件
    38. ;include msvcrt.inc
    39. ;includelib msvcrt.lib
    40. ;库函数的格式为:crt_xxx
    41. ;3.c库函数的是由调用者平衡堆栈
    42. ;每个参数的大小为4字节,所以传入几个参数则在之后esp加回来
    43. ;add esp,[参数个数*4]
    44. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    45. push eax ;push r/m32imm32)可以是寄存器或内存或立即数
    46. call crt_printf
    47. add esp,4
    48. ;根据ecx的值找到下一个结构体名字数组的地址
    49. lea esi,[g_stContacts] ;保存数据的结构体数组
    50. mov ecx,g_nCount ;获取当前以插入的用户个数
    51. mov eax,sizeof(CONTACTSSTRUCT) ;计算结构体大小(sizeof宏)
    52. imul eax,ecx
    53. add esi,eax
    54. imul eax,ecx
    55. lea eax,[esi+CONTACTSSTRUCT.szPhNumber]
    56. lea edx,[esi+CONTACTSSTRUCT.szName]
    57. push eax
    58. push edx
    59. push offset g_szScanfFormat
    60. call crt_scanf
    61. add esp,12
    62. inc g_nCount
    63. pop eax
    64. pop ebx
    65. ret
    66. ADD_USER endp
    67. ;scanf("%s",&g_strTemContacts.szName);
    68. ;for(int i=0;i<g_nCount)
    69. ;{
    70. ;if(strcmp(g_strTemContacts.szName,g_stContacts[i].szName)==0)
    71. ;{
    72. ;printf("%s",g_strTemContacts.szName);
    73. ;printf("%d",g_stContacts[i].szPhNumber);
    74. ;break;
    75. ;}
    76. ;}
    77. ;
    78. FindData proc
    79. ;1.输入数据
    80. lea edi,[g_strTemContacts.szName]
    81. push edi
    82. push offset g_szScanName
    83. call crt_scanf
    84. add esp,8
    85. ;2.开始查询
    86. mov ecx,0
    87. CYCLE_MARK:
    88. cmp ecx,g_nCount
    89. jl _JIXU
    90. ret
    91. ;2.1根据ecx的值找到下一个结构体名字数组的地址
    92. _JIXU: lea esi,[g_stContacts]
    93. lea edi,[g_strTemContacts.szName]
    94. mov eax,sizeof(CONTACTSSTRUCT)
    95. imul eax,ecx
    96. add esi,eax
    97. ;2.2比较字符串
    98. mov eax,ecx
    99. mov ecx,6
    100. repe cmpsd dword ptr[esi],dword ptr[edi]
    101. je CARRIEDOUT_MAR
    102. mov ecx,eax
    103. inc ecx
    104. jmp CYCLE_MARK
    105. CARRIEDOUT_MAR:
    106. ;输出信息
    107. mov ecx,eax
    108. lea esi,[g_stContacts]
    109. mov ebx,sizeof(CONTACTSSTRUCT)
    110. imul ebx,ecx
    111. add esi,ebx
    112. lea eax,[esi+CONTACTSSTRUCT.szPhNumber]
    113. push eax
    114. push offset g_szScanName
    115. call crt_printf
    116. add esp,8
    117. ret
    118. FindData endp
    119. ;scanf("%s",&g_strTemContacts.szName);
    120. ;for(int i=0;i<g_nCount)
    121. ;{
    122. ;if(strcmp(g_strTemContacts.szName,g_stContacts[i].szName)==0)
    123. ;{
    124. ;scanf("%s",g_stContacts[i].szName);
    125. ;scanf("%d",g_stContacts[i].szPhNumber);
    126. ;break;
    127. ;}
    128. ;}
    129. ;
    130. ModifyData proc
    131. ;因为修改信息的第一步也是先要将当前输入的信息在已保存的数组中查询
    132. ;1。输入数据
    133. lea edi,[g_strTemContacts.szName]
    134. push edi
    135. push offset g_szScanName
    136. call crt_scanf
    137. add esp,8
    138. ;2.开始查询
    139. mov ecx,0
    140. CYCLE_MARK:
    141. cmp ecx,g_nCount
    142. jl _JIXU
    143. ret
    144. ;2.1根据ecx的值找到下一个结构体名字数组的地址
    145. _JIXU: lea esi,[g_stContacts]
    146. lea edi,[g_strTemContacts.szName]
    147. mov eax,sizeof(CONTACTSSTRUCT)
    148. imul eax,ecx
    149. add esi,eax
    150. ;2.2比较字符串
    151. mov eax,ecx
    152. mov ecx,6
    153. repe cmpsd dword ptr[esi],dword ptr[edi]
    154. je CARRIEDOUT_MARK
    155. mov ecx,eax
    156. inc ecx
    157. jmp CYCLE_MARK
    158. CARRIEDOUT_MARK:
    159. ;修改信息
    160. mov ecx,eax
    161. lea esi,[g_stContacts]
    162. mov ebx,sizeof(CONTACTSSTRUCT)
    163. imul ebx,ecx
    164. add esi,ebx
    165. lea ebx,[esi+CONTACTSSTRUCT.szName]
    166. lea eax,[esi+CONTACTSSTRUCT.szPhNumber]
    167. push eax
    168. push ebx
    169. push offset g_szScanfFormat
    170. call crt_scanf
    171. add esp,0ch
    172. ret
    173. ModifyData endp
    174. ;scanf("%s",&g_strTemContacts.szName);
    175. ;for(int i=0;i<g_nCount-1)
    176. ;{
    177. ;if(strcmp(g_strTemContacts.szName,g_stContacts[i].szName)==0)
    178. ;{
    179. ;g_stContacts[i].szName=g_stContacts[i+1].szName
    180. ;g_stContacts[i].szPhNumber=g_stContacts[i+1].szPhNumber
    181. ;g_stContacts[g_nCount-1].szName=0
    182. ;g_stContacts[g_nCount-1].szPhNumber=0
    183. ;break;
    184. ;}
    185. ;}
    186. ;
    187. RemoveData proc
    188. ;1输入数据
    189. lea edi,[g_strTemContacts.szName]
    190. push edi
    191. push offset g_szScanName
    192. call crt_scanf
    193. add esp,8
    194. ;2.开始查询
    195. mov ecx,0
    196. CYCLE_MARK:
    197. cmp ecx,g_nCount
    198. jl _JIXU
    199. ret
    200. ;2.1.根据ecx的值找到下一个结构体名字数组的地址
    201. _JIXU: lea esi,[g_stContacts]
    202. lea edi,[g_strTemContacts.szName]
    203. mov eax,sizeof(CONTACTSSTRUCT)
    204. imul eax,ecx
    205. add esi,eax
    206. ;2.2.比较字符串
    207. mov eax,ecx
    208. mov ecx,6
    209. repe cmpsd dword ptr[esi],dword ptr [edi]
    210. je CARRIEDOUT_MARK
    211. mov ecx,eax
    212. inc ecx
    213. jmp CYCLE_MARK
    214. CARRIEDOUT_MARK:
    215. ;删除
    216. ;将esi设置为当前要删除的结构体数组的首地址
    217. mov ecx,eax
    218. lea edi,[g_stContacts]
    219. mov ebx,sizeof(CONTACTSSTRUCT)
    220. imul ebx,ecx
    221. add edi,ebx
    222. mov esi,edi
    223. mov ebx,sizeof(CONTACTSSTRUCT)
    224. add esi,ebx
    225. add ecx,1
    226. mov eax,g_nCount
    227. sub eax,ecx
    228. mov ebx,sizeof(CONTACTSSTRUCT)
    229. imul ebx,eax
    230. mov ecx,ebx
    231. rep movs BYTE ptr[edi],BYTE ptr[esi]
    232. mov ebx,sizeof(CONTACTSSTRUCT)
    233. push ebx
    234. push 0
    235. push edi
    236. call crt_memset
    237. add esp,12
    238. dec g_nCount
    239. push offset g_szOK
    240. call crt_printf
    241. add esp,4
    242. push 2000
    243. call Sleep
    244. ret
    245. RemoveData endp
    246. ShowData proc
    247. mov ecx,0
    248. _LOOP: lea esi,[g_stContacts]
    249. mov ebx,sizeof(CONTACTSSTRUCT)
    250. imul ebx,ecx
    251. add esi,ebx
    252. push ecx
    253. lea edx,[esi+CONTACTSSTRUCT.szPhNumber]
    254. push edx
    255. lea eax,[esi+CONTACTSSTRUCT.szName]
    256. push eax
    257. push offset g_szScanfFormat
    258. call crt_printf
    259. add esp,0ch
    260. pop ecx
    261. push ecx
    262. push offset g_enter
    263. call crt_printf
    264. add esp,4
    265. pop ecx
    266. inc ecx
    267. cmp ecx,g_nCount
    268. jl _LOOP
    269. ret
    270. ShowData endp
    271. PrintMenu proc
    272. push offset g_show_menu
    273. call crt_printf
    274. add esp,4
    275. ret
    276. PrintMenu endp
    277. entry:
    278. BEGINTO:
    279. call PrintMenu
    280. lea eax, g_nSelect
    281. ;mov eax,0
    282. ;push offset g_nSelect
    283. push eax
    284. push offset g_szSelectFormat
    285. call crt_scanf
    286. add esp, 8
    287. cmp g_nSelect,1
    288. jne CHOOSE2
    289. jmp CHOOSE1
    290. CHOOSE1:
    291. call ADD_USER
    292. jmp BEGINTO
    293. CHOOSE2:
    294. cmp g_nSelect,2
    295. jne CHOOSE3
    296. call FindData
    297. jmp BEGINTO
    298. CHOOSE3:
    299. cmp g_nSelect,3
    300. jne CHOOSE4
    301. call ModifyData
    302. jmp BEGINTO
    303. CHOOSE4:
    304. cmp g_nSelect,4
    305. jne CHOOSE5
    306. call RemoveData
    307. jmp BEGINTO
    308. CHOOSE5:
    309. cmp g_nSelect,5
    310. jne _END
    311. call ShowData
    312. jmp BEGINTO
    313. _END:
    314. ret
    315. end entry