The MASM Forum

64 bit assembler => 64 bit assembler. Conceptual Issues => Topic started by: Jokaste on December 09, 2017, 05:45:29 AM

Title: Macro for String
Post by: Jokaste on December 09, 2017, 05:45:29 AM
Yes I don't like macros but there are cases when they really help the programmer.
I am trying to write a macro that completes a string with one to four ZEROes.
This is to have not to write 'ALIGN 4' between each line.
I have imagined something like CSTRING4(LABEL,"String")
I have tried to write it but the SIZESTR and the @SIZESTR are not my friends.

Is there some wants that wants to help me?

After the string one must add four zeroes because if the string length is a multiple of four it is not null terminated.
Examples :
"1234" => "1234",0,0,0,0 ; The worst case
"123"   => "123",0           ; The best case
"12"     => "12",0,0
"1"       => "1",0,0,0

Actually I count each byte by hand and sometimes I use ObjConv to verify the aligment.
Not very easy.
Title: Re: Macro for String
Post by: jj2007 on December 09, 2017, 06:37:54 AM
You can use slen INSTR 2, <arg>, <"> to calculate the size.
Use this to check the result:
tmp$ CATSTR <Myarg=>, <arg>, < with LEN=>, %slen
% echo tmp$
Title: Re: Macro for String
Post by: Jokaste on December 09, 2017, 08:09:32 AM
I don't understand how it works. :icon_exclaim:
Title: Re: Macro for String
Post by: qWord on December 09, 2017, 08:33:23 AM
CSTRING4 macro lbl,quoted_string
LOCAL quoted_string_size, string_size

    quoted_string_size SIZESTR <quoted_string>
   
    string_size = quoted_string_size - 2
   
    lbl db quoted_string
   
    IF (string_size MOD 4) NE 0
        db 4 - (string_size MOD 4) dup (0)
    ELSE
        db 4 dup (0)
    ENDIF
endm

regards
Title: Re: Macro for String
Post by: Jokaste on December 09, 2017, 02:54:50 PM
Now it's clear.
Thanks