王爽汇编语言实验7
最近在学底层汇编做的一个练习,放上来纪念,感觉有点生硬,不过运行是没问题的。(王爽汇编语言p160)
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'
;年份(4字节)
dd 16,22,382,1356,2390,8000,1600,24486,50065,97479,140417,197514
dd 345980,590827,803530,1183000,1843000,2759000,3753000,4649000,5973000
;年收入(4字节)
dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226
dw 11542,11430,15257,17800
;员工人数(2字节)
data ends
table segment
db 21 dup ('year summ ne ?? ')
table ends
;-U 反汇编
;-T 2 执行跟踪
;-D DS:0 查看范围
;年份开始偏移地址为0000
;年收入开始偏移地址为0054
;员工人数开始偏移地址为00a8
;table位置分别是0000h,0005h,000ah,000dh
assume cs:code,ds:data,es:table
code segment
start :
mov ax,data
mov ds,ax
mov ax,table
mov es,ax
mov bx,0
mov di,0
mov si,0
mov cx,21
s:
;读取年份放到table
mov ax,ds:[di]
mov es:[bx],ax
mov ax,ds:[di+2]
mov es:[bx+2],ax
;读取员工数放到table
mov ax,ds:[00a8h+si]
mov es:[bx+000ah],ax
;读取收入放到table
mov ax,ds:[di+0054h]
mov es:[bx+5],ax
mov dx,ds:[di+0054h+2] ;高位字
mov es:[bx+5+2],dx
;总收入除以员工,得平均收入(ax为商,dx为余数)
div word ptr ds:[00a8h+si]
mov es:[bx+000dh],ax
add di,4h ;年份,收入下一行
add si,2h ;员工下一行
add bx,10h ;表格下一行
loop s
mov ax,4c00h
int 21h
code ends
end start
debug结果放在es寄存器,用d es:0查看
补充:综合编程 , 其他综合 ,