Skip to content

Instantly share code, notes, and snippets.

@alexsunday
Created November 23, 2019 14:33
Show Gist options
  • Save alexsunday/15a49e7796a9d6a24b22e054bcfc110e to your computer and use it in GitHub Desktop.
Save alexsunday/15a49e7796a9d6a24b22e054bcfc110e to your computer and use it in GitHub Desktop.
assume cs:code,ds:data,ss:stack
; 将 data 段中的数据按如下格式写入到 table 段
; 并计算21年中的人均收入(取整)
; 结果也按照下面的格式写入到 table 段
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'
;以上是表示21年的21个字符串 year
dd 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514
dd 345980,590827,803530,1183000,1843000,2759000,3753000,4649000,5937000
;以上是表示21年公司总收入的21个dword数据 sum
dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226
dw 11542,14430,15257,17800
; 以上表示21年公司员工数量
data ends
table segment
;0123456789ABCDEF
db 21 dup ('year summ ne ?? ')
table ends
stack segment stack
db 128 dup (0)
stack ends
code segment
start:
mov ax,stack
mov ss,ax
mov sp,128
mov ax, data
mov ds, ax
mov ax, table
mov es, ax
mov cx, 2 * 9 + 3
mov bx, 0
setData:
push cx
; 先复制年份 每个年份 4 字节
mov cx, 4
mov si, 0
cpYear:
mov al, ds:[bx + si]
mov es:[si], al
inc si
loop cpYear
; 再复制收入数据 每个收入占 4 字节
mov cx, 4
mov si, 0
cpPay:
mov al, ds:[bx + si + (2 * 9 + 3) * 4]
mov es:[si + 5], al
inc si
loop cpPay
pop cx
add bx, 4
; 目标地址+1,切换到下一条记录
mov dx, es
inc dx
mov es, dx
loop setData
; 重设 es 复制 人数记录,计算平均收入 再循环一遍
mov ax, table
mov es, ax
mov cx, 2 * 9 + 3
mov si, 0
forResult:
; 先跳过年份与收入记录区
mov bx, ds:[si + (2 * 9 + 3) * 4 * 2]
mov es:[10], bx
; dx 放高位,ax 放低位,除后 ax 放商数,dx 放余数
; mov ax,
mov ax, es:[5]
mov dx, es:[7]
div bx
mov es:[13], ax
add si, 2
; 指向下一条记录
mov dx, es
inc dx
mov es, dx
loop forResult
mov ax,4C00H
int 21H
code ends
end start
@alexsunday
Copy link
Author

图片

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment