Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #60552

Re: Portable Assembler

From Alex <alex@rivadpm.com>
Newsgroups comp.lang.forth
Subject Re: Portable Assembler
Date 2017-06-10 11:34 +0100
Organization A noiseless patient Spider
Message-ID <ohghoj$jkk$1@dont-email.me> (permalink)
References (2 earlier) <ohesqt$4qp$1@dont-email.me> <ohf1h9$l9e$1@dont-email.me> <ohf6bi$6pp$1@dont-email.me> <1c433b5c-f714-4b8e-83dd-1332c98c5140@googlegroups.com> <ohfi44$3i9$1@dont-email.me>

Show all headers | View raw


On 6/10/2017 02:34, Cecil Bayona wrote:
> On 6/9/2017 5:23 PM, foxaudioresearch@gmail.com wrote:
>> But Cecil has rediscovered the truth about assemblers in Forth.
>> They are not too difficult especially if you do not  try to get fancy.
>>
> 
> RPN assemblers are pretty simple in Forth but if one wants Infix 
> mnemonics its a little harder but not bad using Forth to create it. I 
> like the Infix mnemonics used by the VFX Forth by MPE but it requires 
> more work to do.
> 

There's a BSD licensed version of a postfix 32 and 64 bit Intel 
assembler as part of my WF32 project here; 
https://github.com/alextangent/wf32/tree/master/src/asm, documented at 
https://github.com/alextangent/wf32/blob/master/src/asm/readme.txt

I'm currently modifying the way its packaged to simplify porting between 
Forths, but the essence will be the same; there is an engine of about 
400 lines of code (lots of comments ups that to just under 1000) and 
then instruction tables at approx 1.<a small bit> lines per opcode 
(again, lots of comments push the figure higher). The assembler 
currently takes up 57KB of code and data space once loaded.

The engine can generate most (no VEX currently and no 16 bit 
contemplated) instructions from supplied tables for 32 bit and 64 bit 
modes.

The opcode tables support basic instructions, floats and (a few) SSE 
instructions. Support macros for specific Forths (like NEXT and labels) 
are provided in a separate file to aid porting.

The disassembler is a work in progress, but disassembles the basic 
instruction set OK. No floats or SSE/VEX stuff yet.

The syntax is Intel, with one modification; instead of [ ] to indicate 
memory operands, { } are used. So Intel [EAX][EBX] becomes { EAX EBX }.
Here's an example (the disassembler produces code that can be 
assembled). There's no clash with { } locals syntax as the assembler 
runs while interpreting.

code c@  ( a1 -- c1 )    \ fetch the character c1 from address a1
       movzx   eax byte { eax }
       next; inline

see c@ code c@ ( ? -- ? )
\ c@ is defined in src/kernel/gkernel32.fs at line 274
\ ' optc@ compiled
\ code=$401284 len=3 type=129
( $0 )    movzx   eax byte { eax }                  \ 0FB600
( $3 )    ret                                       \ C3 ( end ) ok

code ?dup       ( n -- n [n] )  \ duplicate top of data stack if non-zero
     1 -1 in/out
       test    eax eax
       je      short @@1
       mov     { -cell ebp } eax
       sub     ebp cell
@@1:  next; inline

see ?dup
code ?dup ( 1 -- ? )
\ ?dup is defined in src/kernel/gkernel32.fs at line 162
\ inlined
\ code=$401183 len=10 type=129
( $0 )    test    eax eax                           \ 85C0
( $2 )    je      short ' ?dup $A +                 \ 7406
( $4 )    mov     dword { $-4 ebp } eax             \ 8945FC
( $7 )    sub     ebp $4                            \ 83ED04
( $A )    ret                                       \ C3 ( end ) ok

-- 
Alex

Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Portable Assembler rickman <gnuarm@gmail.com> - 2017-06-09 14:35 -0400
  Portable Assembler Mark Wills <markwills1970@gmail.com> - 2017-06-09 11:47 -0700
    Re: Portable Assembler rickman <gnuarm@gmail.com> - 2017-06-09 15:30 -0400
      Re: Portable Assembler Cecil Bayona <cbayona@cbayona.com> - 2017-06-09 15:51 -0500
        Re: Portable Assembler rickman <gnuarm@gmail.com> - 2017-06-09 18:13 -0400
          Re: Portable Assembler foxaudioresearch@gmail.com - 2017-06-09 15:23 -0700
            Re: Portable Assembler Cecil Bayona <cbayona@cbayona.com> - 2017-06-09 20:34 -0500
              Re: Portable Assembler albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-06-10 08:36 +0200
                Re: Portable Assembler Cecil Bayona <cbayona@cbayona.com> - 2017-06-10 10:31 -0500
                Re: Portable Assembler Mark Wills <markwills1970@gmail.com> - 2017-06-11 09:07 -0700
                Re: Portable Assembler rickman <gnuarm@gmail.com> - 2017-06-11 12:36 -0400
                Re: Portable Assembler Cecil Bayona <cbayona@cbayona.com> - 2017-06-11 11:40 -0500
                Re: Portable Assembler Mark Wills <markwills1970@gmail.com> - 2017-06-12 05:30 -0700
                Re: Portable Assembler Mark Wills <markwills1970@gmail.com> - 2017-06-21 02:49 -0700
                Re: Portable Assembler foxaudioresearch@gmail.com - 2017-06-21 06:24 -0700
                Re: Portable Assembler foxaudioresearch@gmail.com - 2017-06-20 17:42 -0700
                Re: Portable Assembler albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-06-16 15:02 +0200
                Re: Portable Assembler Alex <alex@rivadpm.com> - 2017-06-16 15:09 +0100
                Re: Portable Assembler Cecil Bayona <cbayona@cbayona.com> - 2017-06-16 11:24 -0500
                Re: Portable Assembler Alex <alex@rivadpm.com> - 2017-06-16 18:04 +0100
                Re: Portable Assembler Alex <alex@rivadpm.com> - 2017-06-16 18:23 +0100
              Re: Portable Assembler Alex <alex@rivadpm.com> - 2017-06-10 11:34 +0100
                Re: Portable Assembler Cecil Bayona <cbayona@cbayona.com> - 2017-06-10 10:57 -0500
              Re: Portable Assembler stephen@mpeforth.com (Stephen Pelc) - 2017-06-10 16:47 +0000
                Re: Portable Assembler Cecil Bayona <cbayona@cbayona.com> - 2017-06-10 12:57 -0500
        Re: Portable Assembler David Schultz <abuse@127.0.0.1> - 2017-06-09 19:23 -0500
          Re: Portable Assembler Cecil Bayona <cbayona@cbayona.com> - 2017-06-09 20:21 -0500
            Re: Portable Assembler hughaguilar96@gmail.com - 2017-06-09 18:38 -0700
  Re: Portable Assembler Paul Rubin <no.email@nospam.invalid> - 2017-06-10 00:28 -0700
    Re: Portable Assembler rickman <gnuarm@gmail.com> - 2017-06-11 01:15 -0400

csiph-web