Something like:
Code: Select all
int i = 50;
print(I);
like:
Code: Select all
print("Hello");
Code: Select all
int i = 50;
print(I);
Code: Select all
print("Hello");
Code: Select all
void printint(unsigned int i)
{
putch((char)(((i / 1000000000) %10) + '0'));
putch((char)(((i / 100000000) %10) + '0'));
putch((char)(((i / 10000000) %10) + '0'));
putch((char)(((i / 1000000) %10) + '0'));
putch((char)(((i / 100000) %10) + '0'));
putch((char)(((i / 10000) %10) + '0'));
putch((char)(((i / 1000) %10) + '0'));
putch((char)(((i / 100) %10) + '0'));
putch((char)(((i / 10) %10) + '0'));
putch((char)(((i / 1) %10) + '0'));
csr_y++;
}
Code: Select all
int divider = 1000000000
int digit = 0
bool printFlag = False
while divider > 0 do
digit = (i/divider) % 10
if digit > 0
PrintFlag = True
endIf
if PrintFlag then
putch((char) digit)
endIf
divider = divider / 10
endWhile
For hex display, it's even simpler:Crazed123 wrote: That'll work OK for decimal, but what about hex? Or do the ASCII values for A, B, C, D, E and F come straight after the one for '9'? I can't remember.
Code: Select all
char * tohexprint(unsigned int x) {
char buffer[9];
int i;
for (i=0; i<8; i++) {
int asc = ((x & (15 << (4*i))) >> (4*i)) + 0x30;
if (asc > 0x39) asc += 0x7; // or 0x27
buffer[7-i] = asc;
}
return buffer;
}
Code: Select all
void print_unsigned_long(unsigned long val, unsigned radix) {
char buf [33], *s = buf + sizeof(buf);
unsigned remainder;
/* store terminating nul character in buf */
s--;
*s = '\0';
/* repeatedly divide 'val' by 'radix' until 'val' == 0 */
do {
/* ...it's the remainder we really want... */
remainder = (unsigned)(val % radix);
val = val / radix;
/* convert binary remainder to ASCII digit */
remainder += '0';
if(remainder > '9')
remainder += ('A' - ('9' + 1));
/* store ASCII digits RIGHT-TO-LEFT in buf */
s--;
*s = remainder;
} while(val != 0);
/* et voil?, display numeric string */
puts(s); }
Code: Select all
char* tohexprint(unsigned int x)
{
char* buffer = new char[8]; //Buffer to put the string
buffer[8] = 0; //Terminate the string
char _Hex[17] = "0123456789ABCDEF";//Hex string
_asm
{
mov ecx,8 //cycle though 8 times
mov edi,[buffer] //edi -> points to buffer
add edi,8 //edi -> points to end of buffer
mov eax,[x] //eax -> integer to convert
lea edx,_Hex //edx -> points to hex string
NextDig:
push eax //save eax
and eax,0Fh //last 4 bits of eax
mov al,byte ptr [edx+eax]//al -> _Hex[eax]
mov byte ptr[edi],al //put char into buffer
pop eax //restore eax
shr eax,4 //get now bits
dec edi //goto next char of buffer
loop NextDig //do it all again 8 times
}
return buffer;
}