I am trying to convert packed decimal numbers to ascii strings. Here is my understanding:
Following:
bcd BYTE 34h
Convert to decimal 34 after โunpackingโ. Now I'm not sure how to do this. If I convert this hexadecimal number to binary, it will be as follows:
0011 0100
Now, if my procedure prints each bit value 4 bits at a time, then it should print an ascii character string, right? Therefore, if I go through the loop, take the first 4-bit binary number, print its actual value, it will print 3 .. then do the same, print it 4.
So here is my general idea:
Take the 8-bit value "34h", move it to AH and AL. In AH, clear the second half of the bits using the following command:
and ah, 11110000b
and in AL, clear the first half of the bits using the following:
and al, 00001111b
So, AH = 0110b or 3 AND AL = 0100b or 4, then print them accordingly.
Is this a good approach? Or am I going to completely make a mistake or think about it?
EDIT: Here is my final decision with the original value 12345678h. Thanks to everyone who helped!
;----------------------------------------------------------------------------- PackedToAsc PROC USES eax ebx edx ecx esi ; This function displays a packed decimal value in its "ascii" form ; ie 12345678h would display decimal, 12345678 in decimal form ; ; Requires ECX = SIZEOF packed decimal ; ESI to be pointing to the packed decimal ;----------------------------------------------------------------------------- mov edx, [esi] ; temp store our offset mov eax, 0 ; clear eax mov ebx, 0 ; clear ebx L1: rol edx, 8 ; rotate left 8 bits to avoid little endian mov [esi], edx ; mov our temp back to the actual value mov al, BYTE PTR [esi] ; al = 12h 0001 0010 mov bl, BYTE PTR [esi] ; bl = 12h 0001 0010 shr al, 4 ; al = 0000 0001 and bl, 00001111b; ; bl = 0000 0010 add al, 48 ; convert to ascii call WriteChar ; display al mov al, bl add al, 48 ; convert to ascii call WriteChar ; display bl loop L1 call Crlf ret PackedToAsc END
R