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.
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$
I don't understand how it works. :icon_exclaim:
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
Now it's clear.
Thanks