summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2018-11-28 21:22:11 +0100
committerNao Pross <naopross@thearcway.org>2018-11-28 21:22:11 +0100
commit095687abc7ee78c637cb142e85e2e2f48dd37785 (patch)
treeed5db4823a4a6d4c300ca1a520501ff73984a9fc
parentSet input buffer to be 8 bytes to fit in a register for shl (diff)
downloadbase32asm-095687abc7ee78c637cb142e85e2e2f48dd37785.tar.gz
base32asm-095687abc7ee78c637cb142e85e2e2f48dd37785.zip
Use 4 spaces for indent, update comments, change input buffer shift direction
Diffstat (limited to '')
-rw-r--r--b32e.asm99
1 files changed, 56 insertions, 43 deletions
diff --git a/b32e.asm b/b32e.asm
index ada7ff0..9c136dd 100644
--- a/b32e.asm
+++ b/b32e.asm
@@ -12,63 +12,76 @@ 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
+ ; 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, 5
- syscall
- ret
+ ; linux x64 write(stdout, output_buffer, 8)
+ mov rax, 1
+ mov rdi, 1
+ mov rsi, output_buffer
+ mov rdx, 5
+ syscall
+ ret
; b32e
; encodes 40 bits (5 bytes) to 8 RFC4648 base32 characters
-; inputs: bl=5 bits
-; uses: rxb, rdx, r11
+; uses reg: rbx, rdx, r11
+; uses mem: input_buffer, output_buffer
b32e:
- ; set up outputs counter
- xor r11, r11
+ ; set up output counter
+ xor r11, r11
+
.loop:
- ; get 5 bits from the input
- xor rbx, rbx
- mov bl, byte [input_buffer]
- ; mask and shift to convert to a number 0 ~ 32
- and bl, 0xf8
- shr bl, 3
+ ; clear rbx
+ xor rbx, rbx
+
+ ; get a byte from the input
+ mov bl, byte [input_buffer]
+
+ ; 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
+
+ ; convert to base32
+ add rbx, rfc4648
+ mov dl, byte [rbx]
+ mov [output_buffer + r11], dl
- ; rshift the input buffer
- shl qword [input_buffer], 5
+ ; increase counter
+ inc r11
- ; convert to base32
- add rbx, rfc4648
- mov dl, byte [rbx]
- mov byte [output_buffer + r11], dl
+ ; check counter
+ ; when the counter reaches 8 it means that 8 characters (40 bits)
+ ; have been processed and written
+ cmp r11, 8
+ js .loop
- ; increase counter
- inc r11
- cmp r11, 8
- js .loop
- ret
+ ret
_start:
- nop
- call read_input
- call b32e
- call write_output
+ nop
+ call read_input
+ call b32e
+ call write_output
.exit:
- ; linux x64 exit(0)
- mov rax, 60
- mov rdi, 0
- syscall
+ ; linux x64 exit(0)
+ mov rax, 60
+ mov rdi, 0
+ syscall