Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3353296
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:08:03+00:00 2026-05-18T02:08:03+00:00

I’m trying to convert packed decimal numbers into ascii strings. Here is my understanding

  • 0

I’m trying to convert packed decimal numbers into ascii strings. Here is my understanding thus far:

The following:

bcd BYTE 34h

Should convert to the decimal number 34 after being “unpacked”. Now I’m not sure on the best way of doing this. If I convert this hexadecimal number to binary it is as follows…

0011 0100 

Now, if I have my procedure print out each 4bit binary value at a time, then it should print the ascii string of numbers, correct? So if I go through a loop, grab the first 4 bit binary number, print its actual value out, its going to print 3.. then do the same, its going to print 4.

So, here is my general idea:

Take an 8bit value “34h”, mov it into AH and AL. In AH, clear the second half of the bits using the follow:

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 these out accordingly..

Is this a good approach? Or am I going about completely incorrect or way over thinking it?

EDIT: Here is my final solution with original value of 12345678h. Thanks to all who helped!

;-----------------------------------------------------------------------------
PackedToAsc PROC USES eax ebx edx ecx esi
; This function displays a packed decimal value in its "ascii" form
; i.e. 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

P

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:08:03+00:00Added an answer on May 18, 2026 at 2:08 am

    BCD uses only the digits 0 thru 9.
    An unpacked BCD digit uses the lower nibble of an entire byte and to convert it to ASCII you add 48.
    The number 34h is 52 decimal and will be represented as an unpacked BCD as 00000101 and 00000010
    (Changed to avoid confusion when using built-in instructions)
    When it is packed: 01010010 == BCD packed 52

    To unpack it, you can do as you have done, but you need to shift AH right to place the value in the lo-nibble. To convert to ASCII just add 48.

    [edit]

    MASM (=> ALL instructions, Linux included) that runs on 80×86 processors uses the little-endian scheme. CPUs such as Motorola 68000 (Apple Mac) and RISC uses big-endian.

    When you store a number as BCD, the least significant byte is at the lowest address thru to the most-significant at the highest, e.g.:

    my_unpacked_bcd  DB 4,3,2,1 ; this is the decimal number 1234
    my_packed_bcd    DW 3412h  ; this defines the same number as packed
    

    Packed BCD depends on what you want to do with it. If you want to ADD, MUL, DIV, SUB you must present the values as required by these instructions. Also remember to add zero-bytes to start and end of your digits to hold carries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.