Skip to content

Instantly share code, notes, and snippets.

@alexsunday
Last active December 1, 2019 07:48
Show Gist options
  • Save alexsunday/4f32e8eeb406dd384eadfa7ff1fcd8e5 to your computer and use it in GitHub Desktop.
Save alexsunday/4f32e8eeb406dd384eadfa7ff1fcd8e5 to your computer and use it in GitHub Desktop.
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'
;以上是表示21年的21个字符串 year
dd 16,22,382,1356,2390,8000,16000,24486,50065,9749,14047,19751
dd 34598,59082,80353,11830,18430,27590,37530,46490,59370
;以上是表示21年公司总收入的21个dword数据 sum
dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226
dw 1154,1443,1525,1780
; 以上是公司人数
data ends
table segment
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
main_process:
call cp_records
call clear_screen
call display_records
jmp quit
clear_screen:
mov bx, 0B800h
mov es, bx
mov bx, 0
mov dx, 0700H
mov cx, 2000
clearScreen:
mov es:[bx], dx
add bx, 2
loop clearScreen
ret
cp_records:
; 数据段来源
mov ax, data
mov ds, ax
mov si, 0
; 复制到目标地址
mov ax, table
mov es, ax
mov di, 0
mov bx, 0
mov cx, 21
copy_record:
; copy year
mov ax, ds:[bx + 0]
mov es:[di + 0], ax
mov ax, ds:[bx + 2]
mov es:[di + 2], ax
; copy amount
mov ax, ds:[bx + 21 * 4 + 0]
mov es:[di + 5], ax
mov dx, ds:[bx + 21 * 4 + 2]
mov es:[di + 5 + 2], dx
; compute avg
div word ptr ds:[si + 21 * 4 + 21 * 4 + 0]
mov es:[di + 13], ax
; copy count
mov ax, ds:[si + 21 * 4 + 21 * 4 + 0]
mov es:[di + 4 + 1 + 4 + 1], ax
add bx, 4
add si, 2
add di, 16
loop copy_record
ret
display_records:
; 数据段来源
mov ax, table
mov ds, ax
mov si, 0
; 复制到目标地址
mov ax, 0B800H
mov es, ax
mov di, 160 + 16
mov bx, 0
mov cx, 21
show_record:
; show year
push cx
push di
mov cx, 4
mov si, 0
show_year:
mov dl, ds:[bx + si]
add di, 2
call show_byte
inc si
loop show_year
pop di
pop cx
; db 21 dup ('year summ ne ?? ')
; show amount
push di
add di, 12 * 2
mov ax, ds:[bx + 5]
mov dx, ds:[bx + 7]
call short_div
pop di
; show count
push di
add di, (12 + 12) * 2
mov ax, ds:[bx + 10]
mov dx, 0
call short_div
pop di
; show avg
push di
add di, (12 + 12 + 12) * 2
mov ax, ds:[bx + 13]
mov dx, 0
call short_div
pop di
add bx, 16
add di, 160
loop show_record
ret
quit:
mov ax,4C00H
int 21H
show_byte:
mov es:[di + 0], dl
mov byte ptr es:[di + 1], 00000010B
ret
short_div:
push cx
push dx
push di
loop_div:
mov cx, 10
div cx
add dl, 30H
call show_byte
mov cx, ax
jcxz shortDivEnd
mov dx, 0
sub di, 2
jmp loop_div
shortDivEnd:
pop di
pop dx
pop cx
ret
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