summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--b32e.asm27
1 files changed, 21 insertions, 6 deletions
diff --git a/b32e.asm b/b32e.asm
index c7ef93b..8bab796 100644
--- a/b32e.asm
+++ b/b32e.asm
@@ -38,11 +38,18 @@ write_output:
; b32e
; encodes 40 bits (5 bytes) to 8 RFC4648 base32 characters
-; uses reg: rbx, r11
+; uses reg: rax(in: bytes read), rbx, rcx, r11
; uses mem: input_buffer, output_buffer
b32e:
+ ; save the number of bits read in cl
+ mov bl, 8 ; each byte contains 8 bits
+ mul bl
+ mov cl, al
; set up output counter
xor r11, r11
+ ; initialize output buffer with padding
+ mov rbx, 0x3d3d3d3d3d3d3d3d
+ mov qword [output_buffer], rbx
.loop:
; clear rbx
@@ -66,12 +73,20 @@ b32e:
; increase counter
inc r11
+ ; check number of bits converted >= bits read
+ mov bl, 5 ; each iteration processed 5 bits
+ mov rax, r11
+ mul bl
+ cmp al, cl
+ jge .exit
+
; check counter
; when the counter reaches 8 it means that 8 characters (40 bits)
; have been processed and written
cmp r11, 8
- js .loop
+ jl .loop
+.exit:
ret
@@ -86,11 +101,11 @@ _start:
je .exit
; swap endianness of input
- mov rax, qword [input_buffer]
- bswap rax
+ mov rbx, qword [input_buffer]
+ bswap rbx
; correct position in qword
- shr rax, 24
- mov qword [input_buffer], rax
+ shr rbx, 24
+ mov qword [input_buffer], rbx
; convert to base 32
call b32e