Giter Club home page Giter Club logo

nasmjf's Introduction

nasmjf - a NASM port of JONESFORTH

This is a fully-functioning Forth interpreter faithfully ported from the original by Richard W.M. Jones:

You can see the full original source in the jonesforth/ directory in this repo.

$ nasmjf
JONESFORTH VERSION 1
20643 CELLS REMAINING
OK ." Hello World"
Hello World

This repo is a port from the original GNU Assembler (GAS) implementation to the Netwide Assembler (NASM). The biggest difference between the two assemblers is AT&T-style GAS syntax vs. Intel-style NASM syntax. But I have made a couple changes. The biggest one is that nasmjf loads the jonesforth.f source file (containing the second half of the interpreter written in Forth) upon startup.

See "Loads Jones’s FORTH source on start" below.

Current status

The assembly portion of this interpreter port is pretty much "done". I’m currently testing the rest of the built-in words and then I’ll shift to cleaning up and improving the comments and structure of the assembly source.

Why does this exist?

Check out the log text files. They’re my rambling learning-in-public and thinking "out loud" way of describing what I’m up to. The latest log will probably give an idea of what I’m currently doing or what I’ve most recently completed.

I also wrote an article about my delightful process with this project: http://ratfactor.com/assembly-nights

I also have a placeholder for future notes and rambling thoughts about the project here: http://ratfactor.com/nasmjf

Loads Jones’s FORTH source on start

The implementation of JONESFORTH is in two parts: an assembly language "bootstrap" and additional essential word definitions written in FORTH.

This NASM contains a hard-coded path to the jonesforth.f FORTH source file and reads it automatically when the interpreter starts. This is to make starting and debugging the system easier and more convenient.

If you wish to disable or simply examine this change, search for lines with comments containing the string LOADJF. You can comment out most of these lines. A few will need to remain. Figuring out which is "left as an exercise for the reader", as they say.

Compiling and running

Assemble and link with:

# assemble! (-g enables debugging symbols)
nasm -f elf32 -g -o nasmjf.o nasmjf.asm

# link
ld nasmjf.o -o nasmjf ; rm nasmjf.o

Run by calling the executable you just compiled:

$ ./nasmjf
'A' EMIT
A

GNU Debugger

I’ve made heavy use of the GNU Debugger to fix mistakes, understand what my program is doing, and in these early stages, it’s nearly the only way to tell what’s happening in the program at all.

I’m assembling with DWARF2 debugging info. See the r script for params.

See gdb.script for current defaults I’m using.

Show stuff:

maint info sections     # memory sections
info addr word_buffer   # address of symbol (label/var/func)
info sym 0x804c608      # reverse of info addr, symbol at addr
info var buff           # list (with addr!) of symbol names w/ "buff"
info var                # list ALL symbols
info var var_           # list all symbols that start with "var_"

Print values (register, label, literal numbers (handy as base converter)

p 0x50                  # prints 80
p/x 80                  # prints 0x50
p/x (int)some_label     # show 4 bytes (32b) of data at some_label in hex
p/x &some_label         # ADDRESS of some_label

Print value at memory location

x/x &some_label         # show a byte of data at some_label in hex
x/s &some_label         # show a string at some_label
x/4x &some_label        # show four consecutive bytes

Set temporary break and jump to location (by label)

tbreak docol
jump docol

Create GDB commands

define foo
    p $arg0
    p $arg1
end

GNU Screen

See the file screenrc in this repo to see the current convenience setup. In short, I’ve got a GDB session and Vim session open in separate windows so I can quickly toggle between them. Anything outside of those two applications is best done in a new window to keep from accidentally closing one of the two main windows.

  • C-j C-j toggle between main windows

  • C-j c create a new window with a shell

  • C-j H start (or stop) logging window (not actually what I want)

  • C-j h save hardcopy of scrollback buffer (actually what I want)

  • C-j ? help (show other shortcuts)

I’m using the hardcopy feature to help me record running each milestone of progress in GDB sessions to test and document (and celebrate!) the work.

An alias called rc starts my two-windowe session like so:

alias jf='screen -c nasmjf/screenrc'

.vimrc

My whole setup on this machine is dedicated to this project. Here’s the entirety of my current .vimrc:

set tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab
colorscheme elflord
" my favorite buffer switing mappings
nnoremap <right> :bn<cr>
nnoremap <left> :bp<cr>
" my eeepc chugs when trying to apply highlighting to this large asm file
au BufRead jonesforth.S set syntax=text nowrap
au BufRead nasmjf.listing set nowrap
let mapleader = ","
" run my 'r' script for nasmjf.asm
nnoremap <leader>r :!r<cr>

PUBLIC DOMAIN

Because Richard Jones released his work as public domain, it’s only right that I should release my port also as public domain. So here’s the license:

I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.

In case this is not legally possible, I grant any entity the right to use this work for any purpose, without any conditions, unless such conditions are required by law.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.