Can't use putstr with getstr in assembly?

heymrdj

Diamond Member
May 28, 2007
3,999
63
91
Code:
  .MODEL SMALL
  .586
  .STACK 100h
INCLUDE  PCMAC.INC
 
  .DATA
Prompt1  DB 'Enter your name:$'
Prompt2  DB 'Your name is:$'
MAXCHAR  EQU 30
GetStruct DB MAXCHAR
GetCnt  DB ? 
Buffer  DB MAXCHAR DUP (?)
  .CODE
Display  PROC
  _Begin
  _PutStr Prompt1
  _GetStr GetStruct
  _putCh 10
  _PutStr Prompt2
  _Putstr Buffer
Display  ENDP
  END Display

This is Assembly code, written in Masm 6.15

This generates line after line of trash from the memory (as there is no delimiter initiated). Any way to get the '$' in there so I can putstr and getstr?
 

Cogman

Lifer
Sep 19, 2000
10,283
134
106
putstr goes until it hits a 0. you need to change Prompt1 and prompt2 to

Code:
Prompt1  DB 'Enter your name:$', 0
Prompt2  DB 'Your name is:$', 0
 

heymrdj

Diamond Member
May 28, 2007
3,999
63
91
putstr goes until it hits a 0. you need to change Prompt1 and prompt2 to

Code:
Prompt1  DB 'Enter your name:$', 0
Prompt2  DB 'Your name is:$', 0

I wasn't aware of this. I thought the $ symbol stops the reading. I'll give it a try in a bit when I get a moment to try.
 

heymrdj

Diamond Member
May 28, 2007
3,999
63
91
I wasn't aware of this. I thought the $ symbol stops the reading. I'll give it a try in a bit when I get a moment to try.


Nope this didn't work. With all the forum downtime I haven't been able to get in a reply.

Here's a screenie.

masma.jpg
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Try pre-zeroing the buffer into which you are GetStr-ing. bzero ought to do it, if you can get to that from MASM.

EDIT: Fully zero GetStruct before passing to to GetStr. My thought is that your input string 'Casey' isn't null-terminated, so when you print it, you print junk until you hit a zero, as cogman pointed out can happen.
 
Last edited:

heymrdj

Diamond Member
May 28, 2007
3,999
63
91
I left off Exit 0....i'm going to shoot myself now.

Thanks for the help guys :p.
 

coldm

Junior Member
Oct 4, 2014
1
0
0
I left off Exit 0....i'm going to shoot myself now.

Thanks for the help guys :p.

Sorry for the massive bump, I realize this post it years old, but I was wondering if someone could post the fix for this please. I think the OP is still active, help would be greatly appreciated, otherwise I apologize. I would have Just tried to PM the OP but I need a minimum of 25 posts.
 

heymrdj

Diamond Member
May 28, 2007
3,999
63
91
I don't know if I still have the original code or not, as it was certainly made years ago :). I'm not sure where exactly I was missing exit 0. I haven't coded in assembly since about that year either.