%include "lmacros1.mac" ; Write numbers as decimal digits into a string %define _1digits_nocheck(d) (((d)% 10)+'0') %xdefine _2digits_nocheck(d) _1digits_nocheck((d)/10),_1digits_nocheck(d) %xdefine _3digits_nocheck(d) _1digits_nocheck((d)/100),_2digits_nocheck(d) %xdefine _4digits_nocheck(d) _1digits_nocheck((d)/1000),_3digits_nocheck(d) %xdefine _5digits_nocheck(d) _1digits_nocheck((d)/10000),_4digits_nocheck(d) %xdefine _1digits(d) (!!(d/10)*(1<<32)+ _1digits_nocheck(d)) %xdefine _2digits(d) _1digits((d)/ 10),_1digits_nocheck(d) %xdefine _3digits(d) _1digits((d)/ 100),_2digits_nocheck(d) %xdefine _4digits(d) _1digits((d)/ 1000),_3digits_nocheck(d) %xdefine _5digits(d) _1digits((d)/10000),_4digits_nocheck(d) %macro _appenddigitstrdef 2.nolist %substr %%ii "0123456789ABCDEF" (%2) + 1 %strcat _%1 _%1,%%ii %endmacro ; %1 = name of single-line macro to set. will be prefixed by underscore ; %2 = number to write ; %3 = minimal number of digits, 0..5. defaults to 1 ; (setting it to 0 with a number of 0 defines macro to "") %macro _autodigitsstrdef 2-3.nolist 1 %if %3 > 5 %error Minimal number of digits 6 or more: %3 %endif %define _%1 "" %if (%2) >= 100000 %error Number has to use 6 or more digits: %2 %endif %if (%2) >= 10000 || %3 >= 5 _appenddigitstrdef %1, %2 / 10000 % 10 %endif %if (%2) >= 1000 || %3 >= 4 _appenddigitstrdef %1, %2 / 1000 % 10 %endif %if (%2) >= 100 || %3 >= 3 _appenddigitstrdef %1, %2 / 100 % 10 %endif %if (%2) >= 10 || %3 >= 2 _appenddigitstrdef %1, %2 / 10 % 10 %endif %if (%2) >= 1 || %3 >= 1 _appenddigitstrdef %1, %2 / 1 % 10 %endif %endmacro ; %1 = name of single-line macro to set. will be prefixed by underscore ; %2 = number to write ; %3 = minimal number of hexits, 0..8. defaults to 1 ; (setting it to 0 with a number of 0 defines macro to "") %macro _autohexitsstrdef 2-3.nolist 1 %if %3 > 8 %error Minimal number of hexits 9 or more: %3 %endif %define _%1 "" %if (%2) >= 1_0000_0000h %error Number has to use 9 or more hexits: %2 %endif %if (%2) >= 1000_0000h || %3 >= 8 _appenddigitstrdef %1, (%2 >> (7 * 4)) & 0Fh %endif %if (%2) >= 100_0000h || %3 >= 7 _appenddigitstrdef %1, (%2 >> (6 * 4)) & 0Fh %endif %if (%2) >= 10_0000h || %3 >= 6 _appenddigitstrdef %1, (%2 >> (5 * 4)) & 0Fh %endif %if (%2) >= 1_0000h || %3 >= 5 _appenddigitstrdef %1, (%2 >> (4 * 4)) & 0Fh %endif %if (%2) >= 1000h || %3 >= 4 _appenddigitstrdef %1, (%2 >> (3 * 4)) & 0Fh %endif %if (%2) >= 100h || %3 >= 3 _appenddigitstrdef %1, (%2 >> (2 * 4)) & 0Fh %endif %if (%2) >= 10h || %3 >= 2 _appenddigitstrdef %1, (%2 >> (1 * 4)) & 0Fh %endif %if (%2) >= 1h || %3 >= 1 _appenddigitstrdef %1, (%2 >> (0 * 4)) & 0Fh %endif %endmacro %assign ii 0 %rep 31 _autodigitsstrdef DEF, ii %strcat string _DEF %strlen ll string %substr ones string ll %if ll >= 2 %substr tens string ll - 1 %else %define tens "0" %endif %deftok tokenones ones %deftok tokentens tens %if tokentens != 1 && tokenones == 1 %define suffix "st" %elif tokentens != 1 && tokenones == 2 %define suffix "nd" %elif tokentens != 1 && tokenones == 3 %define suffix "rd" %else %define suffix "th" %endif db _DEF,suffix,10 %assign ii ii + 1 %endrep %assign ii 0BADC0DEh %rep 128 _autohexitsstrdef DEF, ii %strcat string _DEF %strlen ll string %substr ones string ll %if ll >= 2 %substr tens string ll - 1 %else %define tens "0" %endif %strcat ones "0",ones,"h" %strcat tens "0",tens,"h" %deftok tokenones ones %deftok tokentens tens %if tokentens != 1 && tokenones == 1 %define suffix "st" %elif tokentens != 1 && tokenones == 2 %define suffix "nd" %elif tokentens != 1 && tokenones == 3 %define suffix "rd" %else %define suffix "th" %endif db _DEF,suffix,10 %assign ii ii + 1 %endrep