Hello!
I'm new here, so please be patient witm me!
I need to write a simple code and the question is:
I need to tipe a program which runs on HCS12 microcontroler.
I must write a program that will run on HCS12, which adds up two 24-bits values, that are written down on locations $3000 to $3002 and the lowest nubmer is on location $3000 -lowest byte. and other 24-bit number is on location $3003 to $3005 and again the lower value in on location $3003.
result must be writen down as 24-bit number, that occupies location from $3006-$3008.
Shortly describe a concept of suming the numbers which are longer from 8-bits on
such microcontroler.
Thanks for any help given!
Hello, and welcome to the forum.
Since the 24-bit data is arranged in little endian format, it is probably simplest to treat the problem as three separate additions of single byte values, within three byte arrays. Had the data arrangement been big endian (native to the MCU), a different approach might be adopted.
The following code snippet provides a function uses this method. For simplicity, the snippet does not provide 24-bit overflow handling. This may need to be added.
void add24( char *p1, char *p2, char *pr){ unsigned int i, r, c = 0; for (i = 0; i < 3; i++) { r = p1[i] + p2[i] + c; c = r >> 8; pr[i] = (char)(r & 0x00FF); }}
The function would be called in the following manner -
// Global variables - little endian 24-bit formatbyte var1[3] @ 0x3000 = { 0x45, 0x23, 0x01}; // byte var2[3] @ 0x3003 = { 0xAB, 0x89, 0x67};byte var3[3] @ 0x3006; ... add24( var1, var2, var3);
Regards,
Mac
Hello!
Thanks for helpibg me!
Maybe I missed wrong part of forum, but program must be writed in code like:
LDX #0000
CLRA
LDAA $3000
ADDA $3001
...
Something in this way!
...and I have no idea what to do!
it's quite simple to do it on assembly, if you still need help let me know, i acctually made a 100 bit addition so it's failry simple to make it shorter