The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: wizzra on April 24, 2005, 07:25:58 AM

Title: string len - compile time
Post by: wizzra on April 24, 2005, 07:25:58 AM

mov eax,$-TADD ("This's String length is 26")-1


macro (altered to from macros.asm to return offset)

      TADD MACRO quoted_text:VARARG
        LOCAL vname,lbl
          jmp lbl
            vname db quoted_text,0
          lbl:
        EXITM <offset vname>
      ENDM
Title: a
Post by: AeroASM on April 24, 2005, 10:35:29 AM
Firstly you have no way of referring to the string.

Secondly I do not like to use CADD because of the unnecessary jmp (use SADD and CTXT instead)

Thirdly you can do the same thing without a macro like this:


.data
szText db "Hello",0
szText_len equ $-offset szText-1
.code
mov eax,szText_len

Title: Re: string len - compile time
Post by: hutch-- on April 24, 2005, 10:38:04 AM
Aero,

The value of the CADD macro an similar techniques is that it writes the text into the .CODE section rather than the .DATA section. With very small apps, this saves a data section being added and it also makes the text read only and directly embedded in the code which makes it a bit harder to hack as you cannot make the string longer.
Title: Re: string len - compile time
Post by: AeroASM on April 24, 2005, 01:43:03 PM
What use do very small apps have? What is wrong with the .const section?
Title: Re: string len - compile time
Post by: hutch-- on April 24, 2005, 02:55:59 PM
Try you luck building it to see if you get an extra section or not. When you put data in the code section, you don't.


.code
  txt db "Tis is ascii text",0
  start:
  ; your code etc ....
Title: Re: string len - compile time
Post by: wizzra on April 24, 2005, 03:07:32 PM
AeroASM,

what i wrote was for the .code section string len for compile time.
yes i know we can use the .data section :)
Title: Re: string len - compile time
Post by: AeroASM on April 24, 2005, 03:49:12 PM
All right then do it your way (sigh)

You want a macro for this, right?


.code
jmp @F
szText db "My Text",0
szText_len equ $-offset szText
@@:
mov eax,szText_len



CSSTR macro name,value
LOCAL lbl
jmp lbl
name db value,0
name_len equ $-offset name
lbl:
CSSTR endm

.code
CSSTR szText,"My Text"
mov eax,szText_len
mov edx,offset szText


(BTW this is my first time making a macro)
Title: Re: string len - compile time
Post by: hutch-- on April 25, 2005, 02:21:30 PM
Aero,

If you put data AFTER the .CODE location but BEFORE the "start" label, you don't have to jump over it. Execution starts at the "start" location label so anything before it that is in the .CODE section does not get executed, IE does not get treated as instructions.
Title: Re: string len - compile time
Post by: AeroASM on April 25, 2005, 03:54:36 PM
I know, you ahve already shown me.