summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2018-11-29 00:05:39 +0100
committerNao Pross <naopross@thearcway.org>2018-11-29 00:16:27 +0100
commit0c5dffe44ee1a13ab38041de73e3d0373458375e (patch)
tree9c9bfcd6b0b3890c7da2a2ef88510e637969970a
parentAdd padding to output (diff)
downloadbase32asm-0c5dffe44ee1a13ab38041de73e3d0373458375e.tar.gz
base32asm-0c5dffe44ee1a13ab38041de73e3d0373458375e.zip
Add b32d for future decoder implementation, update test
-rw-r--r--.gitignore1
-rw-r--r--b32d.asm47
-rw-r--r--makefile25
3 files changed, 67 insertions, 6 deletions
diff --git a/.gitignore b/.gitignore
index 7fc285c..bedbda2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@ b32e
b32d
*.o
+*.b32
diff --git a/b32d.asm b/b32d.asm
new file mode 100644
index 0000000..aa7582b
--- /dev/null
+++ b/b32d.asm
@@ -0,0 +1,47 @@
+section .bss
+
+input_buffer resb 8
+output_buffer resb 8
+
+section .text
+global _start
+
+; read_input
+; reads 5 bytes (40 bits) of input
+; uses reg: rax, rdi, rsi, rdx
+; uses mem: input_buffer
+read_input:
+ ; linux x64 read(stdin, input_buffer, 5)
+ mov rax, 0
+ mov rdi, 0
+ mov rsi, input_buffer
+ mov rdx, 5
+ syscall
+ ret
+
+; write_output
+; writes the output buffer to stdout
+; uses reg: rax, rdi, rsi, rdx
+; uses mem: output_buffer(ro)
+write_output:
+ ; linux x64 write(stdout, output_buffer, 8)
+ mov rax, 1
+ mov rdi, 1
+ mov rsi, output_buffer
+ mov rdx, 8
+ syscall
+ ret
+
+; b32d
+; decodes 8 RFC4648 characters without checking its validity (!!!)
+; uses reg:
+; uses mem: input_buffer, output_buffer
+b32d:
+ ret
+
+_start:
+.exit:
+ ; linux x64 exit(0)
+ mov rax, 60
+ mov rdi, 0
+ syscall
diff --git a/makefile b/makefile
index bc75f79..bf4860b 100644
--- a/makefile
+++ b/makefile
@@ -1,15 +1,28 @@
-all: b32e
- # test b32e hello
- echo -n "hello" | ./b32e
- @printf '\n'
- echo -n "hello" | base32 -i
+.PHONY: all
+all: b32e b32d
+.PHONY: test
+test: b32e b32d
+ cat makefile | ./b32e > makefile.b32
+ cat makefile | base32 -w 0 > makefile.check.b32
+
+ cat makefile.b32 | ./b32d
+ cat makefile.check.b32 | base32 -d
+
+# encoder
b32e: b32e.o
ld -o $@ $<
b32e.o: b32e.asm
nasm -f elf64 -g -F dwarf -O0 -w+all -o $@ $<
+# decoder
+b32d: b32d.o
+ ld -o $@ $<
+
+b32d.o: b32d.asm
+ nasm -f elf64 -g -F dwarf -O0 -w+all -o $@ $<
+
.PHONY: clean
clean:
- rm -f *.o b32e b32d
+ rm -f *.o b32e b32d *.b32