CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2006
    Posts
    3

    Unhappy 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

  2. #2
    Join Date
    Nov 2005
    Posts
    14

    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.


    Quote 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

  3. #3
    Join Date
    Dec 2006
    Posts
    72

    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
  •  





Click Here to Expand Forum to Full Width

Featured