Initial commit: try make binaries
This commit is contained in:
34
crc16.c
Normal file
34
crc16.c
Normal file
@@ -0,0 +1,34 @@
|
||||
#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"
|
||||
);
|
Reference in New Issue
Block a user