Skip to content

Instantly share code, notes, and snippets.

@Silva97
Created June 23, 2020 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Silva97/f2f9f9e5040ce52fcab99f0ad0d60864 to your computer and use it in GitHub Desktop.
Save Silva97/f2f9f9e5040ce52fcab99f0ad0d60864 to your computer and use it in GitHub Desktop.
Implementação do algoritmo de checksum RFC 1071 em Assembly x86-64
; Implementação do algoritmo de checksum RFC 1071 em Assembly x86-64.
; Exercício proposto pelo Frederico Pissarra.
bits 64
default rel
section .text
; unsigned short cksum( void *ptr, size_t size );
; Entrada: RDI = ptr
; RSI = size
; Saída: AX
global cksum
cksum:
xor eax, eax
.lpSum:
cmp rsi, 1
jng .lpSumEnd
movzx ecx, word [rdi]
add eax, ecx
add rdi, 2
sub rsi, 2
jmp .lpSum
.lpSumEnd:
cmp rsi, 0
jng .lpShift
movzx ecx, byte [rdi]
add eax, ecx
.lpShift:
mov ecx, eax
shr ecx, 16
jz .lpShiftEnd
and eax, 0xffff
add eax, ecx
jmp .lpShift
.lpShiftEnd:
not eax
xchg ah, al
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment