The MASM Forum

Projects => ObjAsm => Topic started by: Biterider on March 13, 2022, 09:46:36 PM

Title: String character count
Post by: Biterider on March 13, 2022, 09:46:36 PM
Hi
Good news for ObjAsm users!  :cool:

Often we face situations where we need to count bytes or characters, such as:

OCall xsi.WritePbx, $OfsCStrA("SPS ", "0" + PBX_STATE_OFFLINE, CRLF), 7

In this example I send a command to a PLC using an ANSI string. The last parameter is the transmission length.
Every time we change something on this string, we have to recount the characters and hopefully we don't make a mistake.
When we have 100's of affected lines it becomes a real pain.

I have extended the string macros in A String, BString and WString to update 2 new global symbols, ??StrLength and ??StrSize.
??StrLength stores the character count without the zero terminator and ??StrSize the total byte count including the zero terminator, regardless of the character size.

Now the line before looks like this

OCall xsi.WritePbx, $OfsCStrA("SPS ", "0" + PBX_STATE_OFFLINE, CRLF), ??StrLength

and the count doesn't need to be updated anymore, since it is updated automatically   :biggrin:

Note: ??StrLength and ??StrSize store the information of the last string allocation.

Biterider
Title: Re: String character count
Post by: HSE on March 14, 2022, 12:52:10 AM
 :thumbsup: Fantastic