News:

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

error A2041: string or text literal too long

Started by tron, January 20, 2005, 11:48:25 AM

Previous topic - Next topic

tron

let me give a short introduction into what I'm trying to accomplish here :p

basically i have a custom structure setup that has string data members. i would like to be able to initialize the structure from within the ".data" section.

my code looks like this:

Quote
.data

Option   OptionSTRUCT {\
                         "Test",0,
                    "string longer then 255 characters"\
                       }

I'm aware you can normally get around the error by doing something like:

Quote
String db "MoooooooooMoooooooooMoooooooooMoooooooooMooooooooo" ;50
       db "MoooooooooMoooooooooMoooooooooMoooooooooMooooooooo" ;50
       db "MoooooooooMoooooooooMoooooooooMoooooooooMooooooooo" ;50
       db "MoooooooooMoooooooooMoooooooooMoooooooooMooooooooo" ;50
       db "MoooooooooMoooooooooMoooooooooMoooooooooMooooooooo" ;50
       db "MoooooooooMoooooooooMoooooooooMoooooooooMooooooooo" ;50
       db "MoooooooooMoooooooooMoooooooooMoooooooooMooooooooo" ;50
       db "MoooooooooMoooooooooMoooooooooMoooooooooMooooooooo" ;50
       db "MoooooooooMoooooooooMoooooooooMoooooooooMooooooooo" ;50
       db "MoooooooooMoooooooooMoooooooooMoooooooooMooooooooo" ;50
       db "MoooooooooMoooooooooMoooooooooMoooooooooMooooooooo",0 ;50


the problem I'm running into is the string length and the fact that I'm unable to declare data for one member of the structure on multiple lines.


any help is appreciated :D please excuse my inexperience

Tedd

#1
There's an inherent line limit, so if you have a line longer than this you'll get a complaint - even if it's spanned on multiple lines with \
I don't see any way around it other than splitting across lines with multiple db statements.
Why can't you do this?
If it's for getting the length of the string, then you can get around this by doing the following:


.data
reallyreallylongstring  db "this string is..."
    db "really very long..."
    db "so long that it has to be spread across many statements",0
FUNFUNFUN equ $-OFFSET reallyreallylongstring


and then use FUNFUNFUN where want the length of the string
No snowflake in an avalanche feels responsible.

tron

Quote from: Tedd on January 20, 2005, 01:15:15 PM
There's an inherent line limit, so if you try a line longer than things you'll get a complaint - even if it's spanned on multiple lines with \
I don't see any other way around it than splitting it across lines with multiple db statements.
Why can't you do this?
If it's for getting the length of the string, then you can get around this by doing the following:


.data
reallyreallylongstring  db "this string is..."
    db "really very long..."
    db "so long that it has to be spread across many statements",0
FUNFUNFUN equ $-OFFSET reallyreallylongstring


and then use FUNFUNFUN where want the length of the string


maybe you missed the point of the post ... as far as i know you cant split data member declarations across multiple lines with db statements.

Tedd

Aah right, sorry, got it now.
All I can suggest is redefining the structure?
So that you can define the string in separate parts - though it is somewhat annoying.
Or defining the data simply as separate strings/data, but treat the first label as if it was for an actual structure instance ("assume" works okay with this.)
No snowflake in an avalanche feels responsible.

Ratch

#4
tron,

     Try this.  It defines a 300 byte STR1 on one line.  Ratch


S1 EQU 'MoooooooooMoooooooooMoooooooooMoooooooooMooooooooo'
ALPHA STRUC
  BYTE 'TEST',0
  STR1 BYTE S1,S1,S1,S1,S1,S1,0
ALPHA ENDS

tron

Quote from: Ratch on January 20, 2005, 10:42:44 PM
tron,

     Try this.  It defines a 300 byte STR1 on one line.  Ratch


S1 EQU 'MoooooooooMoooooooooMoooooooooMoooooooooMooooooooo'
ALPHA STRUC
  BYTE 'TEST',0
  STR1 BYTE S1,S1,S1,S1,S1,S1,0
ALPHA ENDS


although this works unfortunately the string of data is not going to be a constant that i can just repeat over and over again. not to mention that this is actually a structure prototype and not an initialization of a structure. that code that i gave was just an example of getting around the limitation when you're declaring a variable, as i said before i don't know of a way to span the declaration of a data member onto multiple lines.

Ratch

tron,

     I believe that myself and others are confused about what you want to do.  I showed you how to put a long data declaration on one line.  Why are you insisting on doing it over several lines?  Perhaps you should code something up to demonstrate what you want to do even if the code does not assemble correctly.  Then perhaps we can help you.  Ratch

tron

Quote from: Ratch on January 21, 2005, 05:15:53 AM
tron,

     I believe that myself and others are confused about what you want to do.  I showed you how to put a long data declaration on one line.  Why are you insisting on doing it over several lines?  Perhaps you should code something up to demonstrate what you want to do even if the code does not assemble correctly.  Then perhaps we can help you.  Ratch

masm has a string limit of 255 characters the only way i know how to get around it is to span the declaration across multiple lines. that being said in your example you're defining a structure prototype..... i don't need help with that aspect of the structure i could in fact achieve the same thing you did by using dup(?) in the structure prototype.

I'm trying to initialize the structure with a string greater than 255 characters heres a code sample as you requested

QuotePROFILE       STRUCT
  item1         db        500 dup(?)     
  item2         db        500 dup(?)
PROFILE       ENDS

.data
Profile001 PROFILE {"string1","string2"}

