王爽《汇编语言》程序设计1
星海
posted @ 2010年11月12日 06:12
in 汇编学习
, 1730 阅读
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
tablestr segment
db 840 dup (' ')
tablestr ends
stack segment
dw 16 dup (0)
stack ends
codesg segment
start:
mov ax,data
mov es,ax
mov di,0
mov ax,stack
mov ss,ax
mov sp,32
mov ax,tablestr
mov ds,ax
mov si,0
mov bx,0
mov cx,21
s: mov ax,es:[di]
mov ds:[si],ax
mov ax,es:2[di]
mov ds:2[si],ax
mov ax,es:54h[di]
mov dx,es:56h[di]
add si,10
call dwtoc
sub si,10
div word ptr es:0a8h[bx]
mov dx,0
add si,31
call dwtoc
mov byte ptr ds:5[si],0
sub si,31
mov ax,es:0a8h[bx]
mov dx,0
add si,20
call dwtoc
sub si,20
add si,40
add di,4
add bx,2
loop s
mov cx,21
mov dh,3
mov si,0
mov dl,5
mov bx,0
s0: push cx
mov cl,4ah
call show_str
inc dh
add si,40
pop cx
loop s0
mov ax,4c00h
int 21h
;将dword型数据转为十进制ascii码形式
;ax为例
dwtoc: push cx
push dx
push di
push si
push ax
push bx
mov di,0
dtoc: push ax
mov cx,10
mov ax,dx
mov dx,0
div cx
mov bx,ax ;bx为除法结果的高十六位
pop ax
div cx
push dx ;余数压栈
mov dx,bx ;此时ax除法结果低十六位,dx为高十六位
mov cx,ax
add cx,bx
inc di
jcxz reverse
jmp short dtoc
reverse:mov cx,di
dtocs: pop bx
add bl,30H
mov byte ptr ds:[si],bl
inc si
loop dtocs
dec si
;mov byte ptr ds:[si],0
pop bx
pop ax
pop si
pop di
pop dx
pop cx
ret
show_str:push cx
push si
push ax
push di
push es
push dx ;全部压栈
mov ax,0b800h ;0页显示
mov es,ax
mov al,0a0h
mov ah,0
mul dh
;此时ax中存放dh行数的字节数
mov dh,0
add dl,dl
add ax,dx
mov di,ax
;di存放显示代码所在的偏移值
mov ah,cl
display:mov cl,ds:[si]
mov ch,0
jcxz short strover
mov al,ds:[si]
mov es:[di],al
inc di
mov byte ptr es:[di],ah
inc di
inc si
jmp short display
strover:pop dx
pop es
pop di
pop ax
pop si
pop cx
ret
codesg ends
end start