From 6be5a28bb90b391a5842a8ce3dfc7c154100ab68 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Sat, 12 Aug 2023 15:12:03 +0200 Subject: make a macro for pushing out thunks --- fibs.s | 67 ++++++++++++++---------------------------------------------------- 1 file changed, 14 insertions(+), 53 deletions(-) (limited to 'fibs.s') diff --git a/fibs.s b/fibs.s index c32f424..3d35544 100644 --- a/fibs.s +++ b/fibs.s @@ -9,26 +9,15 @@ # | lag1 | lag2 | -> cont .thunkcode fibs # next value - pushq 030(%rbp) - pushq 020(%rbp) - pushq $2 - pushq $plus - mov %rsp, %r11 + thunkto %r11, $plus, $2, 020(%rbp), 030(%rbp) # fib call with the next value - push %r11 - pushq 030(%rbp) - pushq $2 - pushq $fibs - mov %rsp, %r12 + thunkto %r12, $fibs, $2, 030(%rbp), %r11 - # cons list with lag1 - push %r12 - push 020(%rbp) - pushq $1 - pushq $LIST_code - mov %rsp, %r13 + # cons list with the lagged arg + thunkto %r13, $LIST_code, $1, 020(%rbp), %r12 + # TODO simplify # replace self with IND mov %r13, 010(%rbp) movq $IND_code, 0(%rbp) @@ -39,43 +28,15 @@ # || -> cont .thunkcode fibs0 - pushq $1 - pushq $INT_code - mov %rsp, %r12 - pushq $0 - pushq $INT_code - mov %rsp, %r11 - - push %r12 - push %r11 - pushq $2 - pushq $fibs - - enter %rsp + thunkto %r12, $INT_code, $1 + thunkto %r11, $INT_code, $0 + thunkto %rbp, $fibs, $2, %r11, %r12 + enter_rbp .thunkcode main - pushq $0 - pushq $fibs0 - mov %rsp, %r12 - - pushq $20 - pushq $INT_code - mov %rsp, %r11 - - push %r12 - push %r11 - pushq $2 - pushq $list_int_index - mov %rsp, %r11 - - push %r11 - pushq $1 - pushq $print - mov %rsp, %r11 - - push %rsi - pushq $1 - pushq $main_exit - - mov %rsp, %rsi + thunkto %r12, $fibs0, $0 + thunkto %r11, $INT_code, $20 + thunkto %r11, $list_int_index, $2, %r11, %r12 + thunkto %r11, $print, $1, %r11 + thunkto %rsi, $main_exit, $1, %rsi enter %r11 -- cgit v1.2.3