News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

String character count

Started by Biterider, March 13, 2022, 09:46:36 PM

Previous topic - Next topic

Biterider

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

HSE

Equations in Assembly: SmplMath