|
-
February 8th, 2006, 10:35 PM
#1
input and output strings
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...
Last edited by quicksilver_1931; February 9th, 2006 at 05:25 AM.
Reason: placing an icon
-
February 15th, 2006, 07:33 PM
#2
Re: input and output strings
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.
 Originally Posted by quicksilver_1931
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
-
December 11th, 2006, 05:34 PM
#3
Re: input and output strings
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|