I'm having trouble with my assembly language code.
We were asked to prompt user for input string and we're supposed to display it again or echo it to the command line. We need to assume that it's only up to 20 characters (in the string)
This is the sample output:
Enter a string (max 20 char.)
012345678901234567890
The string you entered is:
012345678901234567890
When I run my code in DOSBOX, I enter: 0123456789 After hitting enter it shows me a bunch of characters and symbols that look weird...
Here is my code:
.186
data segment
message1 db "Enter a string (max 20 char.): " ,13, 10, '$'
message2 db "The string you entered is: " , 13, 10, 'S'
myBStr db 20, 21 dup(?) ,'S'
data ends
stack1 segment stack
db 100 dup(?) ; This is the stack of 100 bytes
stack1 ends
code segment
assume cs:code, ds:data, ss:stack1
start:
mov ax, data
mov ds, ax
mov ax, stack1
mov ss, ax
lea dx, message1 ;load message to dx
mov ah, 9h ;show this message
int 21h
mov ah, 0Ah
lea dx, myBStr ;Load address of string
int 21h
mov ah, 9h ; show message of entered string
int 21h
lea dx, message2 ;load second message to dx
mov ah, 9h ;show this message
int 21h
mov ah, 0Ah
lea dx, myBStr ;Load address of string
int 21h
mov ah, 4ch ;Set up code to specify return to dos
int 21h
code ends
end start
'S'where you should have'$'when you try to print out myBstr at the end you use the wrong interupt number. You use0ahand it should be09hfor output. As well the string really starts atmyBstr+2, notmyBstrsince the first 2 bytes are for the input interrupt call. You should skip over the two bytes when outputting. At the bottom changelea dx, myBStrtolea dx, [myBStr+2]myBStr db 20, 21 dup(?) ,'S'tomyBStr db 20, 22 dup('$')