# A Linux amd64 assembly program in meta5ix using gas syntax that # copies stdin to stdout, like cat. This generates a “compiler” that # consumes no input and compiles the empty string to the desired amd64 # program. - program: body - body: macros {.bss} @{buf:} {.equiv bufsiz, 128} {.fill bufsiz, 1, 0} {.text} {.globl _start} @{_start:} {read \$0, \$buf, \$bufsiz} {cmp \$0, %rax} {jle done} {write \$1, \$buf, %rax} {jmp _start} @{done:} {exit \$0} # Hmm, I guess the system call numbers change when we use the # `syscall` instruction instead of int $0x80. # # has the right ones, and # # says the first six arguments go in %rdi, %rsi, %rdx, %r10, %r8, and # %r9, and the return value is in %rax. We could define syscall, # read, write, etc., macros as meta5ix macros, but gas macros can take # *parameters*. - macros: {.macro sys4 n a b c d} {mov \\a, %rdi} {mov \\b, %rsi} {mov \\c, %rdx} {mov \\d, %r10} {mov \$\\n, %rax} {syscall} {.endm} {.macro exit k} {sys4 60 \\k \$0 \$0 \$0} {.endm} {.macro read fd buf count} {sys4 0 \\fd \\buf \\count \$0} {.endm} {.macro write fd buf count} {sys4 1 \\fd \\buf \\count \$0} {.endm}