给出代码中的数据段,将数据段中的数据打印到屏幕上,数据包括年份、收入、雇员数、人均收入(需设计代码求出)
要输出四列数据,而屏幕一行可以显示80个字符,所以我给每列数据分配20列显示列,如上图
在给出的数据段中,除了年份是字符外,其余数据都是整型,无法直接打印在屏幕上,这就需要生成它们对应的字符码
为了打印方便,我先定义了一个table段,并开辟出21*80个内存来存储数据,格式如下:
年份(占20字节) 收入(占20字节) 雇员数(占20字节)平均收入(占19字节)0(1字节)
将求到的数据放入table段,最后一行一行进行打印
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,16000,24486,50065,97479,140417,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 1680 dup (' ')
table ends
codesg segment
start:mov ax,data
mov ds,ax
mov ax,table
mov es,ax
mov si,0
mov di,0
mov cx,21
L1:push cx
mov cx,2
s1:mov ax,[si]
mov es:[di],ax
add si,2
add di,2
loop s1
add di,76 进行下一行年份的输入
pop cx
loop L1
mov cx,21
mov si,21*4
mov di,20
L2: mov ax,[si]
mov dx,[si+2]
call ddtoc
add si,4
add di,80 在table段中转到下一行继续存数据
loop L2
mov cx,21
mov si,21*4+21*4
mov di,40
L3:
mov ax,[si]
call dtoc
add si,2
add di,80
loop L3
mov bx,0
mov cx,21
L4:mov di,60
mov si,84
mov bx,168
s6:push cx
push di
mov ax,[si]
mov dx,[si+2]
div word ptr ds:[bx]
call dtoc
pop di
pop cx
add di,80
add si,4
add bx,2
loop s6
mov cx,21
mov di,79
mov ax,0
s7: mov es:[di],al
add di,80
loop s7
mov dh,2
mov dl,0
mov ax,table
mov ds,ax
mov si,0
mov di,0
mov cx,21
T: push cx
mov dl,0
mov cl,2
call show_str
pop cx
inc si
add dh,1
loop T
mov ax,4c00h
int 21h
ddtoc: push cx ddtoc子程序功能是将dword类型数据变为十进制的字符串
push di
mov bx,0 统计入栈个数
a: mov cx,dx
jcxz b
x: call divdw 调用除法溢出的子程序,求的余数(cx)入栈
push cx
inc bx
jmp short a
b: mov cx,ax
jcxz ok 判断dx和ax同时为0说明,十进制每一位的数据都取到了
jmp short x
ok: mov cx,bx
r: pop ax 将入栈的余数出栈,并加30h变为字符
add ax,30h
mov es:[di],al
inc di
loop r
pop di
pop cx
ret
divdw: push bx 解决除法溢出的子程序
push si
mov cx,10
mov bx,ax
mov ax,dx
mov dx,0
div cx
mov si,ax
mov ax,bx
div cx
mov cx,dx
mov dx,si
pop si
pop bx
ret
dtoc: push bx 将word型数据转变为十进制的字符串
push cx
push di
mov bx,0
mov cx,10
s3: mov dx,0
push cx
mov cx,ax
jcxz ok1
pop cx
div cx
add dx,30h
push dx
inc bx
jmp short s3
ok1: pop cx
mov cx,bx
s4: pop ax
mov es:[di],al
inc di
loop s4
pop di
pop cx
pop bx
ret
show_str: push dx 打印字符串
push cx
mov ax,0b800h
mov es,ax
mov al,160
mul dh
mov bx,ax
mov al,2
mul dl
mov di,ax
mov ah,cl
mov ch,0
s: mov cl,[si]
jcxz ok2
mov es:[bx+di],cl
mov es:[bx+di+1],ah
add di,2
inc si
jmp short s
ok2:
pop cx
pop dx
ret
codesg ends
end start