|
Written by Angel Tsankov
|
Challenge
---------
Write as short as possible program to convert a two-digit BCD to hexadecimal;
that is, the decimal representation of the output must represent the
hexadecimal representation of the input.
Solution
--------
The solution, in 14 bytes:
;Input AL = (A * 16) + B
;Output AL = (A * 10) + B
88 C4 MOV AH, AL ;AH = AL
82 E4 F0 AND AH, 0F0h ;AH = (A * 16)
D0 EC SHR AH, 1 ;AH = (A * 8)
28 E0 SUB AL, AH ;AL = (A * 8) + B
C0 EC 02 SHR AH, 2 ;AH = A * 2
00 E0 ADD AL, AH ;AL = (A * 10) + B
Submitted by Angel Tsankov <{
This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
}>.
|