Sorry for offtopic but I need a personal favour. Today I read article 8 APJ and at the and there was challenge at the end. I have no idea where to send answer. Could anybody post it for me to APJ? ::/ \::::::. :/___\:::::::. /| \::::::::. :| _/\:::::::::. :| _|\ \::::::::::. :::\_____\:::::::::::...........................................ISSUE.CHALLENGE 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 --------------------------- Here is 9 bytes version by The Svin mov ah,al shr ah,4 and al,0Fh aad Until next time. The Svin.
Posted on 2001-01-29 09:11:00 by The Svin
Don't know where to send the answer, but... If you start with input in ah (instead of al) could you do: shr ax,4 shr al,4 aad Instead? I can't check, I'm at work (no docs or anything), and I'm too stupid to remember what opcodes do! Mirno
Posted on 2001-01-29 09:49:00 by Mirno
Of course you could not. You will loose first tetrada of packed BCD by shr' iting it out with shr ax,4 The Svin.
Posted on 2001-01-29 10:30:00 by The Svin
What do you mean by Tetrada? I'm not very clever you see :( Mirno
Posted on 2001-01-29 10:48:00 by Mirno
You Are smart :) And your algo will work fine and do the same think and is shorter but we have packed BCD in al and unpacked in AX. So to have in ah we need to put it there and that will be additional instruction. tetrada is a simple thing made from the Greek and means 4. It's another word for what some asm programmers call nible. The first tetrada of al means low 4 bits of al or low nible. The Svin.
Posted on 2001-01-29 14:21:00 by The Svin
Ahh I know nibble :) Must remember tetrada, impress my friends :P
Posted on 2001-01-30 06:03:00 by Mirno