实验七——王爽…………我写的最长的一个汇编程序==
October 6, 2013
masm
这是我到目前为止写的最长的汇编程序了。
assume cs:sad, ds:data, ss:stack
stack segment
stack ends
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 years -- 54h bytes
dd 16, 22, 382, 1356, 2390, 8000, 16000, 24486, 50065, 97479, 140417, 197514
dd 345980, 590827, 803530, 1183000, 1843000, 2759000, 3753000, 4649000, 5937000
; income in 21 years -- 54h bytes
dw 3, 7, 9, 13, 28, 38, 130, 220, 476, 778, 1001, 1442, 2258, 2793, 4037, 5635, 8226
dw 11542, 14430, 15257, 17800
; staff in 21 years -- 2ah bytes
data ends
table segment
db 21 dup ('year summ ne ?? ')
table ends
sad segment
start:
mov ax, table
mov ds, ax
mov ax, data
mov es, ax
mov di, 0
mov bx, 0
mov cx, 21
mov si, 0
s:
; year
mov ax, es:[di+0]
mov ds:[bx+0], ax
mov ax, es:[di+2]
mov ds:[bx+2], ax
mov ds:[bx+4], ' '
; income
mov ax, es:[di+54h]
mov ds:[bx+5], ax
mov ax, es:[di+54h+2]
mov ds:[bx+7], ax
mov ds:[bx+9], ' '
; staff
mov ax, es:[si+54h+54h]
mov ds:[bx+0ah], ax
mov ds:[bx+0ch], ' '
; average income
mov ax, ds:[bx+5]
mov dx, ds:[bx+7]
div word ptr ds:[bx+0ah]
mov ds:[bx+0dh], ax
mov ds:[bx+0fh], ' '
add di, 4
; the number of staff takes 2 bytes instead of 4!
add si, 2
add bx, 10h
loop s
mov ax, 4c00h
int 21h
sad ends
end start
刚开始的错误是:没有注意到其实人数所占的字节是2个,步长设置成了4个,所以导致了做除法运算的时候出现了溢出。
程序运行对的那一刻,兴奋!
其实也不太难=_=