Click to See Complete Forum and Search --> : input and output strings


quicksilver_1931
February 8th, 2006, 09:35 PM
hi, can someone please help me in my program. I'm new to the debug.com environment and our prof are lame in teaching it.

I would like to create a program where i can input a string(like my name) (Please enter your name) and the output would be (hello (my name) )

here is the code that i make, but i feel like something is missing, kindly please help me.

a200
db 0d,0a,"Please enter your name: $"

a300
db 0d,0a,"Hello $"

a100
mov ah,09
mov dx,200
int 21

mov ah,0a
int 21

mov ah,09
mov dx,300
int 21
int 20

i want the program to be:
Please enter your name: mark
Hello mark!

*I know something is missing in the string input but i don't know what.. Help please...

The GS Man
February 15th, 2006, 06:33 PM
You need a buffer where the input can be both stored and printed - which means that you may also need to add some code that appends a "$" to the end of the input string if you use code 09 to output the name.



a200
db 0d,0a,"Please enter your name: $"

a300
db 0d,0a,"Hello $"

a100
mov ah,09
mov dx,200
int 21

mov ah,0a
int 21

mov ah,09
mov dx,300
int 21
int 20

iviggers
December 11th, 2006, 04:34 PM
There are two points in your code.

a) DOS 0ah function reserves the first 2 bytes of buffer for information about its available and actual lengths. If you want to use this function, you must to add 2 to dx register; otherwise there will be some strange chars at console.
My favorite way is using 3fh instead (see code below).

b) Print the actual buffer after writing "Hello " at the end.


The following code must work:

a200
db 0d,0a,"Please enter your name: $"

a300
db 0d,0a,"Hello $"

a100
mov ah,09
mov dx,200
int 21

;; DOS 0ah function replacement
;mov ah,0a
;int 21
mov ah,3fh
mov bx,0 ; handler for standard input (keyboard)
mov cx,80 ; catch at most 128 chars
mov dx,200 ; or wherever you want to store bytes
int 21

;; Insert '$' so console doesn't "go crazy" printing extra chars ...
;; anyway missing in your code
add dx,ax ;add actual input-length
mov di,dx
mov al,'$'
stosb

mov ah,09
mov dx,300
int 21

;; print actual buffer, so you get the "Hello Kitty" (or any other cool name)
mov ah,09
mov dx,200
int 21
int 20

Good luck