News:

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

string len - compile time

Started by wizzra, April 24, 2005, 07:25:58 AM

Previous topic - Next topic

wizzra


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

AeroASM

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


hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

AeroASM

What use do very small apps have? What is wrong with the .const section?

hutch--

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 ....
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

wizzra

AeroASM,

what i wrote was for the .code section string len for compile time.
yes i know we can use the .data section :)

AeroASM

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)

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

AeroASM

I know, you ahve already shown me.