同一段里的数据是紧挨着放置的
分成 4 部分
- 填写年份
- 填写收入
- 填写雇员数目
- 计算人均收入并填写
由于前两部分移动的数据量是一致的,所以可以合并到一起写。
第三部分和第二部分的区别是循环的次数少了一半。
计算人均收入重点在于 被除数的高位和低位。
难点在于不同代码段之间的寻址。
代码
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 21 dup('year summ ne ?? ')
table ends
//暂时存放寄存器的地址
stacksg segment
dw 0,0,0,0,0,0,0,0
stacksg ends
codesg segment
//initialize ds
start: mov ax,data
mov ds,ax
//initialize es
mov ax,table
mov es,ax
//initialize ss
mov ax,stacksg
mov ss,ax
mov sp,16
mov bp,0
//initialize bx,cs and ready for the first loop
//the first loop is to move year and profit
mov bx,0
mov cx,21
//double loop
//store and reset cx
//initialize si for each loop
s0:mov [bp],cx
mov cx,2
mov si,0
//set year
//get offset for src
s:mov bx,[bp+2]
//get year from source memory
mov ax,ds:[bx+si]
//get offset for dest
mov bx,[bp+4]
//put year into destination
mov es:[bx+si],ax
//set profit
//get offset for src
mov bx,[bp+2]
//get profit from source memory
mov ax,ds:[bx+si+84]
//get offset for dest
mov bx,[bp+4]
//put profit into destination
mov es:[bx+si+5],ax
add si,2
loop s
//update offset of src memory
mov bx,[bp+2]
add bx,4
mov [bp+2],bx
//update offset of dest memory
mov bx,[bp+4]
add bx,16
mov [bp+4],bx
mov cx,[bp]
loop s0
//initialization for the second loop
//the second loop is to move the number of staffs
//initialize the offset of src
mov bx,168
mov [bp+2],bx
//initialize the offset of dest
mov bx,0ah
mov [bp+4],bx
//set the times of loop
mov cx,21
s1:
//get offset for src
mov bx,[bp+2]
//get the number of staffs from source memory
mov ax,ds:[bx]
//get offset for dest
mov bx,[bp+4]
//put the number of staffs into destination
mov es:[bx],ax
//update offset of src memory
mov bx,[bp+2]
add bx,2
mov [bp+2],bx
//update offset of dest memory
mov bx,[bp+4]
add bx,16
mov [bp+4],bx
loop s1
//initialization for the third loop
//the third loop is to Calculate per capita income
//set the times of loop
mov cx,21
mov bx,0
s2:
//被除数高位
mov dx,es:[bx+7]
//被除数低位
mov ax,es:[bx+5]
//除数
div word ptr es:[bx+0ah]
//将商存入内存
mov es:[bx+0dh],ax
//更新内存指向的偏移量
add bx,16
loop s2
//程序终止
mov ax,4c00h
int 21h
codesg ends
end start
最终的运行结果