0 Replies - 411 Views - Last Post: 03 October 2017 - 03:38 AM

#1 Tony09101  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 16-September 16

MASM How to prompt user for string, then display it back (echo)

Posted 03 October 2017 - 03:38 AM

Hello all, I'm in the process of trying to write a program that prompts a user for a string, then after the user enters a string, it will be outputted back. So far whenever I try testing it in masm, after being prompted to enter a string, I get "X" duplicated 32 times followed by my prompt message again. Why is this happening? Do I need to use the JMP command somewhere? Here is my code so far...

 ;Test #1 ASM in DOS ... In 2014!

.MODEL SMALL            ; Assembler directive specifying the segment model for the generated code

.STACK 4096             ; Setup 4096 byte stack segment


;--------.DATA Assembler directive specifying following is part of "data" segment -------
.DATA 

MAX_LEN			DB			32					;Maximum length of following buffer
ACT_LEN			DB			?					;Actual length stored in buffer
STR_DATA		DB			32 DUP('X')			;Storage buffer for string data
PROMPT			DB			"Enter a string: $"


;----- .CODE is an assembler directive indicating the following source is part of the "code" segment -----
.CODE

MAIN    PROC

        ; .STARTUP Macro simplified setting up segments, which identify the memory reserved for code, data, and stack.
        .STARTUP

        NOP                             
        NOP
                                        

		;Print prompt
		MOV AH, 9						;AH = 9 ==> DOS PRINT $ svc
		MOV DX, OFFSET PROMPT			;DS:DX ==> Addr of string
		INT 21h
		
		;Input the string
		MOV AH, 0AH						;DOS input string service
		MOV DX, OFFSET MAX_LEN			;DS:DX pointer to formatted
		INT 21h
		
		;Print the user's string
		MOV AH, 9
		MOV DX, OFFSET MAX_LEN
		INT 21h

        
        ; ---- .EXIT Macro works as a reverse to .STARTUP, ensuring proper return to the operating system.
        .EXIT           
        
MAIN    ENDP


; ---------- DON'T FORGET THE END AT... the end.  Seriously ----------
END



Is This A Good Question/Topic? 0
  • +

Page 1 of 1