王爽汇编实验7 解答

ASSUME    CS:codesg,DS:data,es:table,ss:stack

data          SEGMENT
              DB        '1975','1976','1977','1978','1979','1980','1981','1982','1983'
              DB        '1984','1985','1986','1987','1988','1989','1990','1991','1992'
              DB        '1993','1994','1995'
              ;以上是表示21年的21个字符串
             
              DD        16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514
              DD        345980,590827,803530,1183000,1843000,2759000,3753000,4649000,5937000
              ;以上是表示21年公司总收入的21个dword型数据
             
              DW        3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226
              DW        11542,14430,15257,17800
              ;以上是表示21年公司雇员人数的21个word型数据
data          ENDS

table         SEGMENT
              DB       21  DUP ('year summ ne ?? ')
table         ENDS

stack         SEGMENT
              DW       0,0
stack         ENDS
     
codesg SEGMENT
       start: mov ax,data
              mov ds,ax
              mov ax,table
              mov es,ax
              mov ax,stack
              mov ss,ax
              mov sp,4             ;指向栈底
             
              mov bx,0             ;内存逐个读取
              mov si,0             ;table段换行,间隔16
              mov cx,21            ;外层循环计数
          s0: push cx
             
              mov bp,0
              mov cx,4             ;内层循环计数
          s1: mov al,ds:0[bx]
              mov es:[si][bp],al         ;记录年份
             
              mov al,ds:84[bx]
              mov es:[si].5[bp],al       ;记录收入
             
              inc bx                     ;bx累加4次后si累加一次,4*21次循环
              inc bp
              loop s1
             
              pop cx
              add si,16
              loop s0                    ;记录完所有年份和收入
            
              mov bx,0             ;内存逐个读取
              mov si,0             ;table段换行,间隔16
              mov cx,21            ;外层循环计数
          r0: push cx
             
              mov bp,0
              mov cx,2             ;内层循环计数
          r1: mov al,ds:168[bx]
              mov es:[si].10[bp],al      ;记录人员
             
              inc bx
              inc bp
              loop r1                    ;bx累加2次后si累加一次,2*21次循环
             
              add si,16
              pop cx
              loop r0                    ;记录完所有人员
             
              mov bx,0
              mov di,0
              mov si,0
              mov cx,21
          sr: mov ax,ds:84[bx]
              add bx,2
              mov dx,ds:84[bx]           ;将收入储存到DX和AX寄存器中
              div word ptr ds:168[di]    ;读取内存中人员数量作为除数
              mov es:[si+13],ax          ;将人均收入(取整)存入到内存中

              add di,2
              add si,16
              loop sr

              MOV       AX,4c00h
              INT       21h
codesg ENDS

END       start

你可能感兴趣的:(c,汇编,table,div)