实验七 运行报错除法溢出
代码如下<p>assume cs:codesg,ds:datasg,ss:stacksg
datasg 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 24580,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
datasg ends
table segment
db 21 dup('year summ ne ?? ')
table ends
stacksg segment
dw 8 dup(0)
stacksg ends
codesg segment
start:
mov ax,datasg
mov es,ax
mov ax,table
mov ds,ax
mov ax,stacksg
mov ss,ax
mov sp,20H
mov bx,0
mov bp,0
mov cx,21
s1: mov si,0
push cx
mov cx,2
s2: mov ax,es:
mov ,ax
inc si
inc si
loop s2 ;存放年份,4个字节
mov si,0
mov cx,2
s3: mov ax,es:
mov ,ax
inc si
inc si
loop s3 ;存放收入,4个字节
mov ax,es:
mov ,ax ;存放人数,2个字节
mov dx,
mov ax,
div word ptr
mov ,ax ;计算人均收入
inc bp
add bx,16
pop cx
loop s1 ;一年复制完成
mov ax,4c00H
int 21h
codesg ends
end start</p><p>
</p>编译时没有错误,得到exe文件之后,debug,提示divide overflow,程序结束。
麻烦各位大佬看看是什么原因,谢谢啦
assume cs:codesg,ds:data,es: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'
dd 16,22,382,1356,2390,800,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
codesg segment
start: mov ax,data
mov ds,ax
mov ax,table
mov es,ax
mov bx,0
mov si,0
mov di,0a8h
mov cx,21
s: mov ax,
mov es:,ax
mov ax,
mov es:,ax
mov al,
mov es:,ax
mov dx,
mov es:,dx
mov bp,
mov es:,bp
div word ptr bp
mov es:,al
add bx,16
add si,4
add di,2
loop s
mov ax,4c00h
int 21h
codesg ends
end start
实验7答案 问题已经解决了。小甲鱼说,灵活寻址就像数组,我还真把它用成数组下标了,把增量写成了+1。bp应该是+4才对。
正确代码如下
assume cs:codesg,ds:table,ss:stacksg,es:datasg
datasg 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 24580,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
datasg ends
table segment
db 21 dup('year summ ne ?? ')
table ends
stacksg segment
dw 8 dup(0)
stacksg ends
codesg segment
start:
mov ax,datasg
mov es,ax
mov ax,table
mov ds,ax
mov ax,stacksg
mov ss,ax
mov sp,20H
mov bx,0
mov bp,0
mov di,0
mov cx,21
s1: mov si,0
push cx
mov cx,2
s2: mov ax,es:
mov ,ax
inc si
inc si
loop s2 ;存放年份,4个字节
mov si,0
mov cx,2
s3: mov ax,es:
mov ,ax
inc si
inc si
loop s3 ;存放收入,4个字节
mov ax,es:
mov ,ax ;存放人数,2个字节
mov dx,
mov ax,
div word ptr
mov ,ax ;计算人均收入
add bp,4 ;增量是4不是1
add di,2
add bx,16
pop cx
loop s1 ;一年复制完成
mov ax,4c00H
int 21h
codesg ends
end start
对代码有问题,可以找我。
谢谢楼上的答案,但是人都是不喜欢读别人代码的,况且没有注释{:10_266:}{:10_266:},不好意思 57158597@qq.com 发表于 2018-9-17 15:07
assume cs:codesg,ds:data,es:table
data segment
层主,你确定你的答案是对的吗?
因为我们两运行的代码运行出来不一样,但是我的除法(复制过后的收入/复制后的人数),我单步跟踪过前面几行都是对的 20180906 发表于 2018-9-17 16:05
层主,你确定你的答案是对的吗?
因为我们两运行的代码运行出来不一样,但是我的除法(复制过后的收入/ ...
嗯,看了下,确实有个地方错了,把代码上的2个al改成AX就行了 57158597@qq.com 发表于 2018-9-18 15:36
嗯,看了下,确实有个地方错了,把代码上的2个al改成AX就行了
哦哦{:10_265:}哎,感觉学这个好累呀
页:
[1]