用到了王爽老师给出的思路
assume cs:code,ds:data,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'
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
stack segment
dw 16 dup (0) ;define a stack with 32 byte space
stack ends
table segment
db 21 dup (' ') ;define table space with 21 rows, each row has 16 spaces(20h)
table ends
code segment
start:mov ax,data ;make ds points to data segment
mov ds,ax
mov ax,table ;make es points to table segment
mov es,ax
mov ax,stack ;make ss points to stack segment
mov ss,ax
mov sp,32 ;make sp points to ss:32
mov si,0 ;initialize si,di,bx
mov di,0
mov bx,0
push di ;push the value in di to the stack, only used to set the initial value of di(used in get employee number)
mov cx,21
l:mov di,0 ;set di to 0,di is used to locate the first and second word in the 'year element' and 'income element'
mov ax,0[si] ;set the first word in 'year element', 0(idata) represent the specific array(year, income, or employee number)
mov es:[bx].0[di],ax ;[bx] represent the struct variable(row), 0(idata) represent the specific item in the struct variable
mov ax,0[si+2] ;set the second word in 'year element'
mov es:[bx].0[di+2],ax
;if the data are bigger, you will wish to use loop to achieve this(remember to set cx properly):
;mov cx,2
;l1:mov ax,0[si]
; mov es:[bx].0[di],ax
; add si,2
; add di,2
;loop l1
;sub si,4
;sub di,4
mov ax,84[si] ;set the first word in 'income element', move it to ax(used to store the lower 16 bits)
mov es:[bx].5[di],ax
mov dx,84[si+2] ;set the second word in 'income element', move it to dx(used to store the higher 16 bits)
mov es:[bx].5[di+2],dx
pop di ;pop the value to di(the di in here only used to get employee number)
div word ptr 168[di] ;perform the operation of division
mov es:[bx].0dh,ax ;move the result to the location of 'average income element'
mov ax,168[di] ;move the employee number to the right place
mov es:[bx].0ah,ax
add di,2 ;because the employee number are word
push di ;save di
add si,4 ;because the year and income are double-word
add bx,16 ;because each row has 16 bytes
loop l
mov ax,4c00h
int 21h
code ends
end start