Statistics

Members: 1927
News: 293
Web Links: 1
Visitors: 3933052

Who's Online

We have 3 guests online
Damn Vulnerable LinuxDamn Vulnerable Linux (DVL) is a Linux-based (modified Damn Small Linux) tool for IT-Security & IT-Anti- Security and Attack & Defense. [CLICK HERE FOR MORE INFOS! ]

Featured Conference Video

T16-Recon2006-Joe_Stewart-OllyBonE.gif OllyBone - Semi-Automatic Unpacking on IA-32. View the conference video here!
Home arrow Articles - Black Hat Methods arrow Assembly arrow Binary-to-ASCII
Binary-to-ASCII
User Rating: / 0
PoorBest 
Written by Jan Verhoeven   


The Challenge
-------------
Write a routine to convert the value of a bit to ASCII in under 10 bytes, with no conditional jumps.

The Solution

Load the number into the AX register and shift through the bits. If a bit is cleared [0], you want to print a "0" character; if a bit is set [1], you want to print a "1".

Prime the BL register with the ASCII character "0"; if the next bit in AX is set, carry will be set after the SHL and BL will thus be incremented to an ASCII "1". The key, as you will see, is the ADC [AddWithCarry] instruction:

L0: B330          MOV     BL,30   ; try with al = ZERO
D1E0          SHL     AX,1    ; ... but if bit = set, ...
80D300        ADC     BL,00   ; ... make it a ONE,

7 bytes all told; with a loop and mov instruction for storing each value in BL to the location of your choice, you will have a full-fledged binary-toascii converter in a handful of bytes.