最近在看王爽老师的《汇编语言》,在进行课程设计一的时候,我需要把已经在之前存在一个数据段中的数据转为ASCII码存在另一个数据段中。在这个过程中,我如果将之前的数据任意读进12行,都是可行的,转化也很成功。但是只要我读入大于13行,就不行了, 就像崩溃了样的动不了。请问这是为什么呢?
汇编语言我没怎么打注释,标的地方就是有问题的,大家能看看就看看吧,谢谢了。
assume cs:code, ds:data
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
table segment
db 21 dup ('year summ ne ?? ')
table ends
showing segment
dw 21 dup(0,0,0,0,0,0,0,0)
showing ends
code segment
start:
mov ax,data
mov ds,ax
mov ax,table
mov es,ax
call input
mov ax,table
mov ds,ax
mov ax,showing
mov es,ax
mov si,0
mov di,0
call convert;将数据转为ASCII码存入showing段中
mov ax,0b800h
mov es,ax
mov ax,showing
mov ds,ax
mov si,0
mov cx,0
mov cl,02h
mov dh,5
mov dl,4
call show_str
mov ax,4c00h
int 21h
show_str:
push ax
push bx
push cx
push dx
push si
push di
mov ax,0
mov bl,cl
mov di,0
mov cx,2
s0:
mov al,dh
mov bh,160
mul bh
add di,ax
mov ax,0
mov al,dl
mov bh,2
mul bh
add di,ax
push cx
mov cx,32
s1:
push cx
mov cx,0
mov cl,[si]
mov es:[di],cl
inc si
inc di
jcxz jump
mov es:[di],bl
inc di
jump:
pop cx
loop s1
add dh,1
mov dl,0
add si,32
pop cx
loop s0
pop di
pop si
pop dx
pop cx
pop bx
pop ax
ret
convert:
push ax
mov cx,12;转12行可以,转13行不行
trans:
mov ax,[si]
mov es:[di],ax
mov ax,[si + 2]
mov es:[di + 2],ax
mov bp,5
mov bx,8
call dtoc
mov bp,0Ah
mov bx,19
call dtocsmall
mov bp,0dh
mov bx,28
call dtocsmall
add si,16
add di,32
loop trans
pop ax
ret
dtocsmall:
push ax
push cx
push dx
push si
push di
add si,bp
add di,bx
mov bp,0
mov ax,[si]
mov dx,0
smallin:
mov cx,10
call divdw
mov bx,cx
mov cx,0
mov si,0
or si,ax
or cx,dx
or cx,si
or cx,bx
jcxz over
add bx,30h
push bx
inc bp
inc cx
loop smallin
over:
mov cx,bp
smalldel:
pop ax
mov es:[di],al
inc di
loop smalldel
pop di
pop si
pop dx
pop cx
pop ax
ret
dtoc:
push ax
push cx
push dx
push di
push si
add si,bp
add di,bx
mov bp,0
mov ax,[si]
mov dx,[si + 2]
transfer:
mov cx,10
call divdw
mov bx,cx
mov cx,0
mov si,0
or si,ax
or cx,dx
or cx,si
or cx,bx
jcxz streamout
add bx,30h
push bx
inc bp
inc cx
loop transfer
streamout:
mov cx,bp
output:
pop bx
mov es:[di],bl
inc di
loop output
pop si
pop di
pop dx
pop cx
pop ax
ret
input:
push si
push di
push ax
push bx
push cx
push dx
push bp
mov bx,0
mov si,0
mov di,0
mov cx,21
streamin:
mov bp,[si]
mov es:[bx],bp
mov bp,[si + 2]
mov es:[bx + 2],bp
mov bp,[si + 84]
mov es:[bx + 5],bp
mov bp,[si + 86]
mov es:[bx + 7],bp
mov bp,[di + 168]
mov es:[bx + 10],bp
push cx
mov cx,es:[bx + 10]
mov ax,es:[bx + 5]
mov dx,es:[bx + 7]
call divdw
mov es:[bx + 13],ax
pop cx
add si,4
add di,2
add bx,16
loop streamin
pop bp
pop dx
pop cx
pop bx
pop ax
pop di
pop si
ret
divdw:
push bx
push ax
mov ax,dx
mov dx,0
div cx
mov bx,ax
pop ax
div cx
mov cx,dx
mov dx,bx
pop bx
ret
code ends
end start