|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我的想法是先把表格建好,然后在show_str里面同时完成转换字符串和输出功能
但是总是只输出年份,调试来调试去现在一运行就死机
我已经卡了五六天了,改的头晕眼花,救救孩子吧
assume cs:code
data segment
db'1975','1976','1977','1978','1979','1980','1981','1982','1983','1984','1985','1986','1987','1988','1989','1990','1991','1992','1993','1994','1995'
dd 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514,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,11542,14430,15257,17800
data ends
table segment
db 21 dup ('year summ ne ?? ')
table ends
a segment
db 20 dup(0) ;重复利用,用来存每一次转换的字符串
a ends
stack segment
dw 60 dup(0) ;栈
stack ends
code segment
start:
mov ax,data
mov ds,ax
mov ax,table
mov es,ax
mov ax,stack
mov ss,ax
mov sp,120
call set_table
mov ax,0b800h
mov ds,ax
mov bx,160
mov bp,0
show:call show_str
add bx,160 ;bx表示屏幕行
add bp,16 ;bp表示table行
mov ax,4c00h
int 21h
============================================
set_table: ;建表格
mov ax,data
mov ds,ax
mov si,0
mov bx,0
mov ax,table
mov es,ax
mov bp,0
mov cx,21
s:mov ax,ds:[bx].0[di] ;年份
mov es:[bp].0,ax
mov ax,ds:[bx].2[di]
mov es:[bp].2,ax
mov ax,ds:[bx].84[di] ;总收入
mov es:[bp].5,ax
mov ax,ds:[bx].86[di]
mov es:[bp].7,ax
mov ax,ds:[bx].168[di] ;人数
mov es:[bp].10,ax
mov ax,ds:[bx].84 ;人均
mov dx,ds:[bx].86
div word ptr ds:[bx].168
mov es:[bp].14,ax
add di,4
add si,2
add bp,16
loop s
ret
==============================================
show_str: ;show_str函数
push cx
push bx
push bp
show_year:
mov si,0
mov di,0
mov cx,4
s1:mov al,es:[bp].0[si]
mov ds:[bx].0[di],al
inc si
add di,2
loop s1
show_salary:
mov si,0
mov di,0
mov ax,es:[bp].5
mov dx,es:[bp].7
call dtoc
push ss
mov ax,a
mov ss,ax
mov si,0
mov di,0
mov bx,160
mov bp,0
s2:mov al,ss:[si]
mov ah,0
mov cx,ax
jcxz ok
mov ds:[bx].20[di],al
inc si
add di,2
jmp short s2
ok:pop ss
show_mans:
mov si,0
mov di,0
mov ax,es:[bp].0ah
mov dx,0
call dtoc
push es
mov ax,a
mov es,ax
s3:mov al,es:[si]
mov ah,0
mov cx,ax
jcxz ok1
mov ds:[bx].40[di],al
inc si
add di,2
jmp short s3
ok1:pop es
show_mansalary:
mov si,0
mov di,0
mov ax,es:[bp].0dh
mov dx,0
call dtoc
push es
mov ax,a
mov es,ax
s4:mov al,es:[si]
mov ah,0
mov cx,ax
jcxz ok2
mov ds:[bx].60[di],al
inc si
add di,2
jmp short s4
ok2:pop es
pop bp
pop bx
pop cx
ret
================================================
dtoc: ;转换字符串
push ax
push dx
push cx
push ds
push si
push di
mov bx,a
mov ds,bx
mov bx,0
mov si,0
s5:mov cx,10
call divdw
add cx,30h
push cx
inc si
mov cx,ax
jcxz ok3
jmp short s5
ok3:mov cx,dx ;从网上抄的判断操作
jcxz ok4
jmp short s5
ok4:mov cx,si
mov si,0
s6:pop ax
mov ds:[si],al
inc si
loop s6
mov al,0
mov byte ptr ds:[si],al
pop di
pop si
pop ds
pop cx
pop dx
pop ax
ret
=============================================
divdw: ;除法溢出处理函数
push bx
push si
push di
push bp
mov bx,ax
mov ax,dx
mov dx,0
div cx
mov si,ax
mov ax,bx
div cx
mov cx,dx
mov dx,si
pop bp
pop di
pop si
pop bx
ret
code ends
end start
本帖最后由 jackz007 于 2022-10-13 14:57 编辑 assume cs:code , ds:data , es:table
data segment para public 'DATA'
db'1975','1976','1977','1978','1979','1980','1981','1982','1983','1984','1985','1986','1987','1988','1989','1990','1991','1992','1993','1994','1995'
dd 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514,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,11542,14430,15257,17800
buff01 db 100h dup(00)
buff02 db 100h dup(00)
buff03 db 100h dup(00)
buff04 db 100h dup(00)
data ends
table segment para public 'DATA'
db 21 dup ('year summ ne ?? ')
table ends
stack segment para stack
dw 800h dup(0) ;
stack ends
code segment para public 'CODE'
;============================================
pause proc near
push ax
xor ax,ax
int 16h
pop ax
ret
pause endp
;============================================
show_crlf proc near
push ax
push dx
mov ah,2
mov dl,10
int 21h
mov dl,13
int 21h
pop dx
pop ax
ret
show_crlf endp
;============================================
show_dec proc near
push bp
mov bp,sp
push ax
push cx
push dx
push si
push di
push ds
mov ax,[bp+4]
mov si,offset buff01
push si
mov cx,10
dec01: xor dx,dx
div cx
add dl,'0'
mov byte ptr ds:[si],dl
inc si
or ax,ax
jnz dec01
mov byte ptr ds:[si],al
lea di,[si-1]
pop si
push si
dec02: cmp si,di
jae dec03
mov al,byte ptr[si]
xchg byte ptr[di],al
mov byte ptr ds:[si],al
inc si
dec di
jmp short dec02
dec03: pop si
mov ah,2
dec04: mov dl,ds:byte ptr[si]
or dl,dl
jz dec05
int 21h
inc si
jmp short dec04
dec05: pop ds
pop di
pop si
pop dx
pop cx
pop ax
mov sp,bp
pop bp
ret
show_dec endp
;============================================
show_str proc near
push bp
mov bp,sp
push ax
push si
push di
push ds
push es
lds si , [bp+4]
cld
mov ah,2
str01: lodsb
or al,al
jz str02
mov dl,al
int 21h
jmp short str01
str02: pop es
pop ds
pop di
pop si
pop ax
mov sp,bp
pop bp
ret
show_str endp
;============================================
maketab proc near
push bp
mov bp,sp
push ax
push bx
push cx
push dx
push si
push di
push ds
push es
mov ax,data
mov ds,ax
mov ax,table
mov es,ax
xor si,si
xor di,di
mov cx,21
cld
push cx
push di
push cx
push di
make01: push cx
mov cx,4
repe movsb
add di,12
pop cx
loop make01
pop di
add di,5
pop cx
push cx
push di
make02: movsw
movsw
add di,12
loop make02
pop di
add di,5
pop cx
make03: movsw
add di,14
loop make03
pop di
pop cx
push es
pop ds
make04: push cx
push di
mov ax,word ptr[di+5]
mov dx,word ptr[di+7]
mov cx,word ptr[di+10]
div cx
mov word ptr ds:[di+13],ax
pop di
add di,16
pop cx
loop make04
pop es
pop ds
pop di
pop si
pop dx
pop cx
pop bx
pop ax
mov sp,bp
pop bp
ret
maketab endp
;=============================================
main proc far
mov ax,data
mov ds,ax
mov ax,table
mov es,ax
call maketab ; 传送数据填表 + 计算平均薪水填表
xor bx,bx
mov cx,21
push bx
push cx
main01: push word ptr es:[bx+10]
call show_dec
add sp,2
call show_crlf
add bx,16
loop main01
call pause
call show_crlf
pop cx
pop bx
main02: push word ptr es:[bx+13]
call show_dec
add sp,2
call show_crlf
add bx,16
loop main02
call pause
mov ax,4c00h
int 21h
main endp
;=============================================
code ends
end main
运行实况: 3
7
9
13
28
38
130
220
476
778
1001
1442
2258
2793
4037
5635
8226
11542
14430
15257
17800
5
3
42
104
85
210
123
111
105
125
140
136
153
211
199
209
224
239
260
304
333
空行前半部分是显示 table 中 23 年的员工数量,后半部分显示的是 table 中 23 年中,每年的员工平均收入,计算方法,自然是总薪水除以员工总数,相关数据也是取自 table,楼主可以计算验证。
这个作业涉及除法溢出的问题,不用专门处理。
|
|