王爽老师《汇编语言》课程设计2

时间:2021-07-09 01:13:29

assume cs:code

 

data1 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'

 

        dd 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514

        dd 345980,590827,803530,1183000,1843000,2759000,3753000,4549000,5937000

 

        dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226

        dw 11542,14430,15257,17800

data1 ends

 

;段地址:es

table segment

        db 21 dup ('year summ ne ?? ')

table ends

 

;要显示的字符串,属性。段地址:ds,对应的显存es,

data2 segment

        dw 10

        dd 0,0,0

        dw 0

        db 08H,03H,02H               ;存放属性:行,列,颜色等等

data2 ends

 

 

code segment

 

;将数据写到table表中

start:

        mov ax,data1

        mov ds,ax

 

        mov ax,table

        mov es,ax

 

        mov cx,15H

        mov si,0

        mov di,0

     s:

        push cx

        mov cx,4

        mov bx,0

     s0:

        mov al,ds:[di]

        mov es:[bx + si],al

        inc bx

        inc di

        loop s0

 

        add si,10H

        pop cx

        loop s

 

        mov cx,15H

        mov bx,5H

 

     s1:

        mov ax,ds:[di]

        mov dx,ds:[di + 2]

        mov word ptr es:[bx],ax

        mov word ptr es:[bx + 2],dx

 

        add di,4

        add bx,10H

        loop s1

 

        mov cx,15H

        mov bx,0AH

     s2:

        mov ax,ds:[di]

        mov word ptr es:[bx],ax

        add bx,10H

        inc di

        inc di

        loop s2

 

        mov cx,15H

        mov bx,5H

     s3:

        mov ax,es:[bx]

        mov dx,es:[bx + 2]

        div word ptr es:[bx + 5]

        mov word ptr es:[bx + 8],ax

        add bx,10H

        loop s3

       

;写到了table表中     

 

;输出年份。

              push es

          mov ax,data2

          mov ds,ax

     

          mov al,2

          mov byte ptr ds:[10H],al

          mov al,2

          mov byte ptr ds:[11],al         ;初始化行列的开始位置

         

          mov bx,0

         

        mov cx,21

       

     s4:push cx

          mov cx,4

          mov si,0

     s5:mov al,es:[bx + si]

          mov ds:[si +2],al

          inc si

          loop s5             ;一个字符串传递完毕。

          push es

          push bx

          mov si,2

          call show_str       ;调用show_str函数

         

          mov al,ds:[10H]

          inc al

          mov byte ptr ds:[10H],al

     

          pop bx

          pop es

          pop cx

         

          add bx,10H

          loop s4

          pop es                           ;到此为止,年份输出完毕。恢复es 指向 table段

         

         

         

         

          ;接下来显示总收入

         

          mov al,2

          mov byte ptr ds:[10H],al

          mov al,10                               ;从第10列开始显示

          mov byte ptr ds:[11H],al                 ;初始化行列的开始位置

          mov bx,0H

          mov si,0EH

         

          mov cx,21

     s6:

        push cx

          mov ax,word ptr es:[bx + 5]

          mov ds:[2],ax

          mov ax,word ptr es:[bx + 7]

          mov ds:[4],ax                           ;将 总收入传递过来

          push es

          push bx

          call divdw                              ;调用生成字符串函数

          call show_str

          pop bx

          add bx,10H

          mov al,byte ptr ds:[10H]

          inc al                                

          mov byte ptr ds:[10H],al                ;指向下一行

         

          pop es

          pop cx

          loop s6

                                         ;总收入显示完毕

                                        

                                        

                                        

                                        

        ;下面显示雇佣人员

       

          mov al,2

          mov byte ptr ds:[10H],al

          mov al,20                               ;从第20列开始显示

          mov byte ptr ds:[11H],al                 ;初始化行列的开始位置

          mov bx,0H

          mov si,0EH

         

          mov cx,21

     s7:

        push cx

          mov ax,word ptr es:[bx + 10]

          mov ds:[2],ax

          mov word ptr ds:[4],0                           ;将 人数传递过来

          push es

          push bx

          call divdw                              ;调用生成字符串函数

          call show_str

          pop bx

          add bx,10H

          mov al,byte ptr ds:[10H]

          inc al                                

          mov byte ptr ds:[10H],al                ;指向下一行

         

          pop es

          pop cx

          loop s7

                                         ;雇员人数显示完毕

                                        

        ;下面显示人均收入

        mov al,2

          mov byte ptr ds:[10H],al

          mov al,30                              ;从第20列开始显示

          mov byte ptr ds:[11H],al                 ;初始化行列的开始位置

          mov bx,0H

          mov si,0EH

         

          mov cx,21

     s8:

        push cx

          mov ax,word ptr es:[bx + 13]

          mov ds:[2],ax

          mov word ptr ds:[4],0                       ;将 人数传递过来

          push es

          push bx

          call divdw                              ;调用生成字符串函数

          call show_str

          pop bx

          add bx,10H

          mov al,byte ptr ds:[10H]

          inc al                                

          mov byte ptr ds:[10H],al                ;指向下一行

         

          pop es

          pop cx

          loop s8

                     

         

        mov ax,4c00H

        int 21H

divdw:     

        dec si 

        mov ax,word ptr ds:[4]

        mov dx,0

        div word ptr ds:[0]

        push ax

        mov ax,word ptr ds:[2]

        div word ptr ds:[0]

        mov cx,dx

        add dl,30H

        mov ds:[si],dl

        pop dx

        mov cx,ax

        mov word ptr ds:[2],ax

        mov word ptr ds:[4],dx

       

        jcxz ok1

        jmp short divdw

  ok1:  ret

   

 show_str:

 

        mov ax,0aH

        mul byte ptr ds:[10H]

        add ax,0B800H

        mov es,ax

        mov bl,ds:[11H]

        dec bl

        add bl,bl

        mov bh,0

 print:

        mov cl,ds:[si]

        mov ch,0

        jcxz ok

        mov byte ptr es:[bx],cl

        mov cl,ds:[12H]

        mov byte ptr es:[bx + 1],cl

        inc bx

        inc bx

        inc si

        jmp print

    ok: ret

code ends

end start