fork.ll (767B)
1 (unix core) |0x0 @stdin |0x1 @stdout |0x2 @stderr |0x3 @syscall |0x4 @arg1 |0x8 @arg2 |0xc @arg3 |0x10 @arg4 |0x14 @result |0x18 @fd |0x1c @read |0x1d @write 2 3 |0x100 @file "test.txt b0 4 5 @parent (writes the letter A to the file marked at @file) 6 &file &arg1 storei (opens the file) 7 #1 &arg2 storei 8 #1 i2b &syscall storeb 9 10 &result loadi (gets the fd) 11 &fd storei 12 13 #65 i2b &write storeb (write the letter) 14 15 &fd loadi &arg1 storei (close the file) 16 #2 i2b &syscall storeb 17 ret 18 19 @child (writes the letter B to stdout) 20 #66 i2b &stdout storeb (writes to stdout) 21 ret 22 23 (main) |0x1000 24 #4 i2b &syscall storeb 25 26 &result loadi 27 #0 neq (if fork != 0) 28 &true jnz 29 &false jmp 30 @true (fork != 0) 31 &parent call 32 &end jmp 33 @false (fork == 0) 34 &child call 35 &end jmp 36 @end 37 38 halt