summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2018-11-28 22:39:59 +0100
committerNao Pross <naopross@thearcway.org>2018-11-28 22:39:59 +0100
commitc3cf8166784515eff25e415535628645d402cb66 (patch)
treedaab64d5518cc9f3bb38d56bbefec4758d7363fe
parentAdd main loop to read more than 5 bytes (diff)
downloadbase32asm-c3cf8166784515eff25e415535628645d402cb66.tar.gz
base32asm-c3cf8166784515eff25e415535628645d402cb66.zip
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.
Diffstat (limited to '')
-rw-r--r--b32e.asm15
1 files changed, 11 insertions, 4 deletions
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