From 3364d19cd1fb854846e76b75abce081b5cdcf220 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Thu, 20 Sep 2018 21:34:56 -0700 Subject: 4561 --- subx/examples/ex4.subx | 22 +++++++++++----------- subx/examples/ex5.subx | 24 ++++++++++++------------ subx/examples/ex6.subx | 12 ++++++------ subx/examples/ex7.subx | 42 +++++++++++++++++++++--------------------- subx/examples/ex8.subx | 2 +- 5 files changed, 51 insertions(+), 51 deletions(-) (limited to 'subx/examples') diff --git a/subx/examples/ex4.subx b/subx/examples/ex4.subx index 89b3bdc9..f018092b 100644 --- a/subx/examples/ex4.subx +++ b/subx/examples/ex4.subx @@ -9,29 +9,29 @@ # 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 - ## read(stdin, x, 1) - # fd = 0 (stdin) + # read(stdin, x, 1) + # fd = 0 (stdin) bb/copy 0/imm32 # copy 0 to EBX - # initialize x (location to write result to) + # initialize x (location to write result to) b9/copy x/imm32 # copy to ECX - # size = 1 character + # size = 1 character ba/copy 1/imm32 # copy 1 to EDX - # read(fd, x, size) + # read(fd, x, size) b8/copy 3/imm32 # copy 3 to EAX cd/syscall 0x80/imm8 # int 80h - ## write(stdout, x, 1) - # fd = 1 (stdout) + # write(stdout, x, 1) + # fd = 1 (stdout) bb/copy 1/imm32 # copy 1 to EBX - # initialize x (location to read from) + # initialize x (location to read from) b9/copy x/imm32 # copy to ECX - # size = 1 character + # size = 1 character ba/copy 1/imm32 # copy 1 to EDX - # write(fd, x, size) + # write(fd, x, size) b8/copy 4/imm32 # copy 4 to EAX cd/syscall 0x80/imm8 # int 80h - ## exit(EBX) + # exit(EBX) b8/copy 1/imm32 # copy 1 to EAX cd/syscall 0x80/imm8 # int 80h diff --git a/subx/examples/ex5.subx b/subx/examples/ex5.subx index 400e17c3..a0bb9d48 100644 --- a/subx/examples/ex5.subx +++ b/subx/examples/ex5.subx @@ -9,36 +9,36 @@ # 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 -## function main +# main: # prolog 55/push # push EBP 89/copy 3/mod/direct 5/rm32/EBP 4/r32/ESP # copy ESP to EBP # allocate x on the stack 81 5/subop/subtract 3/mod/direct 4/rm32/ESP 4/imm32 # subtract 4 bytes from ESP - ## read(stdin, x, 1) - # fd = 0 (stdin) + # read(stdin, x, 1) + # fd = 0 (stdin) bb/copy 0/imm32 # copy 0 to EBX - # initialize x (location to write result to) + # initialize x (location to write result to) 89/copy 3/mod/direct 1/rm32/ECX 5/r32/EBP # copy EBP to ECX - # size = 1 character + # size = 1 character ba/copy 1/imm32 # copy 1 to EDX - # read(fd, x, size) + # read(fd, x, size) b8/copy 3/imm32 # copy 3 to EAX cd/syscall 0x80/imm8 # int 80h - ## write(stdout, x, 1) - # fd = 1 (stdout) + # write(stdout, x, 1) + # fd = 1 (stdout) bb/copy 1/imm32 # copy 1 to EBX - # initialize x (location to read from) + # initialize x (location to read from) 89/copy 3/mod/direct 1/rm32/ECX 5/r32/EBP # copy EBP to ECX - # size = 1 character + # size = 1 character ba/copy 1/imm32 # copy 1 to EDX - # write(fd, x, size) + # write(fd, x, size) b8/copy 4/imm32 # copy 4 to EAX cd/syscall 0x80/imm8 # int 80h - ## exit(EBX) + # exit(EBX) b8/copy 1/imm32 # copy 1 to EAX cd/syscall 0x80/imm8 # int 80h diff --git a/subx/examples/ex6.subx b/subx/examples/ex6.subx index 567c2e24..c2de9c19 100644 --- a/subx/examples/ex6.subx +++ b/subx/examples/ex6.subx @@ -10,18 +10,18 @@ # 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 - ## write(stdout, x, size) - # fd = 1 (stdout) + # write(stdout, x, size) + # fd = 1 (stdout) bb/copy 1/imm32 # copy 1 to EBX - # initialize x (location to write result to) + # initialize x (location to write result to) b9/copy x/imm32 # copy to ECX - # initialize size + # initialize size 8b/copy 0/mod/indirect 5/rm32/.disp32 2/r32/EDX size/disp32 # copy *size to EDX - # write(fd, x, size) + # write(fd, x, size) b8/copy 4/imm32 # copy 4 to EAX cd/syscall 0x80/imm8 # int 80h - ## exit(EBX) + # exit(EBX) b8/copy 1/imm32 # copy 1 to EAX cd/syscall 0x80/imm8 # int 80h diff --git a/subx/examples/ex7.subx b/subx/examples/ex7.subx index 6e0294d9..c3265c21 100644 --- a/subx/examples/ex7.subx +++ b/subx/examples/ex7.subx @@ -15,78 +15,78 @@ # 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 - ## creat(filename) + # creat(filename) bb/copy . . . . . . . filename/imm32 # copy to EBX b9/copy . . . . . . . 0x180/imm32/fixed-perms # copy to ECX b8/copy . . . . . . . 8/imm32/creat # copy 8 to EAX cd/syscall . . . . . . . 0x80/imm8 # int 80h - ## stream = open(filename, O_WRONLY, 0) # we can't use 'fd' because it looks like a hex byte + # stream = open(filename, O_WRONLY, 0) # we can't use 'fd' because it looks like a hex byte bb/copy . . . . . . . filename/imm32 # copy to EBX b9/copy . . . . . . . 1/imm32/wronly # copy 1 to ECX ba/copy . . . . . . . 0x180/imm32/fixed-perms # copy 0 to EDX b8/copy . . . . . . . 5/imm32/open # copy 5 to EAX cd/syscall . . . . . . . 0x80/imm8 # int 80h - # save stream + # save stream bb/copy . . . . . . . stream/imm32 # copy to EBX 89/copy 0/mod/indirect 3/rm32/EBX 0/r32/EAX # copy EAX to *EBX - ## write(stream, "a", 1) - # load stream + # write(stream, "a", 1) + # load stream bb/copy . . . . . . . stream/imm32 # copy to EBX 8b/copy 0/mod/indirect 3/rm32/EBX 3/r32/EBX # copy *EBX to EBX - # + # b9/copy . . . . . . . a/imm32 # copy to ECX ba/copy . . . . . . . 1/imm32/size # copy 1 to EDX b8/copy . . . . . . . 4/imm32/write # copy 4 to EAX cd/syscall . . . . . . . 0x80/imm8 # int 80h - ## close(stream) - # load stream + # close(stream) + # load stream bb/copy . . . . . . . stream/imm32 # copy to EBX 8b/copy 0/mod/indirect 3/rm32/EBX 3/r32/EBX # copy *EBX to EBX - # + # b8/copy . . . . . . . 6/imm32/close # copy 6 to EAX cd/syscall . . . . . . . 0x80/imm8 # int 80h - ## stream = open(filename, O_RDONLY, 0) + # stream = open(filename, O_RDONLY, 0) bb/copy . . . . . . . filename/imm32 # copy to EBX b9/copy . . . . . . . 0/imm32/rdonly # copy 0 to ECX ba/copy . . . . . . . 0x180/imm32/fixed-perms # copy to EDX b8/copy . . . . . . . 5/imm32/open # copy 5 to EAX cd/syscall . . . . . . . 0x80/imm8 # int 80h - # save stream + # save stream bb/copy . . . . . . . stream/imm32 # copy to EBX 89/copy 0/mod/indirect 3/rm32/EBX 0/r32/EAX # copy EAX to *EBX - ## read(stream, b, 1) - # load stream + # read(stream, b, 1) + # load stream bb/copy . . . . . . . stream/imm32 # copy to EBX 8b/copy 0/mod/indirect 3/rm32/EBX 3/r32/EBX # copy *EBX to EBX - # + # b9/copy . . . . . . . b/imm32 # copy to ECX ba/copy . . . . . . . 1/imm32/size # copy 1 to EDX b8/copy . . . . . . . 3/imm32/read # copy 3 to EAX cd/syscall . . . . . . . 0x80/imm8 # int 80h - ## close(stream) - # load stream + # close(stream) + # load stream bb/copy . . . . . . . stream/imm32 # copy to EBX 8b/copy 0/mod/indirect 3/rm32/EBX 3/r32/EBX # copy *EBX to EBX - # + # b8/copy . . . . . . . 6/imm32/close # copy 6 to EAX cd/syscall . . . . . . . 0x80/imm8 # int 80h - ## unlink(filename) + # unlink(filename) bb/copy . . . . . . . filename/imm32 # copy to EBX b8/copy . . . . . . . 0xa/imm32/unlink # copy 10 to EAX cd/syscall . . . . . . . 0x80/imm8 # int 80h - ## exit(b) - # load b + # exit(b) + # load b bb/copy . . . . . . . b/imm32 # copy to EBX 8b/copy 0/mod/indirect 3/rm32/EBX 3/r32/EBX # copy *EBX to EBX - # + # b8/copy . . . . . . . 1/imm32/exit # copy 1 to EAX cd/syscall . . . . . . . 0x80/imm8 # int 80h diff --git a/subx/examples/ex8.subx b/subx/examples/ex8.subx index 452b917d..ab150a17 100644 --- a/subx/examples/ex8.subx +++ b/subx/examples/ex8.subx @@ -1,4 +1,4 @@ -# Example reading commandline arguments: compute length of first arg. +## Example reading commandline arguments: compute length of first arg. # # To run: # $ subx translate ex9.subx ex9 -- cgit 1.4.1-2-gfad0