#include <STC15F2K60S2.h>
void clear_ram(void)
{
    unsigned char i;
    for(i = 0x30; i <= 0x60; i++)
    {
        *(unsigned char volatile xdata *)i = 0; 
    }
}

unsigned char bcd_to_ascii(unsigned char bcd)
{
    return bcd + '0'; 
}

void bcd_add(unsigned char *src1, unsigned char *src2, unsigned char *dest)
{
    unsigned char temp;
    temp = src1[0] + src2[0];
    if(temp > 0x99)  
    {
        temp -= 0x60; 
        dest[0] = temp % 0x10; 
        temp = temp / 0x10 + 1; 
    }
    else
    {
        dest[0] = temp % 0x10;
        temp = temp / 0x10;
    }
    temp += src1[1] + src2[1];
    if(temp > 0x99)
    {
        temp -= 0x60;
        dest[1] = temp % 0x10;
        dest[2] = temp / 0x10; 
    }
    else
    {
        dest[1] = temp % 0x10;
        dest[2] = temp / 0x10;
    }
}

void move_ram(void)
{
    unsigned char i;
    for(i = 0; i < 40; i++)
    {
        *(unsigned char volatile xdata *)(0x20 + i) = *(unsigned char volatile xdata *)(0x1000 + i);
    }
}

void main(void)
{
    unsigned char bcd_data = 0x05;
    unsigned char bcd1[2] = {0x12, 0x34};  
    unsigned char bcd2[2] = {0x56, 0x78}; 
    unsigned char bcd_result[3] = {0}; 
    unsigned char ascii; 
    
    clear_ram();
    
    ascii = bcd_to_ascii(bcd_data);
    
    bcd_add(bcd1, bcd2, bcd_result);
    
    move_ram();
    
    while(1);
}