I am trying to new line after each while_loop. For example I input "cat" it will print 'catcatcatcatcat..." not cat/ncat/n... like in python. I am stuck at this It would be a pleasure if you can point me at the right path or way Thanks in advance
code that I have tried inserting:
MOV dl, 10 MOV ah, 02h INT 21h MOV dl, 13 MOV ah, 02h INT 21h
The code:
.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
CodePudding user response:
You didn't tell your program that you want a new line after each while_ loop.
When you input the string dog, the memory at buff contains 1A 03 64 6F 67 0D 00 00
and after your manipulations it is 1A 03 64 6F 67 24 00 00
.
New line is DOS is provided by CR LF, buff should be like 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.
CodePudding user response:
Your code sucks just insert the MOV dl, 10 MOV ah, 02h INT 21h MOV dl, 13 MOV ah, 02h INT 21h
before ;capture string from keyboard. thank me later