From c3cf8166784515eff25e415535628645d402cb66 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Wed, 28 Nov 2018 22:39:59 +0100 Subject: Swap bytes (endianness) The problem with the code until now, was that x64 is little endian. Therefore when the input buffer is loaded into a register to perform a bit operation (i.e shift) the result was messed up. --- b32e.asm | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'b32e.asm') diff --git a/b32e.asm b/b32e.asm index af02dc3..7f0b14a 100644 --- a/b32e.asm +++ b/b32e.asm @@ -49,19 +49,19 @@ b32e: xor rbx, rbx ; get a byte from the input - mov bl, byte [input_buffer] + mov bl, byte [input_buffer + 4] ; mask and shift to get 5 bits which is a number in 0 ~ 31 and bl, 0xf8 shr bl, 3 - ; rshift the input buffer - shr qword [input_buffer], 5 + ; shift left the input buffer + shl qword [input_buffer], 5 ; convert to base32 add rbx, rfc4648 mov dl, byte [rbx] - mov [output_buffer + r11], dl + mov byte [output_buffer + r11], dl ; increase counter inc r11 @@ -85,6 +85,13 @@ _start: cmp rax, 0 je .exit + ; swap endianness of input + mov rax, qword [input_buffer] + bswap rax + ; correct position in qword + shr rax, 24 + mov qword [input_buffer], rax + ; convert to base 32 call b32e ; print -- cgit v1.2.1