From 7a4c6295f372541de2c5d6e5e91335ac7324bd6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Wed, 17 Aug 2022 03:02:04 +0300 Subject: [PATCH] Add stack manipulation subroutines --- calculator.asm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/calculator.asm b/calculator.asm index 6e0c31e..3f38680 100644 --- a/calculator.asm +++ b/calculator.asm @@ -78,6 +78,26 @@ stEmit: store ffff, r1 ret +; ------------------------------------------------------------------ +; Stack manipulation +; ------------------------------------------------------------------ + +; a - a a +stDup: + cleq r0, r0, peekWord + breq r0, r0, pushWord + +; a b -- a b a +stOver: + cleq r0, r0, popWord + cleq r0, r0, tmpStoreWord01 + cleq r0, r0, peekWord + cleq r0, r0, tmp2StoreWord01 + cleq r0, r0, tmpLoadWord01 + cleq r0, r0, pushWord + cleq r0, r0, tmp2LoadWord01 + breq r0, r0, pushWord + ; ================================================================== ; Low-level functions ; ==================================================================