RAD50 <str>[, cnt]
None
This directive places strings encoded with the RAD50 encoding into constants. The RAD50 encoding places 3 string characters out of a reduced character set into 2 bytes. It therefore saves memory when comparing it with a plain ASCII representation. It also has some drawbacks, however. Only 40 different character values are supported, and the strings have to be decoded before they can be used. This decoding does include some computations including divisions (not just shifts) and is therefore rather expensive.
The encoding takes three bytes and looks them up in a string table. The following listing shows the RAD50 encoding.
unsigned short LookUpPos(char x) { static const char translate[]= " ABCDEFGHIJKLMNOPQRSTUVWXYZ$.?0123456789"; const char* pos= strchr(translate, x); if (pos == NULL) { EncodingError(); return 0; } return pos-translate; } unsigned short Encode(char a, char b, char c) { return LookUpPos(a)*40*40 + LookUpPos(b)*40 + LookUpPos(c); }
If the remaining string is shorter than 3 bytes, it is filled with spaces (which correspond to the RAD50 character 0).
The optional argument cnt can be used to explicitly state how many 16-bit values should be written. If the string is shorter than 3*cnt, then it is filled with spaces.
See the example C code below about how to decode it.
The string data in the following listing assembles to the following data where 11 characters are contained in eight bytes. The 11 characters in the string are represented by 8 bytes.
XDEF rad50, rad50Len DataSection SECTION rad50: RAD50 "Hello World" rad50Len: EQU (*-rad50)/2
$32D4 $4D58 $922A $4BA0
This C code shown in the following listing takes the data and prints "Hello World".
#include "stdio.h" extern unsigned short rad50[]; extern int rad50Len; /* address is value. Exported asm label */ #define rad50len ((int) &rad50Len) void printRadChar(char ch) { static const char translate[]= " ABCDEFGHIJKLMNOPQRSTUVWXYZ$.?0123456789"; char asciiChar= translate[ch]; (void)putchar(asciiChar); } void PrintHallo(void) { unsigned char values= rad50len; unsigned char i; for (i=0; i < values; i++) { unsigned short val= rad50[i]; printRadChar(val / (40 * 40)); printRadChar((val / 40) % 40); printRadChar(val % 40); } }