Write A program in assembly language to convert BCD to ASCII Codes

Started by MBeckford05, April 30, 2008, 09:21:40 PM

Previous topic - Next topic

MBeckford05

In the Binary Coded Decimal notation (BCD) four bits are used  to express digits between 0
And 9.  Assume that your seven digit student ID (2527634)  is stored in the form of a packed BCDs (two digits per byte) in consecutive memory locations starting at the address my_ID.

Write a program in assembly language to convert them into ASCII codes and to display them on the ID on the the screen using MASM32 StdOut function.

You are allowed to use the 8 bit register instructions where appropriate.  Use the MASM32 library function StdOut for the printout.

Hint:  It is known that ASCII codes of numbers 0-9 are 30H-39H,. So the repetitive
Task is to unpack the BCD and to add 30H to each and store it in the display buffer.
In order to unpack the BCD you will need to isolate the four bits from a byte.  A couple of logic instructions mentioned earlier may come in very handy.



redskull

Did you seriously just type the homework assignment word for word?  Why even bother taking the class to begin with if you aren't going to try?  Whatever, either way, isolate a byte into the low byte of a register, use a word-rotate to move the high nibble into the next byte, and then a byte-rotate to move the low nibble back down.  Then add 30 to each.

-alan

Strange women, lying in ponds, distributing swords, is no basis for a system of government

raymond

A bit of searching may have landed you at the following if you REALLY want to learn all about BCDs:

http://www.ray.masmcode.com/BCDtut.html
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com