What does "undefined symbol: stringread" mean?

58 Views Asked by At

I'm working on a big project for my college class.

I put a string/array in the .data section like this:

stringread BYTE DUP(STRSIZE)

And in main I have:


push OFFSET stringread
push esi
call ReadFileLine
pop esi
pop OFFSET stringread

But I get this error:

undefined symbol: stringread

I think my problem is that I didn’t declare the string correctly.

At first I thought maybe I wasn’t allowed to push strings directly onto the stack like that, but I looked at my professor's example code and he had something similar:

array DWORD 1,2,3,4,5
push OFFSET array

EDIT: I replaced the declaration with this, which seems to have fixed it:

stringread BYTE STRSIZE DUP(?)
1

There are 1 best solutions below

0
Sep Roland On BEST ANSWER
stringread BYTE DUP(STRSIZE)

For MASM this line is syntactically wrong. As a consequence what would normally be considered a label, didn't get recognized that way and so the symbol stringread was reported 'undefined' once you used it on the line push OFFSET stringread in main.
The DUP operator needs to be told how many duplications you need. Looking at DUP(STRSIZE) it would seem that you erroneously have placed the repeat count between the parenthesis. One solution could be:

stringread BYTE STRSIZE DUP(0)
push OFFSET stringread
push esi
call ReadFileLine
pop esi
pop OFFSET stringread

OFFSET stringread is a so-called 'immediate' aka just a number. While you can push an immediate, you can not pop an immediate!
You can remove the pushed value either through

  • adding to the stackpointer add esp, 4
  • or popping to a register that you can scratch, like eg. pop edx