in this example i've declared Profile001 is a structure of type PROFILE and the first and second variables in the structure now hold the values "string1" "string2".
now heres the question one more time ( I've made everything as clear as possible )

how could i initialize a PROFILE structure with a string that is longer then 255 characters ? keep in mind masm has a 255 character string limit and the ONLY way i have found to get around this is spanning a string declaration across multiple lines.

Tedd

This works.
(Maybe a little annoying, but it's a way around it - could probably be cleaned up with a macro or two, at least for the padding)


;**********************************************************************************************************

PROFILE       STRUCT
  item1         db        500 dup(?)     
  item2         db        500 dup(?)
PROFILE       ENDS

;**********************************************************************************************************

.data
Profile001 equ $    ;not defined as a PROFILE structure, but that doesn't mean you can't use it like one anyway
  ;--- item1 ---
    db "string1 is.."
    db "..........very long",0
  ;PADDING - to fill rest of string
    db Profile001+(OFFSET PROFILE.item1)+(SIZEOF PROFILE.item1)-$ dup (0)

  ;--- item2 ---
    db "and so is ................."
    db "string2",0
  ;PADDING
    db Profile001+(OFFSET PROFILE.item2)+(SIZEOF PROFILE.item2)-$ dup (0)
;end of 'structure'

.code
start:
    push ebx
    mov ebx,OFFSET Profile001
    assume ebx:ptr PROFILE

    lea eax,[ebx].item1
    ;blah
    ;etc

    assume ebx:nothing
    pop ebx
    invoke ExitProcess, NULL
end start

No snowflake in an avalanche feels responsible.

Ratch

#9
tron,
     OK, now that I know what you are trying to do, I believe I found a solution.  The example shows a reference of 600 and 700 into a 750 byte string defined over three lines. I tested it and it works.  See the code below.  Ratch


S1 EQU MoooooooooMoooooooooMoooooooooMoooooooooMooooooooo
S2 CATSTR <'>,S1,S1,S1,S1,S1,<'>

ALPHA STRUC
  BYTE 'TEXT',0
ADR$1 = $
  BYTE S2
  BYTE S2
  BYTE S2
ALPHA ENDS

.DATA
DWORD 10 DUP 1

BETA ALPHA {}

.CODE
MAIN:
MOV AL,[BETA+ADR$1+600]

EASY EQU BETA+ADR$1

MOV AL,[EASY+700]

END MAIN

tron

I want to initialize the structure in the .data section with a long sting greater than 255 characters. the string is not a short constant repeated over and over its a string of more than 255 unique characters.


I have no idea how else to explain my self, thanks to all who tried to help me.

Ratch

tron,
     No problem, see below.  Ratch


S1  EQU 'Once upon a midnight dreary, while I pondered, weak and weary,'
S2  EQU 'Over many a quaint and curious volume of forgotten lore,'
S3  EQU 'While I nodded, nearly napping, suddenly there came a tapping,'
S4  EQU 'As of someone gently rapping, rapping at my chamber door.'
S5  EQU 'Tis some visitor, I muttered, tapping at my chamber door'
S6  EQU 'Only this, and nothing more. -- The Raven by EDGAR ALLEN POE 1845'

ALPHA STRUC
  BYTE 'TEXT',0
ADR$1 = $
  BYTE 62 DUP (?)
  BYTE 56 DUP (?)
  BYTE 62 DUP (?)
  BYTE 57 DUP (?)
  BYTE 56 DUP (?)
  BYTE 65 DUP (?)
ALPHA ENDS

.DATA
  DWORD 10 DUP (1)
  BETA ALPHA {,S1,S2,S3,S4,S5,S6}

  .CODE
  MOV AL,[BETA+ADR$1+260]  260th byte into string

EASY EQU BETA+ADR$1

  MOV AL,[EASY+380]  380th byte into string

Relvinian

Another thing you can do instead of trying to use the .DATA section for large strings is to have the strings in a resource file (.RC) and use the API LoadString() to get them out of the resource.

This has both advantages and drawbacks.

Relvinian

tron

Quote from: Ratch on January 21, 2005, 10:30:30 PM
tron,
     No problem, see below.  Ratch


S1  EQU 'Once upon a midnight dreary, while I pondered, weak and weary,'
S2  EQU 'Over many a quaint and curious volume of forgotten lore,'
S3  EQU 'While I nodded, nearly napping, suddenly there came a tapping,'
S4  EQU 'As of someone gently rapping, rapping at my chamber door.'
S5  EQU 'Tis some visitor, I muttered, tapping at my chamber door'
S6  EQU 'Only this, and nothing more. -- The Raven by EDGAR ALLEN POE 1845'

ALPHA STRUC
  BYTE 'TEXT',0
ADR$1 = $
  BYTE 62 DUP (?)
  BYTE 56 DUP (?)
  BYTE 62 DUP (?)
  BYTE 57 DUP (?)
  BYTE 56 DUP (?)
  BYTE 65 DUP (?)
ALPHA ENDS

.DATA
  DWORD 10 DUP (1)
  BETA ALPHA {,S1,S2,S3,S4,S5,S6}

  .CODE
  MOV AL,[BETA+ADR$1+260]  260th byte into string

EASY EQU BETA+ADR$1

  MOV AL,[EASY+380]  380th byte into string



I see and this is filling multiple data members I demonstrated in my code example that I'm filling one data member with a long string. I'm fairly certain at this point its not possible  to initialize ONE data member with a long sting. at this point I think I'll just figure something else out, thanks again.

Peterpan

Tron,

Another idea. How about using an offset/pointer in the structure ?
Something like this:

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

.486
.model flat, stdcall
option casemap :none   ; case sensitive

   include \masm32\include\windows.inc
   include \masm32\include\kernel32.inc
   include \masm32\include\user32.inc

   includelib \masm32\lib\kernel32.lib
   includelib \masm32\lib\user32.lib

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

PROFILE       STRUCT
  item1         LPSTR   ?
  item2         LPSTR   ?
PROFILE       ENDS

.Const
   Str1  db 'Header of the string2 1234567890 1234567890 1234568790 1234567890 ',13
         db 'This message is longer than 255 chars, this is the first line',13
         db 'This is the 2nd line, just testing',13
         db 'This is the 3rd line, just testing only',13
         db 'This is the 4th line, whatever ...........',13
         db 'This is the 5th line, sdfsd sdf ',13
         db 'This is the 6th line',13
         db 'This is the 7th line',13
         db 'string3 1234567890 1234567890 1234567890 1234567890 1234568790 1234567890 '
   Str2  db ' This is the caption. You can make this long longer than 500 bytes',0

.Data
   Profile001 PROFILE < offset Str1, offset Str2 >

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
.CODE
Start:
   invoke MessageBox, NULL, Profile001.item1, Profile001.item2, MB_OK
   invoke ExitProcess, 0

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

End Start