aboutsummaryrefslogtreecommitdiff
path: root/exit_123.s
diff options
context:
space:
mode:
authorMirek Kratochvil <exa.exa@gmail.com>2023-08-06 00:25:53 +0200
committerMirek Kratochvil <exa.exa@gmail.com>2023-08-06 00:25:53 +0200
commit74cad993376dc269e8389fbf150be9ecc36890c7 (patch)
tree32a2dbb382836ee0f1853fe5e63036d044fea77d /exit_123.s
parent46d84e91ebe48ade19bd3f5e18360bf853b53968 (diff)
downloaduskel-74cad993376dc269e8389fbf150be9ecc36890c7.tar.gz
uskel-74cad993376dc269e8389fbf150be9ecc36890c7.tar.bz2
fibs work
Diffstat (limited to 'exit_123.s')
-rw-r--r--exit_123.s48
1 files changed, 7 insertions, 41 deletions
diff --git a/exit_123.s b/exit_123.s
index 9fe9264..ed96ad1 100644
--- a/exit_123.s
+++ b/exit_123.s
@@ -1,6 +1,10 @@
+.include "include/uskel.s"
+
+.include "include/data.s"
+
# || -> cont
-.func main
+.thunkcode main
# push a new integer
pushq $100
pushq $INT_code
@@ -27,44 +31,6 @@
mov %rsp, %rsi
enter %r13
-# exitcode -> | cont (unused, should be 0) |
-.func main_exit
- mov 0x8(%rsi), %rdi # result to syscall exitcode
- mov $0x3c, %rax # syscall 60
- syscall # exit %rdi
-
-# | arg1 | arg2 | -> cont
-.func plus
- # push a thunk for finishing the plus
- push %rsi # cont
- push %rbp # ret (self)
- mov 0x18(%rbp), %rax
- push %rax # arg2
- pushq $3
- pushq $plus_step1
-
- mov %rsp, %rsi # continue to the new thunk
- enter 0x10(%rbp) # evaluate arg1
-
-# arg1 -> | arg2 | ret | cont |
-.func plus_step1
- # this is guaranteed to be entered only once (it's a cont), so we can rewrite the thunk in place
- mov 0x10(%rbp), %rax
- movq $plus_fini, 0x00(%rbp)
- mov %rsi, 0x10(%rbp)
-
- mov %rbp, %rsi # continue on the rewritten thunk
- enter %rax # evaluate arg1
-
-# arg2 -> | arg1 | ret | cont |
-.func plus_fini
- mov 0x8(%rsi), %rax # arg 2
- mov 0x10(%rbp), %rsi # location of arg1
- add 0x8(%rsi), %rax # arg 1
-
- mov 0x18(%rbp), %rsi # save result to the original plus thunk
- mov %rax, 0x08(%rsi)
- movq $INT_code, 0x00(%rsi)
-
- enter 0x20(%rbp) # eval cont, returning %rsi
+.include "include/main_exit.s"
+.include "include/intops.s"