i have assembly code and want to convert to equivalent in c i think it is
addition but i want if it is only simple addition so need help and thnx in advance :
Flash_Check_SUM:
clr ZH
clr ZL
clr XH
clr XL
FCK_1:
lpm R1,z+
add XL,R1
brcc FCK_2
inc XH ;carry set so inc Hi Bit
FCK_2:
cpi ZH,HIGH(BSTART*2 -16)
brne FCK_1
cpi ZL,LOW(BSTART*2 -16)
brne FCK_1
lpm R0,Z+
lpm R1,Z
cp R0,XH
brne CK_Fail
cp R1,XL
brne CK_Fail
ret
CK_Fail:
Converting this to C code doesn't answer your actual question. A description of what the assembly is doing would be more helpful.
The X and Z registers are actually two registers each, so they are two bytes long. Some instructions use the Z register as an address to the input. That is what is happening in this code.
The function starts at address 0 and adds byte by byte to the 16-bit X register with
There is then some code to increment the high byte of X if the low byte overflows, (the usual addition algorithm).
The loop continues until Z reaches
BSTART*2 -16, which appears to be all the bytes before the checksum.The last part loads the stored checksum into R0 and R1, and then compares it to the checksum the code just computed in X (XH and XL).
If the checksum fails, then the code skips over the return statement and continues with the code following the checksum function, which presumably indicates an error condition of some sort to the user.