Created
June 23, 2020 01:28
-
-
Save Silva97/f2f9f9e5040ce52fcab99f0ad0d60864 to your computer and use it in GitHub Desktop.
Implementação do algoritmo de checksum RFC 1071 em Assembly x86-64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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