assume cs:codesg
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'
dd 16,22,382,1356,2390,8000,160000,24486,50065,97479,140416,197514
dd 345980,590827,803530,1183000,1843000,2759000,3753000,4649000,5937000
dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226
dw 11542,14430,15257,17800
data ends
table segment
db 21 dup ('year summ ne ?? ')
table ends
ascii segment
db 80 dup (' ') ;最终显示的一行表格占32个字符
ascii ends
stack segment
dd 8 dup(0)
stack ends
codesg segment
start:
mov ax,stack
mov ss,ax
mov sp,32
mov ax,data
mov ds,ax
mov ax,table
mov es,ax
mov bx,0
mov si,0
mov cx,21
year:
mov ax,[bx]
mov es:[si],ax
mov ax,[bx+2]
mov es:[si+2],ax
add si,16
add bx,4
loop year
mov di,0 ;168[di](雇员数)
mov bx,0 ;84[bx] (年收入数据)
mov si,0
mov cx,21
income:
mov ax,168[di]
mov es:[si+0ah],ax
mov ax,84[bx] ;低16位
mov dx,84[bx+2] ;高16位置
mov es:[si+5],ax
mov es:[si+7],dx
div word ptr es:[si+0ah]
mov es:[si+0dh],ax
add si,16
add di,2
add bx,4
loop income
;下面需要把table中的部分数据(es:[bx+5]~es:[bx+9])转换为ASCII
mov bx,0
mov ax,ascii
mov ds,ax
mov bx,0 ;bx指示行
mov cx,21
mov ax,0
push ax ;记录缓存区的行
copyASCII:
mov ax,es:[bx]
mov ds:[0],ax
mov ax,es:[bx+2]
mov ds:[2],ax
mov si,6 ;[bx+6]为收入
mov ax,es:[bx+5]
mov dx,es:[bx+7]
call ChangeToAscii
mov dx,0
mov ax,es:[bx+0ah]
mov si,16
call ChangeToAscii
mov dx,0
mov ax,es:[bx+0dh]
mov si,26
call ChangeToAscii
; ds:si指向的,存储ascii的区域,复制到显示缓存区
pop ax
inc ax
push ax
call showASCII
add bx,10h ;指向tale下一行
loop copyASCII
mov ax,4c00h
int 21h
上面算是“主程序”吧,接下来就是几个函数了
;******下面都是各个函数***********
ChangeToAscii:
;在调用ChangToAscii前,ds:si都是设置好的
push cx
push di
push ax
push dx
push bx
push si
mov di,0
s0:
mov cx,10
call divdw
add cl,30h
mov ch,0
push cx
inc di
mov cx,0
or cx,ax
or cx,dx
jcxz ok
jmp short s0
ok:
mov cx,di
changeS0:
pop bx
mov ds:[si],bl
inc si
loop changeS0
pop si
pop bx
pop dx
pop ax
pop di
pop cx
ret
divdw:
;调用前dx-ax为被除数,cx为除数
;调用后dx-ax为商,cx为余数
push si
push ax
mov ax,dx
mov dx,0
div cx
mov si,ax
pop ax
div cx ;[rem(H/N)*65536+L]/N, ax中为商,dx中为余数
mov cx,dx
mov dx,si
pop si
ret
showASCII:
;ax 表示行
push es
push cx
push bx
push di
push si
push ax
mov ax,ascii
mov ds,ax
mov si,0
mov ax,0b800h
mov es,ax
mov bl,160 ;每行的字节数
pop ax
mul bl ; es:[ax]指向缓存区
mov di,ax
mov cx,80
showS0:
mov bl,ds:[si]
mov es:[di],bl
add si,1
add di,2
loop showS0
pop si
pop di
pop bx
pop cx
pop es
ret
codesg ends
end start
这个课程设计基本包含了好几个前面章节实验的内容了,有空我再详细整理出来~