From 0583f594c484ccd9ea3986a21dd670cabb9edc39 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Tue, 27 Nov 2018 19:54:02 +0100 Subject: Initial implementation of encoder --- .gitignore | 4 ++++ b32e.asm | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ makefile | 5 +++++ 3 files changed, 76 insertions(+) create mode 100644 .gitignore create mode 100644 b32e.asm create mode 100644 makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7fc285c --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +b32e +b32d + +*.o diff --git a/b32e.asm b/b32e.asm new file mode 100644 index 0000000..b74d7d7 --- /dev/null +++ b/b32e.asm @@ -0,0 +1,67 @@ +section .data + +rfc4648 db 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567' + +section .bss + +input_buffer resb 5 +output_buffer resb 8 + +section .text +global _start + +; read_input +; reads 5 bytes (40 bits) of input +read_input: + ; linux x64 read(stdin, input_buffer, 5) + mov rax, 0 + mov rdi, 0 + mov rsi, input_buffer + mov rdx, 5 + syscall + +; write_output +; writes the output buffer to stdout +write_output: + ; linux x64 write(stdout, output_buffer, 8) + mov rax, 1 + mov rdi, 1 + mov rsi, output_buffer + mov rdx, 5 + syscall + +; b32e +; encodes 40 bits (5 bytes) to 8 RFC4648 base32 characters +; inputs: bl=5 bits +; uses: rxb, rdx, r11 +b32e: + ; set up outputs counter + xor r11, r11 +.loop: + ; get 5 bits from the input + xor rbx, rbx + mov bl, byte [input_buffer] + and bl, 0x1f + + ; rshift the input buffer + + ; convert to base32 + add rbx, rfc4648 + mov dl, byte [rbx] + mov byte [output_buffer + r11], dl + + ; increase counter + inc r11 + cmp r11, 8 + js .loop + + +_start: + nop + call read_input + call b32e + + ; linux x64 exit(0) + mov rax, 60 + mov rdi, 0 + syscall diff --git a/makefile b/makefile new file mode 100644 index 0000000..a5df0c9 --- /dev/null +++ b/makefile @@ -0,0 +1,5 @@ +b32e: b32e.o + ld -o $@ $< + +b32e.o: b32e.asm + nasm -f elf64 -O0 -w+all -o $@ $< -- cgit v1.2.1