Reputation: 11
I am trying to take a string as input from my emu 8086 assembler. I want to print the inputted string as output. While printing the string i am getting some funny characters as output along with the input I have given.
What should I do to stop entering input I have tried to terminate the input with a $
sign.
DATA SEGMENT
A DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV AX,DATA
MOV AH,0AH
LEA DX,A
INT 21H
LEA DX,A
MOV AH,9H
INT 21H
CODE ENDS
END START
Upvotes: 1
Views: 2551
Reputation: 39166
A number of problems here.
You forget to setup DS
.
mov ax, DATA
mov ds, ax
You don't quit the program.
mov ax, 4C00h ; DOS.Terminate
int 21h
You don't provide the correct input buffer for the DOS.BufferedInput function 0Ah.
DATA SEGMENT
A db 64, 0, 64 dup (0)
DATA ENDS
I've got a nice explanation of this DOS function here
You don't fetch the string to output where its characters are stored and you don't properly $-terminate it.
lea dx, A+2
mov bx, dx
mov bl, [bx-1] ; Length of the string
mov bh, 0
add bx, dx
mov byte [bx], "$" ; Replace 13 by "$"
mov ah, 09h ; DOS.DisplayString
int 21h
Upvotes: 2
Reputation: 32732
You don't have the buffer for INT 21/0A set up correctly. The byte pointed to by DS:DX
is a maximum byte count to be read, the next byte will hold the number of bytes read, then the string read will be stored starting with the second byte. You'll need something like
A DB 20 ; buffer length
DB 0 ; (return) number of characters read
DB 20 DUP(?)
DB '$' ; extra byte for string termination
To accept up to 20 characters. You'll still need to add the '$' character before calling INT 21/09, and the offset in DX should be A+2 (not A).
Upvotes: 0