Hi. I am aware that this board is intended for 32-bit ASM development, but I am a beginner and am learning out of a book that does DOS-based 16-bit ASM. My code is probably pretty simple to most all of you.
My applications goal is that it simply loops and gets user input up to 60 characters (or when the user hits Enter) and stores it in allocated memory. Then, it should add an exclamation point to their string when they finish (as well as an end-string $ marker) and then print it out. The only part that is not working is that it puts the exclamation point overwriting the first character instead of at the end.
Can you please look and tell me why? Thanks!
CR EQU 0DH
LF EQU 0AH
DATA SEGMENT
DB 60 DUP(?)
NEWLINE DB CR,LF,'$'
WELCOME DB 'Welcome to String Saver!',CR,LF,'$'
DATA ENDS
TEMP SEGMENT STACK
DW 100H DUP(?) ; Stack storage
TEMP ENDS
CODE SEGMENT ; Code
ASSUME DS:DATA
ASSUME SS:TEMP
ASSUME CS:CODE
_START:
MOV AX,DATA
MOV DS,AX ; Initialize data segment
MOV BX,0 ; Initialize counter
MOV AH,9
MOV DX,OFFSET WELCOME
INT 21H ; Print welcome
INPUT:
CMP BX,59 ; Check size
JZ PROCESS
MOV AH,1 ; Get a character
INT 21H
MOV BYTE PTR ,AL ; Store in memory
ADD BX,1
CMP AL,CR ; Continue if enter pressed
JNZ INPUT
PROCESS:
MOV BYTE PTR ,'!' ; Append exclamation
MOV BYTE PTR ,'$' ; ...and end $
MOV AH,9 ; String printing
MOV DX,OFFSET NEWLINE
INT 21H ; Print newline
MOV DX,0
INT 21H ; Print stored string
MOV AX,4C00H
INT 21H ; Return to DOS
CODE ENDS
END _START
Thanks!Nevermind!
I was storing the carrage return by accident in the string, so when it printed that sent it back to the beginning of the DOS printout area, to then print the exclamation point. So it seemed that it was putting it as the first character, although it wasn't. Sorry about that!
Try the below code, I think I fixed it for you
I am not sure, cuz I am not sure where your DATA segment
and code segemts start from the info you gave me, so I
took the safe way around that.
CR EQU 0DH
LF EQU 0AH
DATA SEGMENT
NEWLINE DB 60 DUP(?)
WELCOME DB 'Welcome to String Saver!',CR,LF,'$'
DATA ENDS
TEMP SEGMENT STACK
DW 100H DUP(?) ; Stack storage
TEMP ENDS
CODE SEGMENT ; Code
ASSUME DS:DATA
ASSUME SS:TEMP
ASSUME CS:CODE
_START:
MOV AX,DATA
MOV DS,AX ; Initialize data segment
MOV BX,NEWLINE ; Initialize Counter
MOV AH,9
MOV DX,OFFSET WELCOME
INT 21H ; Print welcome
INPUT:
CMP BX,59 ; Check size
JZ PROCESS
MOV AH,1 ; Get a character
INT 21H
MOV BYTE PTR ,AL ; Store in memory
ADD BX,1
CMP AL,CR ; Continue if enter pressed
JNZ INPUT
PROCESS:
MOV BYTE PTR ,'!' ; Append exclamation
MOV BYTE PTR ,'$' ; ...and end $
MOV AH,9 ; String printing
MOV DX,OFFSET NEWLINE
INT 21H ; Print newline
MOV DX,0
INT 21H ; Print stored string
MOV AX,4C00H
INT 21H ; Return to DOS
CODE ENDS
END _START
Hope this helps
Zcoder.....
hutch, i tried to compile the code u have given pellybelly but failed!
There is this error with this line: "MOV BX,NEWLINE ; Initialize Counter"
Hmm. It says that there issomething wrong with this instruction.
So, how do we correct it?
NEWLINE is a byte and bx is a word. Use
xor bx, bx
mov bl, NEWLINE
or
movzx bx, NEWLINE