How to convert a code in Assembly language to C code? [closed]

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

lpm R1,z+  ; load the byte at address Z into R1 and post-increment Z
add XL,R1  ; Add R1 to X

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.

Browse More Popular Posts

Leave a Comment