From 9bc51a5249dd2e286eb1e15bb18004f061a8121f Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sun, 12 Aug 2018 22:46:49 -0700 Subject: 4514 - prefix jump targets with function name I'd been planning next to automatically namespace jump targets in different functions. But just a check for duplicate labels should suffice, and managing unique names isn't a huge burden. I'm wary of growing the translator too much. All this will eventually need to be self-hosted in SubX. --- subx/ex7.subx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subx/ex7.subx b/subx/ex7.subx index b386df82..86e018c8 100644 --- a/subx/ex7.subx +++ b/subx/ex7.subx @@ -38,7 +38,7 @@ factorial: b8/copy . . . . . . . 1/imm32 # copy 1 to EAX # if (n <= 1) jump exit 81 7/subop/compare 3/mod/direct 2/rm32/EDX . . . . . 1/imm32 # compare EDX with 1 - 7e/jump-if-<= . . . . . . $exit/disp8 # jump if <= to $exit + 7e/jump-if-<= . . . . . . $factorial:exit/disp8 # jump if <= to $factorial:exit # EBX: n-1 89/copy 3/mod/direct 3/rm32/EBX . . . 2/r32/EDX . . # copy EDX to EBX 81 5/subop/subtract 3/mod/direct 3/rm32/EBX . . . . . 1/imm32 # subtract 1 from EBX @@ -58,7 +58,7 @@ factorial: # return n * factorial(n-1) 0f af/multiply 3/mod/direct 2/rm32/EDX . . . 0/r32/EAX . . # multiply EDX (n) into EAX (factorial(n-1)) # TODO: check for overflow -$exit: +$factorial:exit: c3/return # vim:ft=subx:nowrap:so=0 -- cgit 1.4.1-2-gfad0