From b9ad7e0e55277c8018ba01def07f06282861bd8b Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Fri, 15 Nov 2024 23:37:08 +0100 Subject: [PATCH] forgot to mention floats --- docs/source/technical.rst | 14 +++++++++----- examples/test.p8 | 8 +++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/docs/source/technical.rst b/docs/source/technical.rst index 173b1c77e..271155b99 100644 --- a/docs/source/technical.rst +++ b/docs/source/technical.rst @@ -144,11 +144,12 @@ Regular subroutines - The arguments passed in a subroutine call are evaluated by the caller, and then put into those variables by the caller. The order of evaluation of subroutine call arguments *is unspecified* and should not be relied upon. - The subroutine is invoked. -- The return value is not put into a variable, but the subroutine passes it back to the caller via cpu register(s): - Byte values will be put in ``A`` . - Boolean values will be put in ``A`` too, as 0 or 1. - Word values will be put in ``A`` + ``Y`` register pair (lsb in A, msb in Y). - Float values will be put in the ``FAC1`` float 'register'. +- The return value is not put into a variable, but the subroutine passes it back to the caller via register(s): + + - A byte value will be put in ``A`` . + - A boolean value will be put in ``A`` too, as 0 or 1. + - A word value will be put in ``A`` + ``Y`` register pair (lsb in A, msb in Y). + - A float value will be put in the ``FAC1`` float 'register'. **Builtin functions can be different:** some builtin functions are special and won't exactly follow these rules. @@ -167,6 +168,9 @@ Two byte parameters: ``sub foo(ubyte bar, ubyte baz) { ... }`` Single word parameter: ``sub foo(uword bar) { ... }`` gets bar in the register pair A + Y (lsb in A, msb in Y), *subroutine* stores it into parameter variable +Floating point parameter: ``sub foo(float bar) { ... }`` + value for bar gets copied into the parameter variable *by the caller* + Other: ``sub foo(ubyte bar, ubyte baz, ubyte zoo) { ... }`` register values indeterminate, values all get stored in the parameter variables *by the caller* diff --git a/examples/test.p8 b/examples/test.p8 index ffef922f9..52164484c 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -2,8 +2,9 @@ main { sub start() { + float zz thing() - thang() + zz = thang(1.22) bool status cx16.r0L, status = extfunction(42, 11223, 999, 1.22, true) cx16.r0L, status = function(42, 11223, 999, 1.22, true) @@ -18,8 +19,9 @@ main { return true } - sub thang() -> float { - + sub thang(float arg) -> float { + arg++ + return arg } sub func1(ubyte arg) {