Reputation: 3360
Hey I have started learning assembly language
.
I wrote the following code:
.MODEL SMALL
.STACK 1000H
.DATA
MSG db "Hey$"
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
MOV AH,0AH ; setting the sub function
MOV DX, offset msg ; moving address of msg to dx
INT 21h ; calling interrupt
MOV AH, 09
MOV DX, OFFSET MSG
INT 21h ; for printing
MOV AH, 04Ch ; Select exit function
MOV AL, 00 ; Return 0
INT 21h ; Call Interupt to Terminate program
MAIN ENDP
END MAIN
I am trying to take input, it is working kind of but when I try printing it I do not get the proper string. I used this list to select the interrupt function.
I am attaching a screenshot, I have given input the following string:
Hey this is me taking input
But I got unexpected result.
Screenshot:
Thanks.
Upvotes: 1
Views: 1323
Reputation: 194
http://www.skynet.ie/~darkstar/assembler/intlist.html
Note: With "db Size dup (0)" we can occupy the value of Size amount of bytes.
.MODEL SMALL
.STACK 10H
Size = 3
.DATA
M1 db Size ; First character=max length
M2 db ? ; Second char of buffer=length of input
MSG db Size dup (20H) ; Rest of buffer=input string
db 0DH ; followed by carriage return (0Dh)
;---
db "$" ; (allways needed for printing function)
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
MOV AH,0AH ; setting the sub function
MOV DX, offset M1 ; moving address of input buffer
INT 21h ; calling interrupt
MOV AH, 09
MOV DX, OFFSET MSG
INT 21h ; for printing
MOV AH, 04CH ; Select exit function
MOV AL, 00 ; Return 0
INT 21h ; Call Interupt to Terminate program
MAIN ENDP
END MAIN
Upvotes: 0
Reputation: 49805
You didn't set aside enough space for your input string; when you "declared" MSG
, you gave it room for only 4 characters ("Hey$"
).
Upvotes: 0