assembly 如何在汇编代码中换行用户打印的字符串?

pokxtpni  于 2022-11-13  发布在  其他
关注(0)|答案(2)|浏览(124)

我尝试在每个while_loop后换行。例如,我输入“cat”,它会输出“catcatcatcatcat...”而不是“cat/ncat/n...”,就像在python中一样。我被困在这里了。如果你能给我指出正确的路径或方法,那将是一件很愉快的事情。提前感谢。
我尝试插入的代码:

MOV dl, 10
MOV ah, 02h
INT 21h
MOV dl, 13
MOV ah, 02h
INT 21h

代码:

.model small
.stack 100h
.data
buff db  26        ;MAX NUMBER OF CHARACTERS ALLOWED (25).
     db  ?         ;NUMBER OF CHARACTERS ENTERED BY USER.
     db  26 dup(0) ;CHARACTERS ENTERED BY USER.
.code
main:
mov ax, @data
mov ds, ax              

;CAPTURE STRING FROM KEYBOARD.                                    
mov ah, 0Ah ;SERVICE TO CAPTURE STRING FROM KEYBOARD.
mov dx, offset buff
int 21h
                     

;CHANGE CHR(13) BY '$'.
mov si, offset buff + 1 ;NUMBER OF CHARACTERS ENTERED.
mov cl, [ si ] ;MOVE LENGTH TO CL.
mov ch, 0      ;CLEAR CH TO USE CX. 
inc cx ;TO REACH CHR(13).
add si, cx ;NOW SI POINTS TO CHR(13).
mov al, '$'
mov [ si ], al ;REPLACE CHR(13) BY '$'.
                     

;DISPLAY STRING.                   
mov ah, 9 ;SERVICE TO DISPLAY STRING.
mov dx, offset buff + 2 ;MUST END WITH '$'.
int 21h

;LOOPING 10x
mov cx, 11
while_:
dec cx
jz end_while
mov ah, 9
int 21h
jmp while_
end_while:
exit:
mov ah, 4ch
int 21h

end main
ljo96ir5

ljo96ir51#

你没有告诉你的程序,你希望在每个 while_ 循环后都有一个新的行。当你输入字符串dog时,在buff的内存中包含1A 03 64 6F 67 0D 00 00,在你的操作后它是1A 03 64 6F 67 24 00 00
新的一行是DOS由CR+LF提供,buff应该像1A 03 64 6F 67 0D 0A 24

;CHANGE CHR(13) BY '$'.
mov si, buff + 1  ;NUMBER OF CHARACTERS ENTERED.
mov cl, [ si ]    ;MOVE LENGTH TO CL.
mov ch, 0         ;CLEAR CH TO USE CX. 
inc cx            ;TO REACH CHR(13).
add si, cx        ;NOW SI POINTS TO CHR(13).

; Insert the following four lines here:
INC SI          ; To reach CHR(10).
MOV AL,10       ; LineFeed character
MOV [SI],AL     ; Store LF after CR.
INC SI          ; To reach '$' terminator.

mov al, '$'
mov [ si ], al  ; Append CHR(10) BY '$'.
;DISPLAY STRING.
sczxawaw

sczxawaw2#

你的代码很烂,只是在前面插入了MOV dl, 10 MOV ah, 02h INT 21h MOV dl, 13 MOV ah, 02h INT 21h;从键盘捕获字符串.稍后谢谢我

相关问题