Question
PIC18F program The objective of this problem is to compile and debug a C program using MPLAB C18 compiler, to add two 16-bit numbers, each
PIC18F program
The objective of this problem is to compile and debug a C program using MPLAB C18 compiler, to add two 16-bit numbers, each containing two ASCII numbers, and then store the result as a packed BCD byte.
a. Write a C language program to add two 16-bit numbers by converting each number from ASCII number representation into packed a BCD byte. b. Write a PIC18F assembly language program to accomplish the above.
Description ASCII numbers are 8-bit numbers with the high 4 bits as 00112 or 310. These numbers can be converted to packed BCD by masking off the high 4 bits. Since the numbers to be added are 16-bit wide, one can convert the numbers into 8-bit packed BCD by masking off the high 4 bits of each ASCII number. The high byte can be shifted 4 times to the left and logically ORed with the low byte. The two converted 8-bit packed BCD numbers can then be added.
Example
Convert two ASCII numbers and add them as follows:
1st two-digit ASCII number 3432H -> Convert to unpacked BCD 0402H -> Convert to packed BCD 42H
2nd two-digit ASCII number 3336H -> Convert to unpacked BCD 0306H -> Convert to packed BCD 36H
Add the two packed BCD bytes = 42H + 36H = 78H (Result)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started