diff options
Diffstat (limited to '')
-rw-r--r-- | pasmgen.asm | 94 |
1 files changed, 75 insertions, 19 deletions
diff --git a/pasmgen.asm b/pasmgen.asm index bbd4c37..ffcce2c 100644 --- a/pasmgen.asm +++ b/pasmgen.asm @@ -1,6 +1,6 @@ format ELF64 executable -macro genclass class, class_len, caps +macro genclass class, class_len { ;; Generate 16 bits (smallest) of randomness from the cpu rdrand ax @@ -13,45 +13,84 @@ macro genclass class, class_len, caps ;; Save output letter into out_buf, bump rcx add rdx, class mov rdx, [rdx] - if caps eq 1 - sub rdx, 32 - end if mov [rcx], rdx inc rcx inc rsi } -macro triplet -{ - genclass consonants, consonants_len - genclass vowels, vowels_len - genclass consonants, consonants_len -} - segment readable executable entry main main: + ;; No arg preload case + cmp [rsp], word 1 + jne argparse + + mov r8, qword 3 + mov r9, qword 2 + mov r10, qword 3 + + jmp generate + +argparse: + ;; Check args (need 3) + cmp [rsp], word 3 + jle fail + + ;; load arg1 + mov r8, [rsp+16] + mov r8, [r8] + and r8, 0xFF + sub r8, 48 + + ;; load arg2 + mov r9, [rsp+24] + mov r9, [r9] + and r9, 0xFF + sub r9, 48 + + ;; load arg3 + mov r10, [rsp+32] + mov r10, [r10] + and r10, 0xFF + sub r10, 48 + +generate: ;; Store which output byte we're up to in rcx mov rcx, out_buf ;; Store chars generated in rsi xor rsi, rsi - genclass consonants, consonants_len, 1 +tripleter: + genclass consonants, consonants_len genclass vowels, vowels_len genclass consonants, consonants_len - triplet - triplet - genclass symbols, symbols_len + dec r8 + test r8, r8 + jnz tripleter +symboler: genclass symbols, symbols_len + dec r9 + test r9, r9 + jnz symboler +numberer: genclass numbers, numbers_len - genclass numbers, numbers_len - genclass numbers, numbers_len + dec r10 + test r10, r10 + jnz numberer + ;; Append new line to string mov [rcx], word 10 inc rsi - + + ;; Special case to caps the first character + xor rax, rax + mov al, byte [out_buf] + sub al, 32 + mov rbx, out_buf + mov [rbx], al + ;; Write mov rdi, 1 ;; stdout mov rdx, rsi @@ -63,9 +102,26 @@ main: mov rdi, 0 mov rax, 0x3c syscall + +fail: + ;; Write + mov rdi, 1 ;; stdout + mov rsi, usage + mov rdx, usage_len + mov rax, 0x01 + syscall + + ;; Exit 1 + mov rdi, 1 + mov rax, 0x3c + syscall + segment readable writeable +usage db "usage: passmgen [<triplet#> <symbol#> <number#>]", 10 +usage_len = $ - usage + numbers db "0123456789" numbers_len = $ - numbers vowels db "aeiou" @@ -75,4 +131,4 @@ consonants_len = $ - consonants symbols db "!@#$%&()-=_+[]{}\\|;<>/?." symbols_len = $ - symbols -out_buf rb 32 +out_buf rb 64 |