about summary refs log tree commit diff stats
path: root/069allocate.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-09-19 15:19:07 -0700
committerKartik Agaram <vc@akkartik.com>2019-09-19 15:19:07 -0700
commit68666b07b88fb4d72ff824550dd271b84520fdf5 (patch)
tree6ee85e0ba43f7f3a6750aca8f9e276eff737d06c /069allocate.subx
parenta9d473e22426a7636980b8266e9b48cbae3bba05 (diff)
downloadmu-68666b07b88fb4d72ff824550dd271b84520fdf5.tar.gz
5669
Diffstat (limited to '069allocate.subx')
-rw-r--r--069allocate.subx28
1 files changed, 28 insertions, 0 deletions
diff --git a/069allocate.subx b/069allocate.subx
index 8845c8c3..f7063d2e 100644
--- a/069allocate.subx
+++ b/069allocate.subx
@@ -16,11 +16,39 @@
 # very same 'allocate' helper. They just need a new allocation descriptor for
 # their book-keeping.
 
+# A default allocation descriptor for programs to use.
+== data
+Heap:
+  # curr
+  0/imm32
+  # limit
+  0/imm32
+
 == code
 #   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
 
+# Let's start initializing the default allocation descriptor.
+
+Entry:
+    # initialize heap
+    # . Heap = new-segment(64KB)
+    # . . push args
+    68/push  Heap/imm32
+    68/push  0x10000/imm32/64KB
+    # . . call
+    e8/call  new-segment/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
+
+    e8/call  run-tests/disp32  # 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'.
+$array-equal-main:end:
+    # syscall(exit, Num-test-failures)
+    8b/copy                         0/mod/indirect  5/rm32/.disp32            .             .           3/r32/ebx   Num-test-failures/disp32          # copy *Num-test-failures to ebx
+    b8/copy-to-eax  1/imm32/exit
+    cd/syscall  0x80/imm8
+
 # Claim the next 'n' bytes of memory starting at ad->curr and update ad->curr.
 # Abort if there isn't enough memory in 'ad'.
 allocate:  # ad : (address allocation-descriptor), n : int -> address-or-null/eax