鱼C论坛

 找回密码
 立即注册
查看: 3028|回复: 0

[汇编作业] 课程设计一

[复制链接]
发表于 2017-12-19 21:47:06 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 90182si 于 2017-12-19 21:51 编辑

QQ截图20171219214538.jpg

  1. assume cs:code,ds:data
  2. data segment
  3.     db '1975','1976','1977','1978','1979','1980','1981','1982','1983','1984'
  4.     db '1985','1986','1987','1988','1989','1990','1991','1992','1993','1994'
  5.     db '1995'
  6.     dd 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514,345980
  7.     dd 590827,803530,1183000,1843000,2759000,3753000,4649000,5937000
  8.     dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226,11542,14430,15257,17800
  9.         db 30 dup(0);临时数据段
  10. data ends
  11. code segment       
  12. start:
  13.         mov ax,data    ;思路:将年份,收入,员工数,平均数依次入栈,再依次保存到临时数据段,
  14.         mov ds,ax           ;最后从数据段中出来到0b800h显存区,就这样循环21次
  15.         mov bx,0
  16.         mov si,0
  17.         mov di,0d2h    ;临时数据段地址84+84+42=210=d2h
  18.         mov dh,4           ;从第四=五行显示
  19.         mov cx,21
  20. mains:
  21.         push cx
  22.         push bx
  23.         push di
  24.         push si       
  25.         push dx       
  26.         mov ax,[bx]
  27.         mov [di],ax
  28.         mov ax,[bx+2]
  29.         mov [di+2],ax        ;年份       
  30.         mov ax,[bx+84]
  31.         mov dx,[bx+86]  ;每次加4字节
  32.         add di,5        ;di+5,因为年份占4字节外加一个0,共5个字节
  33.         call dtoc                 ;收入       
  34.         mov cx,[si+168] ;因为dw只占2个字节,bx每次+4,si每次+2,因此不能用bx代替si,有很多朋友这出现过问题
  35.         call divdw
  36.         mov dx,0
  37.         add di,16                ;先将平均数保存
  38.         call dtoc                 ;平均数       
  39.         sub di,8                ;再保存员工数
  40.         mov ax,[si+168]
  41.         call dtoc                ;员工数
  42. show:
  43.         pop dx                        ;行
  44.         mov dl,8                ;列
  45.         mov cl,66            ;颜色
  46.         mov si,0d2h                ;从0d2h
  47.         call show_str   ;显示年份
  48.         add si,5
  49.         add dl,10                ;列+10,间隔,可以自行修改
  50.         call show_str   ;显示收入
  51.         add si,8
  52.         add dl,10
  53.         call show_str   ;显示员工数
  54.         add si,8
  55.         add dl,10
  56.         call show_str   ;显示平均数
  57.         pop si
  58.         pop di
  59.         pop bx
  60.         add si,2
  61.         add bx,4
  62.         inc dh          ;下一行
  63.         pop cx
  64.         loop mains
  65.         mov ax,4c00h
  66.         int 21h       
  67. show_str:             ;以下三个小程序可以直接拿来用,这里不作解释
  68.         push si
  69.         mov ax,0b800h;(ax,dx,si,di)
  70.         mov es,ax    ;
  71.         mov al,160   ;
  72.         mul dh       ;
  73.         mov di,ax    ;
  74.         mov al,2     ;
  75.         mul dl       ;
  76.         add di,ax    ;       
  77. next:
  78.         mov al,[si]
  79.         cmp al,0
  80.         je endret
  81.         mov es:[di],al
  82.         mov es:[di+1],cl
  83.         inc si
  84.         add di,2
  85.         jmp next
  86. endret:
  87.         pop si
  88.         ret       
  89. dtoc:
  90.         push ax
  91.         push dx
  92.         push cx
  93.         push si
  94.         push di
  95.         mov si,0       
  96. tw: mov cx,ax       
  97.         jcxz ok
  98.         mov cx,10
  99.         call divdw               
  100.         add cx,48
  101.         push cx       
  102.         inc si
  103.         jmp tw
  104. ok: mov cx,si
  105. of: pop ax
  106.         mov [di],ax
  107.         inc di
  108.         loop of
  109.         pop di
  110.         pop si
  111.         pop cx
  112.         pop dx
  113.         pop ax
  114.         ret
  115. divdw:
  116.         push bx;(ax,dx,cx)
  117.         push ax
  118.         mov ax,dx
  119.         mov dx,0
  120.         div cx
  121.         mov bx,ax
  122.         pop ax
  123.         div cx
  124.         mov cx,dx
  125.         mov dx,bx
  126.         pop bx
  127.         ret
  128. code ends
  129. end start
复制代码


想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-25 23:31

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表