about summary refs log tree commit diff stats
path: root/examples/ex1.subx
blob: 0aca40f8aa2b7772dc9499661c06902c14ffa575 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# First program: same as https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html
# Just return 42.
#
# To run (from the subx directory):
#   $ ./subx translate examples/ex1.2.subx -o examples/ex1
#   $ ./subx run examples/ex1
# Expected result:
#   $ echo $?
#   42

== code 0x09000000

Entry:
# syscall(exit, 42)
bb/copy-to-EBX  2a/imm32  # 42 in hex
b8/copy-to-EAX  1/imm32/exit
cd/syscall  0x80/imm8

== data 0x0a000000

# . . vim:nowrap:textwidth=0
eax 8/imm32 cd/syscall 0x80/imm8 syscall_read: # fd/ebx : int, buf/ecx : addr, size/edx : int -> nbytes-or-error/eax : int b8/copy-to-eax 2/imm32 cd/syscall 0x80/imm8 c3/return syscall_write: # fd/ebx : int, buf/ecx : addr, size/edx : int -> nbytes-or-error/eax : int b8/copy-to-eax 3/imm32 cd/syscall 0x80/imm8 c3/return syscall_open: # filename/ebx : (addr kernel-string), flags/ecx : int -> fd-or-error/eax : int b8/copy-to-eax 0/imm32 cd/syscall 0x80/imm8 c3/return syscall_close: # fd/ebx : int -> status/eax b8/copy-to-eax 1/imm32 cd/syscall 0x80/imm8 c3/return # anonymous mmap not implemented