Author Topic: String character count  (Read 314 times)

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 893
  • ObjAsm Developer
    • ObjAsm
String character count
« 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
« Last Edit: March 14, 2022, 01:28:43 AM by Biterider »

HSE

  • Member
  • *****
  • Posts: 2070
  • AMD 7-32 / i3 10-64
Re: String character count
« Reply #1 on: March 14, 2022, 12:52:10 AM »
 :thumbsup: Fantastic
Equations in Assembly: SmplMath