Hi all,
I'm trying to cat a string dword ptr to a literal string.
There must be a simple way of doing this.
Thanks for any help.


include \masm32\include\masm32rt.inc

Info equ <Mickey >
Letter Macro Let:req
          Info CATSTR Info,getarg(Let,<A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z>)
      EndM
.data
Rec db "MOUSE",0
.code
start:
      xor eax,eax
      xor ecx,ecx
      mov esi,offset Rec
@@:
      Let=1
      mov cl,65
      mov al,
      or al,al
      jz @F
Back:
      .If al==cl
          Letter Let
          print str$(eax),10
          jmp Pass
      .EndIf
      inc cl
      Let=Let+1
      jmp Back
Pass:
      inc esi
      jmp @B
@@:

    inkey
    exit
end start
Posted on 2010-01-26 14:35:09 by xroot
xroot,

Please read MASM manual, especially focus on difference between compile-time features (like equ, macro, catstr and numeric equates) and statements that generate code.
Posted on 2010-01-27 01:15:30 by baldr
Sorry,
I have read the MASM manual, over and over and over......
Posted on 2010-01-27 09:25:31 by xroot
I agree with xroot, the macro system is quite complicated when you are new to it. My macro skills are fairly limited :oops:

Could you explain in simple terms what exactly you're trying to do?
Posted on 2010-01-27 09:45:59 by JimmyClif

Could you explain in simple terms what exactly you're trying to do?


He's looping through an uppercase ASCIIZ string, check for the terminator, and then checking against each capital letter (e.g. 65 = 0x41 = 'A') of the alphabet.

The Letter macro is using CATSTR to an EQU.

1.) He probably should be using TEXTEQU instead of EQU.

2.) Mixing assemble-time (Info being an equate and not a variable/string/pointer) and run-time processing, in such a manner, doesn't quite work (what baldr was hinting at).
Posted on 2010-01-27 10:59:34 by SpooK
equ with <> is the same as textequ <>, says in the manual.
Posted on 2010-01-27 13:15:57 by xroot

equ with <> is the same as textequ <>, says in the manual.


Then the manual is probably correct :)

However, the finer point is that you are mixing assembly-time constructs with run-time logic.

EQU is an assembly-time construct and therefore will have no bearing at run-time.

What you are doing is also easily accomplished by a run-time lookup table. For example:

1.) Make sure the returned ASCII character is within the desired span, A-Z in your case.
2.) Subtract the base (65) from the returned ASCII character to form an offset.
3.) Add the offset to a byte table pointer and retrieve the value.
4.) Use a runtime concat function to append the value to a string.

Also, if you are using the lookup only as a filter, that is not needed, step 1 in the example above is already such a filter.
Posted on 2010-01-27 14:26:20 by SpooK
Thanks for your info,
My problem is that I need a literal "equ" at the end of run time from the string pointer.


Posted on 2010-01-27 15:37:36 by xroot

My problem is that I need a literal "equ" at the end of run time from the string pointer.


For what exact purpose?

Please be as verbose and detailed as possible in your response.
Posted on 2010-01-27 15:48:41 by SpooK
xroot: macros are handled at assemble-time (actually even before that: at preprocess-time), and it's mostly just glorified text substitution - try assembling with "ml /Fl /Sa" to get an expanded listing that shows what your macros expand to, and what the assembler sees.
Posted on 2010-01-27 17:56:05 by f0dder
Yes, the assembler fully 'expands' macros into a bunch of regular linear code, then assembles it.
So all a macro usually does is hide (from you, the programmer) a small block of code (that you could have written literally), perhaps changing it slightly based on input arguments.
When a macro is executed, it emits a series of statements which are passed to the assembler as if you literally wrote them in the sourcecode.
They make sourcecode pretty, and are useful for situations where you need subtle variations of the same chunk of code, but they are not something you can call at runtime like a procedure, they are "inline".

Posted on 2010-01-28 02:49:32 by Homer
I disagree with "text substitution" and "hides code" statements, it's language inside a language and is what makes asm programming great (for me).

let us look at the following macro code:
.data
align 16
CRC32Table label dword
i = 0
crc = i
WHILE i LT 256
crc = i
REPT 8
   crc = (crc shr 1) xor (0EDB88320h * (crc and 1))
ENDM
DD crc
i = i + 1
ENDM
Please if someone can translate this to ANY other language I'll be very interested.



xroot, you do realize that { "Let=1" "Letter Let" "Let=Let+1" } lines are interpreted independent of the code between.
Try to use "echo" command for "debugging" macros

Info equ <Mickey >
%echo Info

for Let,<M,o,u,s,e>
Info catstr Info,<Let>
%echo Info
endm

Info catstr <!">,Info,<!">;; append quotes

.data
Rec db Info,0



Posted on 2010-01-28 07:07:30 by drizz
OK, so macros can be used to define (possibly complex) patterns of data algorithmically, yes I should have mentioned that too. But ultimately,
When a macro is executed, it emits a series of statements which are passed to the assembler as if you literally wrote them in the sourcecode.
is an accurate appraisal.
Posted on 2010-01-28 07:11:07 by Homer
I quess it can't be done.
All I want is a way to convert a string ptr to a literal and cat it to another literal.

s equ <any literal>
LET macro anyptr:req
      s catstr s,<here is the converted string ptr literal>,<more literal string>
      endm

anyproc proc string:dword
            LET string
anyproc endp
Posted on 2010-01-28 09:52:25 by xroot
xroot: no, of course it can't be done - macros are applied before assembling, and what you want is to apply them at runtime.
Posted on 2010-01-28 10:11:40 by f0dder

All I want is a way to convert a string ptr to a literal and cat it to another literal.


Again, that is mixing semantics. A literal is an programming language construct. Assemblers and compilers store literals as variables/arrays/strings/etc.

Strings are generally just arrays of BYTE or WORD sized values stored in memory, hence the need for pointer semantics.

Your options are to concat literals at assembly-time (during the phase that the program is assembled and turned into a set of instructions/data), or concat strings at run-time (during the phase that the program instructions are actually executing and data is accessed/manipulated.)
Posted on 2010-01-28 10:11:55 by SpooK