Re: NOT

Anton Ertl <anton-8NJIiSa5LzB3ZGU3T6kWFyEcasqEdqbRs2V0tQ3P5b8@public.gmane.org>
Newsgroups gmane.comp.lang.forth.gforth
Message-ID <[email protected]>
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
<http://www.complang.tuwien.ac.at/anton/euroforth/ef10/papers/ertl.pdf>
for details.

- anton
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.