Well I got a class assignment requiring the use of int 21h,0xa(string input).

The problem is the teacher is old, and doesn;t care about how right the things he teaches are and apparenlty he taught us things wrongly again -.- then it;s -15 points in the exam...

He taught us the first number we enter (followed by enter) is the size and it enters in the first byte,then we enter the string and any extra characters are thrown away, he said it automatically places an $ at the end (after I asked him if I need to add that somehow)...
But anyway it simply doesn;t work.

Sorry I just had to say that >.<;

Back to topic:
That's my string declaration:

string db 4,?,dup('$')

I copied it from someplace, I think it places in the first byte 4 which stands for the size ,at the second ?, no idea why '?' but that;s what I copied, and then the rest would b '$'s..

I dunno if I got it right but when I wanna enter something it lets me enter 3 characters...So I dun quite get how it works at all, and am confused what sits in which byte.

All I wanna do is get a string at the size of 18 and print it, that's all...

Actually the assignment asked to print the string backwards (a-z would b printed as z-a)
and print the number of times a appears and number of times 'ab' appears...
These are easy for me (the logic), I just can;t input and output the string o.o;

That';s what I wrote:

xor ax,ax 
lea dx,string  
mov ah,0xA
int 21h

mov ah,9h  
mov dx,offset string[2]
int 21h

Ok so I dun quite get how the input works and I know my output is bad as well, since it doesn;t work....

Any help would b grately appreciated.

7 Years
Discussion Span
Last Post by UtaChan

If you look at this link you will see that the first two bytes of the input buffer contain the buffer size followed by the number of characters in the buffer when the interrupt returns. You have to declare the buffer to be at least three bytes larger than the number of characters you want the user to enter, more is better just in case the user decides to enter more than what you are expecting.


How do I write it then?
I mean input a string then output it.
It still doesn;t wrok for me


>>string db 4,?,dup('$')

I think that should be string db 4,?,4 dup('$') The first 4 is what is stored in the first byte, the ? says the second byte just contains whatever is already in the storage location, then the 4 dup('$') says to create 4 more bytes and fill each one with '$' character. If you want to enter more than 4 characters then replace 4 dup('$') with the number of characters you want to enter plus one more for the '\n' enter key. I would add another 2 or 3 bytes for good measure.

See this link on how to declare variables in assembly language


Thanks it works :3
The problem is if I let the user enter characters all the way he will over-write the $, so I will just manually add it after teh 18th char since I was asked to make it 18 char length or less.

Thanks for the help ^^

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.