3

I've been searching the internet for a good while for this but none of them help me in my solution. What I'm trying to achieve is to read user input and display it starting from a prompt.

For example, the prompt asks the user's age and the user inputs their age, and then the program outputs the user's age in the console. Here is what I have so far:

INCLUDE Irvine32.inc
.data
    prompt_name BYTE "Enter your name: ", 0 
    MAX = 80
    name BYTE (MAX + 1) DUP (?)
    
.code
main PROC
    
    ;----------------------------------
    call Clrscr
    mov edx, OFFSET prompt_name
    call WriteString

    mov edx, OFFSET name
    mov ecx, SIZEOF name
    call ReadString
    mov edx, OFFSET name
    call WriteString
    ;----------------------------------
    exit
main ENDP
END main

I've tried to change the DUP(?) to DUP(0). I've tried multiple solutions from other similar questions but it always give me the same error: Syntax error for lines mov edx, OFFSET name and mov ecx, SIZEOF name. I've also tried mov ecx, MAX as described in the library but to no avail. I would appreciate any advice, thanks!

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Vince
  • 109
  • 2
  • 9
  • 1
    Does it work if you simply use `name BYTE 81 DUP (?)` – Jester Nov 11 '20 at 22:30
  • @Jester I've tried that before and it doesn't work either. I'll try it again real fast. Edit: no it doesn't work still. – Vince Nov 11 '20 at 22:34
  • 1
    `name` might be a reserved word, try a different label name like `foo` or `mybuf`. Or maybe `MAX` is a reserved word, if MASM lets you use `MAX(foo,bar)` in expressions? – Peter Cordes Nov 12 '20 at 02:58
  • @PeterCordes can't believe I didn't try to change the variable name. ```name``` is indeed a reserved keyword. I would have never guess that. Post it as an answer so I can mark it? Thanks a lot! – Vince Nov 12 '20 at 03:25
  • 1
    Turns out I didn't have to. Once we knew that was the answer, google for `site:stackoverflow.com masm reserved word "name"` found a nice detailed answer to a question whose very title answers this :P And another question that had this exact problem (so the answer is answer in the answer, not title, and is an exact duplicate). – Peter Cordes Nov 12 '20 at 03:28
  • @PeterCordes Glad you helped. Too bad I'm question blocked now :( haha thanks again – Vince Nov 12 '20 at 03:38
  • 1
    Really? I didn't know closing as a duplicate counted the same as other close reasons. It shouldn't be blocked for too long, this didn't get any downvotes, and doesn't deserve any. – Peter Cordes Nov 12 '20 at 03:49
  • @PeterCordes Yeah I hope so. I try to do a lot of googling before posting questions and word them well but I've been getting post blocked a decent amount. – Vince Nov 12 '20 at 03:56
  • 2
    I made an edit to the title that justifies an upvote, hopefully that should help. `name` being reserved is a fairly non-obvious thing, so maybe this Q&A will be a useful signpost for future readers. Your text at the bottom saying exactly which lines gave syntax errors were useful for seeing the exact problem and guessing the answer, so nice job on writing a question. – Peter Cordes Nov 12 '20 at 04:07

0 Answers0