News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

[new question] string processing

Started by JayJay, December 14, 2011, 08:00:32 PM

Previous topic - Next topic

jj2007

Quote from: donkey on December 16, 2011, 02:37:06 AMYou can put it anywhere as long as it is not addressed before being declared (MASM limitation, GoAsm does not care),  however to make sure that the processor does not try to execute it you must jump over it using a JMP instruction.

Another convenient place is just before the proc:
include \masm32\include\masm32rt.inc

.code
start: call MyTest
exit

mText db "The text", 0
mTitle db "The title", 0
MyTest proc
invoke MessageBox, 0, addr mText, addr mTitle, MB_OK
ret
MyTest endp

end start


By the way, JWasm allows forward references, too - a source of trouble if you use JWasm by default and want to remain compatible with Masm :wink

clive

But the issue to be addressed is how to keep the names local to the procedure, which MASM 6.xx only does for "foo:" references not "foo db ?" ones.

JayJay is asking for locally scoped strings, without using the stack/LOCAL, with the possibility of using the same name in multiple procedures for different data.
It could be a random act of randomness. Those happen a lot as well.

FORTRANS

Quote from: clive on December 16, 2011, 02:37:08 PM
But the issue to be addressed is how to keep the names local to the procedure, which MASM 6.xx only does for "foo:" references not "foo db ?" ones.

JayJay is asking for locally scoped strings, without using the stack/LOCAL, with the possibility of using the same name in multiple procedures for different data.

Hi,

   Well, if the name is local, and you want it global, you have a
problem of sorts, correct?  A possible way out is indirect addressing
with a pre-defined pointer to a string?  Like maybe;

.DATA
StringPointer   DD      ?
NullString      DB      "Null!",0
.CODE

PROC    SomeWhere

        MOV     StringPointer,OFFSET Foo

; Code that calls another procedure that wants the local string.
        CALL    Bar
; ...

; Then reset the pointer after usage.

        MOV     StringPointer,OFFSET NullString
        RET

Foo:
        DB      "This is a local string.",0

ENDP


   Seems a bit contrived though.

Regards,

Steve N.

jj2007

Quote from: clive on December 16, 2011, 02:37:08 PM
But the issue to be addressed is how to keep the names local to the procedure, which MASM 6.xx only does for "foo:" references not "foo db ?" ones.

To complicate things further: This assembles fine...

include \masm32\include\masm32rt.inc

.code
start: call MyTest
exit

MyTest proc
jmp @F
mText:
db "The text", 0
@@:
invoke MessageBox, 0, offset mText, 0, MB_OK
ret
MyTest endp

MyTest2 proc
jmp @F
mText:
db "The text", 0
@@:
; invoke MessageBox, 0, offset mText, 0, MB_OK
ret
MyTest2 endp

end start