35 lines
836 B
C
35 lines
836 B
C
#include <stdint.h>
|
|
|
|
#define kDataAddr ((uint8_t*) 0x0000)
|
|
|
|
uint16_t crc16(int data_len) {
|
|
const uint8_t* data = kDataAddr;
|
|
|
|
uint16_t crc = 0xFFFF;
|
|
for (unsigned int i = 0; i < data_len; ++i) {
|
|
uint16_t dbyte = data[i];
|
|
crc ^= dbyte << 8;
|
|
for (unsigned char j = 0; j < 8; ++j) {
|
|
uint16_t mix = crc & 0x8000;
|
|
crc = (crc << 1);
|
|
if (mix)
|
|
crc = crc ^ 0x1021;
|
|
}
|
|
}
|
|
return crc;
|
|
}
|
|
|
|
asm (
|
|
".global main \n"
|
|
"main: \n"
|
|
" push %bp \n"
|
|
" mov %sp, %bp \n"
|
|
" mov 6(%bp), %si \n"
|
|
" push (%si) \n"
|
|
" call crc16 \n"
|
|
" mov 8(%bp), %di \n"
|
|
" mov %ax, (%di) \n"
|
|
" pop %bp \n"
|
|
" lret $4 \n"
|
|
);
|