Skip to content
gsly edited this page Jun 25, 2012 · 1 revision

There is a bug in the HP ITOS() (Integer to ASCII/OS String) method as implemented in the DVx in that the buffer used to return the string is not terminated with a zero. Replace the method with the following that corrects this issue:

// Function: Integer to ASCII/OS String
//
// Arg0 = Integer (DWord) to convert
// Return = Buffer of ASCII representation (Length = 0x5)

Method (ITOS, 1, NotSerialized)
{
		// Buffer to store converted string
		
		Store (Buffer (0x06)
				{
						0x20, 0x20, 0x20, 0x20, 0x20, 0x00
				}, Local0)
		
		// Lookup table for ASCII digit
		
		Store (Buffer (0x11)
				{
						"0123456789ABCDEF"
				}, Local7)
		Store (0x05, Local1)    // Counter
		Store (Zero, Local2)    // Index into Local0 (String)

		While (Local1)
		{
				Decrement (Local1)
				And (ShiftRight (Arg0, ShiftLeft (Local1, 0x02)), 0x0F, Local4) // Get next digit to convert
				GBFE (Local7, Local4, RefOf (Local5))							// Get ACSII version from Local7 lookup table
				PBFE (Local0, Local2, Local5)									// Put digit in string buffer
				Increment (Local2)												// Index++
		}
		Store(Zero, Index(Local0, Local2))  // Ensure string ends with '\0'

		Return (Local0)
}
Clone this wiki locally