In article <
[email protected]>,
Krzysztof Jeszke <
[email protected]> wrote:
Hello everyone.
i'm currently trying to build an executable using GForth's built in assembler, but apparently it, and most of the assemblers that are written in forth only
assemble the code to be used as a word. Is it possible to somehow redirect the assemblers or something similar to write the machine code to an allocated
chunk of memory instead of the forth vocabulary?
First of all, the choice of assembler matters. The following is about
Intel 386.
If you want to tie Forth to assembler, your are better off with a Forth
written in assembler, where the correspondance is clear.
If you compile in ciforth :
lina -c hello.frt
you generate an executable `hello',
with an intermediate step that identifies
the part of memory that is written to the executable.
It is not hard to extend lina.asm with the assembler code
that result in hello.asm, provided that hello is small.
There is a reverse engineering assembler written in ciforth:
https://github.com/albertvanderhorst/ciasdis
These can generate an assembler file from an executable, and then
regenerate the executable. That second part you could port to gforth.
Examples are part of the tests.
A prestigious example is to generate version 4.0.5 of lina 32 itself,
analysing the code and generating labels found in the executable.
Expect to write a Forth code plug in to extract these labels.
Likewise a 64 bit lina is reverse engineered and reassembled, but this
is not transferred to github yet.
Part of the Makefile:
lina530.asm : ciasdis lina530crawl.cul testcmp/lina530
ciasdis -d testcmp/lina530 lina530crawl.cul >$@
ciasdis -a $@ lina530
$(DIFF_BIN) lina530
$(DIFF_TXT) $@
So the lina530 in testcmp is disassembled (-d) generating lina530.asm.
Then this source is assembler (-a) to a lina530.
The files are identical to the ones in testcmp, or the test fails.
Groetjes Albert
--
"in our communism country Viet Nam, people are forced to be
alive and in the western country like US, people are free to
die from Covid 19 lol" duc ha
albert@spe&ar&c.xs4all.nl &=n
http://home.hccnet.nl/a.w.m.van.der.horst
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)