Old crc16 is now a .asm
This commit is contained in:
45
src/crc16.asm
Normal file
45
src/crc16.asm
Normal file
@@ -0,0 +1,45 @@
|
||||
CPU 8086
|
||||
|
||||
_start:
|
||||
push bp
|
||||
mov bp, sp
|
||||
mov si, [bp+8]
|
||||
push word [si]
|
||||
mov si, [bp+10]
|
||||
push word [si]
|
||||
call crc16
|
||||
mov di, [bp+6]
|
||||
mov [di], ax
|
||||
mov sp, bp
|
||||
pop bp
|
||||
retf 6
|
||||
|
||||
crc16:
|
||||
push bp
|
||||
mov bp, sp
|
||||
mov bx, [bp+4]
|
||||
add [bp+6], bx
|
||||
mov ax, -1
|
||||
.L2:
|
||||
cmp bx, [bp+6]
|
||||
jne .L5
|
||||
pop bp
|
||||
ret
|
||||
.L5:
|
||||
mov dl, [bx]
|
||||
mov cl, 0x8
|
||||
shl dx, cl
|
||||
xor ax, dx
|
||||
mov dl, cl
|
||||
.L4:
|
||||
mov cx, ax
|
||||
shl cx, 1
|
||||
test ax, ax
|
||||
xchg cx, ax
|
||||
jge .L3
|
||||
xor ax, 4129
|
||||
.L3:
|
||||
dec dl
|
||||
jne .L4
|
||||
inc bx
|
||||
jmp .L2
|
57
src/crc16.s
57
src/crc16.s
@@ -1,57 +0,0 @@
|
||||
.arch i8086,jumps
|
||||
.code16
|
||||
.att_syntax prefix
|
||||
#NO_APP
|
||||
#APP
|
||||
.section .text.init
|
||||
.global _start
|
||||
_start:
|
||||
|
||||
.section .text.main
|
||||
.global main
|
||||
main:
|
||||
push %bp
|
||||
mov %sp, %bp
|
||||
mov 8(%bp), %si
|
||||
push (%si)
|
||||
call crc16
|
||||
add $0x2, %sp
|
||||
mov 6(%bp), %di
|
||||
mov %ax, (%di)
|
||||
pop %bp
|
||||
lret $4
|
||||
|
||||
#NO_APP
|
||||
.text
|
||||
.global crc16
|
||||
.type crc16, @function
|
||||
crc16:
|
||||
pushw %bp
|
||||
movw %sp, %bp
|
||||
xorw %bx, %bx
|
||||
movw $-1, %ax
|
||||
.L2:
|
||||
cmpw 4(%bp), %bx
|
||||
jne .L5
|
||||
popw %bp
|
||||
ret
|
||||
.L5:
|
||||
movb %cs:(%bx), %dl
|
||||
movb $8, %cl
|
||||
shlw %cl, %dx
|
||||
xorw %dx, %ax
|
||||
movb %cl, %dl
|
||||
.L4:
|
||||
movw %ax, %cx
|
||||
shlw $1, %cx
|
||||
testw %ax, %ax
|
||||
xchgw %ax, %cx
|
||||
jge .L3
|
||||
xorw $4129, %ax
|
||||
.L3:
|
||||
decb %dl
|
||||
jne .L4
|
||||
incw %bx
|
||||
jmp .L2
|
||||
.size crc16, .-crc16
|
||||
.ident "GCC: (GNU) 6.3.0"
|
Reference in New Issue
Block a user