News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Packed Decimal Conversion

Started by Jaflo187, December 02, 2009, 09:48:47 PM

Previous topic - Next topic

Jaflo187

Write a procedure named PackedToAsc that converts a 4-byte packed decimal interger to a string of ASCII decimal digits. Pass the packed interger and the address of a buffer holding the ASCII digits to the procedure. Write a short test program that displays several converted intergers.


jj2007

Quote from: Jaflo187 on December 02, 2009, 09:48:47 PM
Write a procedure named PackedToAsc that converts a 4-byte packed decimal interger to a string of ASCII decimal digits. Pass the packed interger and the address of a buffer holding the ASCII digits to the procedure. Write a short test program that displays several converted intergers.

Hey, it's called integer, not interger. And we don't do homework for kids here, sorry.

MichaelW

By packed decimal integer I assume you mean an unsigned packed BCD.

http://en.wikipedia.org/wiki/Binary-coded_decimal#Basics

To convert a packed BCD value to a string, you take each nibble, starting with the rightmost (the least-significant), convert the value of the nibble to a decimal digit by adding the ASCII character code for zero (30h) to it, and store the result in the string. Since you are starting with the least-significant digit you must fill the string starting with the last (rightmost) digit and progressing to the first (leftmost) digit. And since the string would normally be null-terminated, unless you can depend on the buffer containing a terminating null, you will need to store a null at the end of the buffer at some point in your procedure. My implementation required one loop label and 12 instructions, including the RET.

And BTW, since hex values are stored as one digit per nibble, an easy way to specify a packed BCD value in code is to specify it as hex, with the restriction that you cannot use the hex digit values A-F. For example, the decimal packed BCD value 12345678 could be specified as 12345678h, or the value 1000 as 1000h.
eschew obfuscation

hutch--

Jaflo187,

We have tried to help you but read the rules, we don't do your homework for you. There will not be a next time, do your own work and we will help you, try again and you will have the option of going elsewhere.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Ficko

Quote
...don't do your homework for you...

Agree!  :snooty:

I am amazed how nice people responded to you despite your AV software seems to cut off "please" from your outgoing messages. :green

However if you wanna "shock" your teacher and simplify your solution try to use the FPU.

http://www.website.masmforum.com/tutorials/fptute/fpuchap2.htm#bcds


ecube

I think it's interesting they teach ASM in his school, a lot better than c++ nonsense  :U

dedndave

i think they teach ASM under the label of "computer architecture basics"
many of these students will never use ASM after they leave school
some of them catch the bug if they find it fun/interesting

as for converting packed to string, my hint would be the AAM instruction
it sounds like the instructor just wants to see if you know how to create and call a procedure
really though - lol - you could at least phrase the question as though it didn't come straight out of a homework assignment
the point is - at least make an effort to write the code
if it doesn't work, we MAY help you out   :bg