Motorolla MC68HC11 Microcontroller BCD to ASCII converter.

NiCeBoY

Joined Aug 20, 2008
59
Hello..,,
I am required to write a program module to convert a BCD digit passed to it in the lower nibble of AccA to its ASCII character code. The upper nibble should be treated as a "don't care".
Return the ASCII code in AccA and save in a suitable memory location.
All other CPU register values are to remain unchanged.

Note: A program module is a routine that is called from the main program.
Can anyone show me how to write this program please?..

I have programmed program for Addition,substraction,multiplication,division and branching.. but this one i dont know how to start and what to do...

Regards..

hgmjr

Joined Jan 28, 2005
9,029
What software programming language are you using?

hgmjr

NiCeBoY

Joined Aug 20, 2008
59
Hello,
i have attached an example of a program i did before as an example(microl04.zip)

micro04.zip contain:
pf32.exe - i use to write codes,
SIMF1 - i used to simulate
AS11.exe i use to compile from dos by using the command:
AS11 filename.asm -L

Thx mate..

Attachments

• 304.4 KB Views: 43
• 365 bytes Views: 35

hgmjr

Joined Jan 28, 2005
9,029
I have moved this thread to the Homework Section as that is clearly where it appears to belong.

hgmjr

hgmjr

Joined Jan 28, 2005
9,029
Rich (BB code):
START ORG $2050 TABLE DB 32,0,50,0,72,0,86,0,104,0,125,0,176,0,212 counter equ$2080 ;loop counter
org $2000 ldaa #8 staa counter ;init counter LDY #$2050 ;Init data pointer
CONVERT LDAA 0,Y
SUBA #32
LDAB #5
MUL
LDX #9
IDIV
STX $10,y INY ;Increment Data Pointer INY ;Increment Data Pointer Twice dec counter BNE CONVERT bra * I have reposted your source code using the CODE tags. hgmjr hgmjr Joined Jan 28, 2005 9,029 Hello..,, I am required to write a program module to convert a BCD digit passed to it in the lower nibble of AccA to its ASCII character code. Can anyone show me how to write this program please?.. I have programmed program for Addition,substraction,multiplication,division and branching.. but this one i dont know how to start and what to do... Thank you all in advance for your help.. Regards.. By the way, is it safe to assume that AccA in your opening post refers to accummulator A? hgmjr Thread Starter NiCeBoY Joined Aug 20, 2008 59 yes AccA refers to Accumulator A.. thx.. Mark44 Joined Nov 26, 2007 628 Can anyone show me how to write this program please?.. I am required to write a program module to convert a BCD digit passed to it in the lower nibble of AccA to its ASCII character code. The upper nibble should be treated as a "don't care". Return the ASCII code in AccA and save in a suitable memory location. All other CPU register values are to remain unchanged. Regards.. BCD digits represent the decimal numbers 0 through 9, using four bits. They are 0000, 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001. The ASCII codes for the characters '0' through '9' are 48 through 57 in decimal, or 0x30 through 0x39 in hex. To convert a BCD number in the lower nibble of AccA, you need to do two things: 1. Mask off the upper nibble of AccA (by ANDing it with 0x0F). 2. Add 0x30 to what's in AccA. After that, save the contents of AccA to whatever memory location you're using. The steps above assume that the caller to your module passes an actual BCD digit in AccA. You could add logic to guarantee that what is passed is a BCD digit by checking that the low nibble is greater than or equal to 0 and less than or equal to 9. (This test would come before step 1, above.) Since your problem statement says that the caller will pass a BCD digit, you shouldn't need to do this test, but it's something to think about. Hope that helps, Mark Thread Starter NiCeBoY Joined Aug 20, 2008 59 hmm... I understand what we should do.. but the problem is how to code it... ORG$2000 ; Start
ANDA $0F ; And accumulator A with 0F(Hex) ADDA$30 ; Add 30(Hex) to accumulator A
STAA $2050 ; Store Acuumulator a in adress 2050 Can anyone help me out with the code plz..? thx hgmjr Joined Jan 28, 2005 9,029 Another approach that is used is this one. 1. Define a table that contains the 16 ASCII values for the digits 0 through 9 and A through F. 2. Use a lower nibble mask and add the resulting masked value as an offset into the table to fetch the ASCII value needed. For the upper digit, use an upper nibble mask together with a right-shift four bit positions. Then use the resulting value as an offset into the table to fetch the ASCII value needed. hgmjr Mark44 Joined Nov 26, 2007 628 hmm... I understand what we should do.. but the problem is how to code it... Rich (BB code): ORG$2000 ; Start
ANDA $0F ; And accumulator A with 0F(Hex) ADDA$30 ; Add 30(Hex) to accumulator A
STAA \$2050 ; Store Acuumulator a in adress 2050
Can anyone help me out with the code plz..?

thx
NiCeBoY,
You produced the code above. Have you tried it out? Why are you asking for more help?

NiCeBoY

Joined Aug 20, 2008
59
Yes man i tried this code... but the LECTURER told me this is not enough.. and is nothing compare to what he is expecting...

Then i showed his the steps that you gave me..
he told me this is what is need.. that is you are good..
But the problem is how to write the codes

Mark44

Joined Nov 26, 2007
628
Yes man i tried this code... but the LECTURER told me this is not enough.. and is nothing compare to what he is expecting...

Then i showed his the steps that you gave me..
he told me this is what is need.. that is you are good..
But the problem is how to write the codes
How to write the codes for what? You need to ask him to give you a clue about what he is expecting. There is no way to write the code if you don't know what it's supposed to do. The code I gave you should be sufficient for the requirements you gave in your first post. The only thing that might possibly be lacking is that the lecturer asked for a module, which suggests to me a subroutine or procedure, or whatever it might be called in 68HC11 assembly.