[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gforth] NOT

From: Anton Ertl
Subject: Re: [gforth] NOT
Date: Sat, 16 Feb 2019 08:47:37 +0100
User-agent: NeoMutt/20170113 (1.7.2)

On Fri, Feb 15, 2019 at 04:21:47PM -0500, J. David Boyd wrote:
> Any idea how to implement the word NOT in gforth to create a 1s complement?
> I can find an assembler definition in SwiftForth, but no other luck anywhere.

: not invert ;

Or better use INVERT directly.

> I also don't seem to be able to find the assembler registers used by gforth.
> Either I'm blind, or it is not documented anywhere.

They are not documented anywhere, because the register allocation is
done by the C compiler that compiles the Gforth engine.  You can write
words in assembly that are not dependent on the specific engine by using

'abi-code'       "name" - colon-sys         gforth       "abi-code"
   Start a native code definition that is called using the platform's
ABI conventions corresponding to the C-prototype:
     Cell *function(Cell *sp, Float **fpp);
   The FP stack pointer is passed in by providing a reference to a
memory location containing the FP stack pointer and is passed out by
storing the changed FP stack pointer there (if necessary).

and, similarly, ;ABI-CODE.

You have to look up the calling convention (ABI) of the platform you
are using.  E.g., on the System V AMD64 ABI (used by, e.g., Linux and
MacOS X on AMD64), the sp argument is passed in rdi, the fpp argument
in rsi, and the changed stack pointer is returned in rax.

Note that ABI-CODE words have some overhead that CODE words do not
have.  See
for details.

- anton

reply via email to

[Prev in Thread] Current Thread [Next in Thread]