鸿 网 互 联 www.68idc.cn

王爽<汇编语言> 课程设计1

来源:互联网 作者:佚名 时间:2015-08-13 07:39
assume cs:codesg,ds:datasg,ss:stacksg datasg segment db 2h ;绿色 ;0h db 24h ;绿底红色 ;1h db 71h ;白底蓝色 ;2h db 'welcome to masm!',0 ;text ;3h db 16 dup(0) ;14h db '1975','1976','1977','1978','1979','1980','1981','1982','1983','1984','19
  1. assume cs:codesg,ds:datasg,ss:stacksg
  2. datasg segment
  3. db 2h ;绿色 ;0h
  4. db 24h ;绿底红色 ;1h
  5. db 71h ;白底蓝色 ;2h
  6. db 'welcome to masm!',0 ;text ;3h
  7. db 16 dup(0) ;14h
  8. db '1975','1976','1977','1978','1979','1980','1981','1982','1983','1984','1985','1986','1987','1988','1989','1990','1991','1992','1993','1994','1995' ;24h
  9. dd 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514,345980,590827,803530,1183000,1843000,2759000,3753000,4649000,5937000 ;78h
  10. dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226,11542,14430,15257,17800 ;0cch
  11. db 64 dup(0) ;字缓冲 ;0f6h
  12. datasg ends
  13. table segment
  14. dd 21 dup (0,0,0,0)
  15. table ends
  16. stacksg segment
  17. dd 16 dup (0)
  18. stacksg ends
  19. codesg segment
  20. ;--------------------------------------------------------showStr-------------------------------------------------------------------------------
  21. showStr:push bp;(byte->height(+9h)_byte->width(+8h),byte_byte->color(+6h),word->text_addr(+4h))(无返回,已恢复栈)
  22. mov bp,sp
  23. push ax
  24. push bx
  25. push cx
  26. push dx
  27. push di
  28. push si
  29. push es
  30. ;计算所在行数
  31. mov al,ss:9h[bp];获取行数
  32. mov bl,160;每行160个字节
  33. mul bl;行数x每行字节数
  34. push ax;保存下结果
  35. ;计算所在列数
  36. mov al,ss:8h[bp];获取列数
  37. mov bl,2h;你懂的...
  38. mul bl;
  39. pop bx
  40. add ax,bx;定位显存位置
  41. mov si,ax;保存一下
  42. ;显示
  43. mov di,0
  44. mov bx,ss:4h[bp]
  45. mov ax,0b800h
  46. mov es,ax
  47. for1:mov cl,ds:[bx][di];循环每个字符,复制到显示缓冲区,并加上色
  48. mov ch,0
  49. jcxz return
  50. mov byte ptr es:[si],cl;复制字符
  51. inc si
  52. mov ch,ss:6h[bp];获取颜色参数
  53. mov byte ptr es:[si],ch;设置颜色
  54. inc si
  55. inc di
  56. loop for1
  57. return:pop ax
  58. mov es,ax
  59. pop si
  60. pop di
  61. pop dx
  62. pop cx
  63. pop bx
  64. pop ax
  65. pop bp
  66. ret 6h
  67. ;--------------------------------------------------------showStr-------------------------------------------------------------------------------
  68. ;--------------------------------------------------------divdw---------------------------------------------------------------------------------
  69. divdw:push bp;(word->dividl(+8h),word->dividh(+6h),word->divish(+4h))(有返回(pop(+4h余),pop(+6h结果高位),pop(+8h结果低位)),自行恢复栈)
  70. mov bp,sp
  71. push ax
  72. push bx
  73. push cx
  74. push dx
  75. mov dx,0
  76. mov ax,ss:6h[bp]
  77. div word ptr ss:4h[bp]
  78. mov word ptr ss:6h[bp],ax;32位结果的高位
  79. mov ax,word ptr ss:8h[bp]
  80. div word ptr ss:4h[bp];欧几里德同余公式,被搞死...郁闷
  81. mov word ptr ss:8h[bp],ax;32位结果的底位
  82. mov word ptr ss:4h[bp],dx;32位结果的余
  83. pop dx
  84. pop cx
  85. pop bx
  86. pop ax
  87. pop bp
  88. ret
  89. ;--------------------------------------------------------divdw---------------------------------------------------------------------------------
  90. ;--------------------------------------------------------dtoc----------------------------------------------------------------------------------
  91. dtoc:push bp;(word->numl(+8h),word->numh(+6h),word->txt_addr(+4h))(无返回,已恢复栈)
  92. mov bp,sp
  93. push di
  94. push ax
  95. push dx
  96. push bx
  97. push cx
  98. push si
  99. mov si,0;转换计数
  100. mov di,ss:4h[bp];获取存放字符串的地址
  101. mov ax,ss:8h[bp];获取被除数低位
  102. push ax
  103. mov ax,ss:6h[bp];获取被除数高位
  104. push ax
  105. mov ax,10;设置除数
  106. push ax
  107. call divdw
  108. pop cx
  109. pop dx
  110. pop ax
  111. jmp dtoc_go
  112. dtoc_to:push ax
  113. push dx
  114. mov ax,10
  115. push ax
  116. call divdw
  117. pop cx
  118. pop dx
  119. pop ax
  120. dtoc_go:add cx,30h;数字转字符
  121. push cx;保存结果
  122. inc si
  123. mov cx,ax;先检查结果的低位等不等于0
  124. jcxz dtoc_ch;如果等于转到dtoc_ch检查高位
  125. jmp dtoc_to;否则继续转换
  126. dtoc_ch:mov cx,dx;检查高位等不等于0
  127. jcxz dtoc_fl;高位和低位都为0,除完...你懂的
  128. jmp dtoc_to;不用看了,继续转吧...
  129. dtoc_fl:mov cx,si
  130. jcxz dtoc_f
  131. dtoc_l1:pop ax
  132. mov ds:[di],al;设置正确结果
  133. inc di
  134. loop dtoc_l1
  135. dtoc_f:pop si
  136. pop cx
  137. pop bx
  138. pop dx
  139. pop ax
  140. pop di
  141. pop bp
  142. ret 6h
  143. ;--------------------------------------------------------dtoc----------------------------------------------------------------------------------
  144. ;--------------------------------------------------------cl_mem--------------------------------------------------------------------------------
  145. cl_mem:push cx;清空下字节缓冲
  146. push si
  147. mov si,0
  148. mov cx,40h
  149. clm_s:mov byte ptr ds:0f6h[si],0h
  150. inc si
  151. loop clm_s
  152. pop si
  153. pop cx
  154. ret
  155. ;--------------------------------------------------------cl_mem--------------------------------------------------------------------------------
  156. start:mov ax,datasg
  157. mov ds,ax
  158. mov ax,stacksg
  159. mov ss,ax
  160. mov sp,40h
  161. mov ax,table
  162. mov es,ax
  163. mov si,0;设置表格
  164. mov di,0
  165. mov cx,21
  166. main_s:mov bx,24h;年份
  167. mov ax,ds:[bx].2[si]
  168. mov dx,ds:[bx][si]
  169. mov es:2[di],ax
  170. mov es:[di],dx
  171. mov bx,78h;收入
  172. mov ax,ds:[bx].2[si]
  173. mov dx,ds:[bx][si]
  174. mov es:[di].7,ax
  175. mov es:[di].5,dx
  176. mov ax,si
  177. mov bl,2
  178. div bl
  179. mov ah,0
  180. mov dx,ax
  181. mov bp,si
  182. mov si,dx
  183. mov bx,0cch;雇员数
  184. mov ax,ds:[bx][si]
  185. mov es:[di].0ah,ax
  186. mov si,bp
  187. mov ax,es:[di].5;人均收入
  188. mov dx,es:[di].7
  189. div word ptr es:[di].0ah
  190. mov es:[di].0dh,ax
  191. add si,4
  192. add di,10h
  193. loop main_s
  194. ;---------------------------------------------------------------------------------------------------------------------------------------
  195. mov di,0
  196. mov si,10
  197. mov bx,10
  198. mov cx,21
  199. main_set:call cl_mem;清空下显示缓冲区
  200. mov ax,es:[di]
  201. mov ds:[0f6h],ax
  202. mov ax,es:[di].2h
  203. mov ds:[0f8h],ax;复制年份到显示到显示缓冲区
  204. mov ah,bl
  205. mov al,20
  206. push ax
  207. mov ah,0
  208. mov al,0fh
  209. push ax
  210. mov ax,0f6h
  211. push ax
  212. call showStr;显示年份
  213. call cl_mem;清空下显示缓冲区
  214. mov ax,es:5h[di]
  215. push ax
  216. mov ax,es:7h[di]
  217. push ax
  218. mov ax,0f6h
  219. push ax
  220. call dtoc
  221. mov ah,bl
  222. mov al,30
  223. push ax
  224. mov ah,0
  225. mov al,0fh
  226. push ax
  227. mov ax,0f6h
  228. push ax
  229. call showStr;显示收入
  230. call cl_mem;清空下显示缓冲区
  231. mov ax,es:0ah[di]
  232. push ax
  233. mov ax,0
  234. push ax
  235. mov ax,0f6h
  236. push ax
  237. call dtoc
  238. mov ah,bl
  239. mov al,40
  240. push ax
  241. mov ah,0
  242. mov al,0fh
  243. push ax
  244. mov ax,0f6h
  245. push ax
  246. call showStr;显示雇员数
  247. call cl_mem;清空下显示缓冲区
  248. mov ax,es:0dh[di]
  249. push ax
  250. mov ax,0
  251. push ax
  252. mov ax,0f6h
  253. push ax
  254. call dtoc
  255. mov ah,bl
  256. mov al,50
  257. push ax
  258. mov ah,0
  259. mov al,0fh
  260. push ax
  261. mov ax,0f6h
  262. push ax
  263. call showStr;显示人均收入
  264. add di,10h
  265. inc bx
  266. dec cx
  267. jcxz game_o
  268. jmp main_set
  269. game_o:mov ax,4c00h
  270. int 21h
  271. codesg ends
  272. end start

网友评论
<