0基础汇编入门实验7代码, 大家帮看看哪里出错,debug单步跟踪没看见结果,谢谢大家!
assume cs:codesg,ds:datasg,ss:stacksg,es:tablestacksg segment
dw 21 dup(0)
stacksg ends
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 ;si=54h~0A7H
dd 345980,590827,803530,1183000,1843000,2759000,3753000,464900,5937000
dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226 ;bp=A8h~D1H
dw 11542,14430,15257,17800
datasg ends
table segment
db 21 dup ('year summ ne ??')
table ends
codesg segment
start:mov ax,stacksg
mov ss,ax
mov sp,16h
mov ax,datasg
mov ds,ax
mov ax,table
mov es,ax
mov si,0
mov di,0
mov bx,0
mov cx,21
s0: push cx
mov cx,4
s: mov al,
mov es:,al
inc bx
inc di
loop s
mov bx,0
mov di,0
mov dx,56h
mov ax,54h
mov es:7h,dx
mov es:5h,ax
mov ax,0a8h
mov es:0ah,ax
mov ax,54h
mov dx,56h
div word ptr ds:0a8h
mov es:0dh,ax
add bx,4
add si,2
add di,16
pop cx
loop s0
mov ax,4c00h
int 21h
codesg ends
end start
assume cs:codesg,ds:datasg,ss:stacksg,es:table
stacksg segment
dw 21 dup(0)
stacksg ends
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 ;si=54h~0A7H
dd 345980,590827,803530,1183000,1843000,2759000,3753000,464900,5937000
dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226 ;bp=A8h~D1H
dw 11542,14430,15257,17800
datasg ends
table segment
db 21 dup ('year summ ne ??')
table ends
codesg segment
start:
mov ax,stacksg
mov ss,ax
mov sp,16h
mov ax,datasg
mov ds,ax
mov ax,table
mov es,ax
mov si,0
mov di,0
mov bx,0
mov cx,21
s1:
push di
mov al,ds:
mov es:,al
inc si
inc di
pop di
add di,0a0h
loop s1
mov si,54h
mov di,10h
mov cx,21
s2:
push di
mov dx,ds:
mov ax,ds:
mov es:,dx
mov es:,ax
add si,8
add di,8
pop di
add di,0a0h
loop s2
.
.
. ;下面再定义2个循环就行了
.
.
mov ax,4c00h
int 21h
codesg ends
end start 其他地方没有错,就这个地方mov sp,16h计算错你了;
应该是mov sp,2Ah
dw 21 dup(0)
=42=2AH assume cs:codesg,ds:datasg,ss:stacksg,es:table
stacksg segment
dw 21 dup(0) ;这是定义的栈段
stacksg ends
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' ;以上是表示21年的21个字符串
dd 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514
dd 345980,590827,803530,1183000,1843000,2759000,3753000,464900,5937000
;以上是表示21年公司总收的21个dword型数据
dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226
dw 11542,14430,15257,17800;以上是表示21年公司雇员人数的21个word型数据
datasg ends
table segment
db 21 dup ('year summ ne ??') ;以上是表格
table ends
codesg segment
start:mov ax,stacksg
mov ss,ax
mov sp,2Ah
mov ax,datasg
mov ds,ax
mov ax,table
mov es,ax
mov si,0
mov di,0
mov bx,0
mov cx,21
s0:push cx
mov cx,4
s: mov al,
mov es:,al
inc bx
inc di ;以上4句的作用是存放年份
loop s
mov bx,0
mov di,0
mov dx,56h
mov ax,54h
mov es:7h,dx
mov es:5h,ax ;以上4句的作用是存放公司总收人
mov ax,0a8h
mov es:0ah,ax ;以上2句是存放公司的人数
mov ax,54h
mov dx,56h
div word ptr ds:0a8h
mov es:0dh,ax ;以上4句是存放人均收入
add bx,4
add si,2
add di,16 ;以上3句是为下一次循环时存放数据做准备
pop cx
loop s0 ;跳到标号s0处
mov ax,4c00h
int 21h
codesg ends
end start
assume cs:codesg,ds:datasg,ss:stacksg,es:table
stacksg segment
dw 21 dup(0) ;这是定义的栈段
stacksg ends
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' ;以上是表示21年的21个字符串
dd 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514
dd 345980,590827,803530,1183000,1843000,2759000,3753000,464900,5937000
;以上是表示21年公司总收的21个dword型数据
dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226
dw 11542,14430,15257,17800;以上是表示21年公司雇员人数的21个word型数据
datasg ends
table segment
db 21 dup ('year summ ne ??') ;以上是表格
table ends
codesg segment
start:mov ax,stacksg
mov ss,ax
mov sp,2Ah
mov ax,datasg
mov ds,ax
mov ax,table
mov es,ax
mov si,0
mov di,0
mov bx,0
mov cx,21
s0:push cx
mov cx,4
s: mov al,
mov es:,al
inc bx
inc di ;以上4句的作用是存放年份
loop s
mov bx,0 ;此处初始化错了,以至于后面的add bx,4; add si,2 mov di,0 ;没有起作用
mov dx,56h
mov ax,54h
mov es:7h,dx
mov es:5h,ax ;以上4句的作用是存放公司总收人
mov ax,0a8h
mov es:0ah,ax ;以上2句是存放公司的人数
mov ax,54h
mov dx,56h
div word ptr ds:0a8h
mov es:0dh,ax ;以上4句是存放人均收入
add bx,4
add si,2
add di,16 ;以上3句是为下一次循环时存放数据做准备
pop cx
loop s0 ;跳到标号s0处
mov ax,4c00h
int 21h
codesg ends
end start
自己修改了一下代码,单步跟踪只看见前面的年代,后面看不见,不知道对不对。 修改后的代码如下:
assume cs:codesg,ds:datasg,ss:stacksg,es:table
stacksg segment
dw 21 dup(0)
stacksg ends
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 ;si=54h~0A7H
dd 345980,590827,803530,1183000,1843000,2759000,3753000,464900,5937000
dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226 ;bp=A8h~D1H
dw 11542,14430,15257,17800
datasg ends
table segment
db 21 dup ('year summ ne ??')
table ends
codesg segment
start:mov ax,stacksg
mov ss,ax
mov sp,16h
mov ax,datasg
mov ds,ax
mov ax,table
mov es,ax
mov si,0
mov di,0
mov bp,0
mov bx,0
mov cx,21
s0: push cx
mov cx,4
s: mov al,
mov es:,al
inc di
loop s
mov di,0
mov dx,56h
mov ax,54h
mov es:7h,dx
mov es:5h,ax
mov ax,0a8h
mov es:0ah,ax
mov ax,54h
mov dx,56h
div word ptr ds:0a8h
mov es:0dh,ax
add bx,4
add si,2
add bp,16
pop cx
loop s0
mov ax,4c00h
int 21h
codesg ends
end start
这么晚了,还为我解答问题,不胜感激!!!{:5_109:} 哦!对了,di第一次循环不错,但是第二次就错了;
由此,可以得出一个结论:在同一循环体内,担当参与循环次数递增或递减的寄存器,不能赋一次以上不同的值。 ;还可以这样做:在s循环前先push bx与push di然后在s循环结束后再pop di与pop bx
;我个人认为这样的程序,其思路更清晰,且少占用了一个寄存器,这样更适合大程序!
assume cs:codesg,ds:datasg,ss:stacksg,es:table
stacksg segment
dw 21 dup(0) ;这是定义的栈段
stacksg ends
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' ;以上是表示21年的21个字符串
dd 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514
dd 345980,590827,803530,1183000,1843000,2759000,3753000,464900,5937000
;以上是表示21年公司总收的21个dword型数据
dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226
dw 11542,14430,15257,17800;以上是表示21年公司雇员人数的21个word型数据
datasg ends
table segment
db 21 dup ('year summ ne ??') ;以上是表格
table ends
codesg segment
start:mov ax,stacksg
mov ss,ax
mov sp,2Ah
mov ax,datasg
mov ds,ax
mov ax,table
mov es,ax
mov si,0
mov di,0
mov bx,0
mov cx,21
s0:push cx
push bx
push di
mov cx,4
s: mov al,
mov es:,al
inc bx
inc di ;以上4句的作用是存放年份
loop s
pop di
pop bx
mov dx,56h
mov ax,54h
mov es:7h,dx
mov es:5h,ax ;以上4句的作用是存放公司总收人
mov ax,0a8h
mov es:0ah,ax ;以上2句是存放公司的人数
mov ax,54h
mov dx,56h
div word ptr ds:0a8h
mov es:0dh,ax ;以上4句是存放人均收入
add bx,4
add si,2
add di,16 ;以上3句是为下一次循环时存放数据做准备
pop cx
loop s0 ;跳到标号s0处
mov ax,4c00h
int 21h
codesg ends
end start
没个正样 发表于 2012-2-7 04:30 static/image/common/back.gif
;还可以这样做:在s循环前先push bx与push di然后在s循环结束后再pop di与pop bx
;我个人认为这样的程序, ...
高招,学习了,我是抓破头想出bp这个寄存器可用来 ,心里还想要是再有一个循环就没寄存器可用了,把bx,di放到栈中是好办法!!!{:5_95:},共同成长!! 问题已经解决,怎么放到已解决里面呢!!!
学习,支持一下!加油
页:
[1]