diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-07-20 08:41:57 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-07-20 08:43:25 -0700 |
commit | d0f39e75ca761bb9c5fa6889ea0703e3700990a2 (patch) | |
tree | 8c4bf813419efeafc1f25165311b764df9b57b47 /linux/apps | |
parent | 13ef425825cef5fa30f7eb68688b6d114ecbe554 (diff) | |
download | mu-d0f39e75ca761bb9c5fa6889ea0703e3700990a2.tar.gz |
.
Diffstat (limited to 'linux/apps')
-rw-r--r-- | linux/apps/random.subx | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/linux/apps/random.subx b/linux/apps/random.subx new file mode 100644 index 00000000..4b770d8f --- /dev/null +++ b/linux/apps/random.subx @@ -0,0 +1,59 @@ +# Repeatedly read 32-bit numbers from /dev/random, print them to stdout. +# +# To run: +# $ ./translate_subx [01]*.subx apps/random.subx +# $ ./a.elf + +== code 0x09000000 +# instruction effective address register displacement immediate +# . op subop mod rm32 base index scale r32 +# . 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes + +Entry: + # stream/esi = syscall_open("/dev/null", O_RDONLY, 0) # we can't use 'fd' because it looks like a hex byte + bb/copy-to-ebx Filename/imm32 + b9/copy-to-ecx 0/imm32/rdonly + ba/copy-to-edx 0x180/imm32/fixed-perms + e8/call syscall_open/disp32 + # . stream = eax + 89/copy 3/mod/direct 6/rm32/esi . . . 0/r32/eax . . # copy eax to esi + +$loop: + + # syscall_read(Stream, N, 4) + 89/copy 3/mod/direct 3/rm32/ebx . . . 6/r32/esi . . # copy esi to ebx + b9/copy-to-ecx N/imm32 + ba/copy-to-edx 4/imm32/size + e8/call syscall_read/disp32 + + # write-int32-hex-buffered(Stdout, *N) + # . . push args + ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . N/disp32 # push *N + 68/push Stdout/imm32 + # . . call + e8/call write-int32-hex-buffered/disp32 + + # write-buffered(Stdout, Newline) + # . . push args + 68/push Newline/imm32 + 68/push Stdout/imm32 + # . . call + e8/call write-buffered/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp + + eb/jump $loop/disp8 + + # syscall_exit(0) + bb/copy-to-ebx 0/imm32 + e8/call syscall_exit/disp32 + +== data 0x0a000000 + +N: + 0/imm32 +Filename: + 2f 64 65 76 2f 72 61 6e 64 6f 6d 00 +# / d e v / r a n d o m null + +# . . vim:nowrap:textwidth=0 |