主题:[讨论]哪个高手进来帮忙看下啊...急~~~后天就要给老师检查了.万分感谢!
小弟是新手,望各位大哥不吝赐教.原题是这样的:编写一个有主程序和子程序结构的程序模块.子程序的参数是一个N字节数组的首地址TABLE,数N及字符CHAR.要求在N字节数组中查找字符CHAR,并记录该字符出现的次数.主程序则要求从键盘接受一串字符以建立字节数组TABLE,并逐个显示从键盘输入的每个字符CHAR以及它在TABLE数组中出现的次数.(为简化起见,假设出现次数<16,可以用十六进制形式把它显示出来.)
下面是偶编的一个程序,可是在显示次数时总是出现乱码,不知道为什么,下面附上原程序:
;****************************************************
data segment
table db 30,0,30 dup(?)
data ends
;****************************************************
extra segment
table2 db 30 dup(?)
extra ends
;****************************************************
code segment
;----------------------------------------------------
main proc far
assume cs:code,ds:data,es:extra
start:
mov ax,data
mov ds,ax
mov ax,extra
mov es,ax
lea dx,table ;read string
mov ah,0ah
int 21h
sub ch,ch ;cx<=character number
mov cl,table+1
mov si,offset table ;make si point the string
add si,2
push si
push cx
lea di,table2
cld
rep movsb
pop si
pop cx
dispchar: sub dx,dx
mov dl,[si] ;output char
mov ah,2
int 21h
mov al,dl
call search_a
mov dl,20h ;output space
mov ah,2
int 21h
add bx,30h
mov dl,bl
mov ah,2
int21h
mov dl,20h ;output space
mov ah,2
int 21h
inc si
loop dispchar
mov ax,4c00h
int 21h
main endp
;----------------------------------------------------
search_a proc near
push cx
push si
lea di,table2
mov bx,0
mov ch,0
mov cl,table+1
cld
comps: repnz scasb
jnz exit ;没找到退出
inc bx ;否则,记数器加1
sub dx,dx ;置零标志为0
loop comps ;循环记数
exit:
pop si
pop cx
ret
search_a endp
;------------------------------------------------------
code ends
;******************************************************
end start
下面是偶编的一个程序,可是在显示次数时总是出现乱码,不知道为什么,下面附上原程序:
;****************************************************
data segment
table db 30,0,30 dup(?)
data ends
;****************************************************
extra segment
table2 db 30 dup(?)
extra ends
;****************************************************
code segment
;----------------------------------------------------
main proc far
assume cs:code,ds:data,es:extra
start:
mov ax,data
mov ds,ax
mov ax,extra
mov es,ax
lea dx,table ;read string
mov ah,0ah
int 21h
sub ch,ch ;cx<=character number
mov cl,table+1
mov si,offset table ;make si point the string
add si,2
push si
push cx
lea di,table2
cld
rep movsb
pop si
pop cx
dispchar: sub dx,dx
mov dl,[si] ;output char
mov ah,2
int 21h
mov al,dl
call search_a
mov dl,20h ;output space
mov ah,2
int 21h
add bx,30h
mov dl,bl
mov ah,2
int21h
mov dl,20h ;output space
mov ah,2
int 21h
inc si
loop dispchar
mov ax,4c00h
int 21h
main endp
;----------------------------------------------------
search_a proc near
push cx
push si
lea di,table2
mov bx,0
mov ch,0
mov cl,table+1
cld
comps: repnz scasb
jnz exit ;没找到退出
inc bx ;否则,记数器加1
sub dx,dx ;置零标志为0
loop comps ;循环记数
exit:
pop si
pop cx
ret
search_a endp
;------------------------------------------------------
code ends
;******************************************************
end start