## agrawalashishku

I am using 32 bit AT&T version of assembly on linux. Someone please tell me how to convert an integer stored into one ot the registers to a string that can be printed. e.g. 0x00066 should print as 102.

## mickinator

you could use a couple of compare statements to compare the values and then print out the ascii equivalents

## Duoas 1,025

An integer is represented (by humans) thus: `1234` 1 is in the thousands place
2 is in the hundreds place
3 is in the tens place
4 is in the ones place

Each place to the left is times 10. So:
1234 div 10 is 123 R 4
123 div 10 is 12 R 3
12 div 10 is 1 R 2
1 div 10 is 0 R 1

The only problem is that we get the numbers out in the wrong order for printing: 4, 3, 2, 1.

So, just load EAX with your (unsigned) number and reverse it into, say, EBX using div and mul by 10. (Keep in mind that DIV and MUL use EAX:EDX implicitly, so you will have to push and pop some values to preserve them.)

Once the number is reversed, do the same sort of thing again (peeling off the ones position by dividing by ten), add 48 to your result (ASCII code for '0') to turn your 0,1,2,... into '0','1','2',..., then print the character.

Hope this helps.