Author Topic: Macro for String  (Read 125 times)

Jokaste

  • Regular Member
  • *
  • Posts: 48
  • Never be pleased, always improve
    • Grincheux's Tools
Macro for String
« 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.
Kenavo
---------------------------
Grincheux / Jokaste

jj2007

  • Member
  • *****
  • Posts: 7900
  • Assembler is fun ;-)
    • MasmBasic
Re: Macro for String
« Reply #1 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:
Code: [Select]
tmp$ CATSTR <Myarg=>, <arg>, < with LEN=>, %slen
% echo tmp$

Jokaste

  • Regular Member
  • *
  • Posts: 48
  • Never be pleased, always improve
    • Grincheux's Tools
Re: Macro for String
« Reply #2 on: December 09, 2017, 08:09:32 AM »
I don't understand how it works. :icon_exclaim:
Kenavo
---------------------------
Grincheux / Jokaste

qWord

  • Member
  • *****
  • Posts: 1471
  • The base type of a type is the type itself
    • SmplMath macros
Re: Macro for String
« Reply #3 on: December 09, 2017, 08:33:23 AM »
Code: [Select]
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
MREAL macros - when you need floating point arithmetic while assembling!

Jokaste

  • Regular Member
  • *
  • Posts: 48
  • Never be pleased, always improve
    • Grincheux's Tools
Re: Macro for String
« Reply #4 on: December 09, 2017, 02:54:50 PM »
Now it's clear.
Thanks
Kenavo
---------------------------
Grincheux / Jokaste