rw一下 帮我看一下 这个汇编题为什么不能正确的输出输入的字符?

来源:百度知道 编辑:UC知道 时间:2024/09/21 22:31:45
date segment
sr db 32,0,32 dup('0'),0dh,0ah,'$'
date ends
sta segment stack
dw 100h dup(0)
sta ends

code segment
main proc far
assume cs:code,ds:date
star:
push ds
xor ax,ax
push ax
mov ax,date
mov ds,ax

call oup10
call crlf
call inp
call crlf
call oup10
call crlf
call oup
ret
main endp

inp proc near
lea dx,sr
mov ah,0ah
int 21h

ret
inp endp

oup10 proc near
mov ch,2
mov bh,[sr+1]
cc: mov cl,4
rol bx,cl
mov dl,bl
and dl,0fh
add dl,30h
cmp dl,39h
jl ca
add dl,7h
ca:
mov ah,2
int 21h
dec ch
jnz cc
ret
oup10 endp

oup proc near
mov dx,offset sr
add dx,2
mov ah,9
int 21h
ret <

;输出字符串长度部分,我帮你改为十进制输出
date segment
sr db 32,0,32 dup('0'),0dh,0ah,'$'
date ends
sta segment stack
dw 100h dup(0)
sta ends
code segment
main proc far
assume cs:code,ds:date
star:
push ds
xor ax,ax
push ax
mov ax,date
mov ds,ax
call oup10 ;输出空串长度0
call crlf ;换行
call inp ;从键盘接收一串字符
MOV SI,DX ;保存串首偏移
call crlf ;换行
call oup10 ;输出字符串长度
call crlf ;换行
;用'$'输入字符串尾部的回车符 0Dh
MOV AL,sr+1
MOV AH,0
ADD SI,AX
MOV BYTE PTR [SI+2],'$'
call oup ;输出键入的字符串
MOV AH,0
INT 16H ;暂停
ret ;结束
main endp

inp proc near
lea dx,sr
mov ah,0ah
int 21h
ret
inp endp

oup10 proc near
mov di,ds
push cs
pop ds
LEA DX,Tips ;显示长度Length
MOV AH,9
INT 21h
mov ds,di
mov al,[sr+1];串长送AL
aam ;二化十
xchg ah,al
mov dx,ax