Re: translation from x86 assember to machine code

rickh@capaccess.org (Rick Hohensee)
17 Jan 2002 00:33:30 -0500

          From comp.compilers

Related articles
translation from x86 assember to machine code donalies@adelphia.net (michelle) (2002-01-14)
Re: translation from x86 assember to machine code joachim_d@gmx.de (Joachim Durchholz) (2002-01-17)
Re: translation from x86 assember to machine code RLWatkins@CompuServe.Com (R. L. Watkins) (2002-01-17)
Re: translation from x86 assember to machine code hugo_rozas@terra.com.pe (Hugo Rozas M.) (2002-01-17)
Re: translation from x86 assember to machine code rickh@capaccess.org (2002-01-17)
Re: translation from x86 assember to machine code donalies@adelphia.net (michelle) (2002-01-18)
Re: translation from x86 assember to machine code setters@nospam.hotmail.com (Paul Setterfield) (2002-01-28)
| List of all articles for this month |

From: rickh@capaccess.org (Rick Hohensee)
Newsgroups: comp.compilers
Date: 17 Jan 2002 00:33:30 -0500
Organization: http://groups.google.com/
References: 02-01-055
Keywords: assembler
Posted-Date: 17 Jan 2002 00:33:30 EST

"michelle" <donalies@adelphia.net> wrote in message news:02-01-055...
> What I'M Really Looking For Is A Toy Compiler Or Assembler For X86 That'S


I just posted osimplay, which is an x86 assembler written entirely
in the GNU Bash 2 unix-style command interpreter "shell". That's
about as toy as you're gonna get for real machine code. Very
interactive, slow, soft, warm and fuzzy. Improves brain-machine
coordination. No sharp edges ( 386 and earlier only), nothing toxic
( no FPU), hypo-allergenic ( no 8008 legacy "ASCII" instructions)...
osimplay has all the 386 protected memory stuff, but that's
de-emphasized a bit. It's easy to program application code, for small
programs, for an assembler.


Internally, the x86 is pretty nasty to assemble. If you want to just
understand the concepts something like a 68000 might be better.
But alas, ubiquity being the factor that it is... .


GNU Bash has a very nice function listing feature, "type".
"surprises" is what I've renamed Intel's "STI" opcode to in osimplay.
Here's "type surprises" interactively, in my shell. In this example
osimplay has already been sourced into my shell's state...
..................................................................
:;type surprises
surprises is a function
surprises ()
{
        if test "$1" = "h"; then
                echo -e "\n\t\t\t\t\tIntel STI\n
Allow external hardware to interrupt the CPU. \"nosurprises\"
turns them off. \n\n";
        else
                herelist;
                ab 0xfb;
                opnote surprises $*;
        fi
}
...................................................................


"ab" is "assemble byte"; append a byte to $output and increment
$here. The echo -e is what you get in osimplay if you do
  surprises h . "herelist" is for the listing file.


"surprises" is a minimal example; one name, one possible opcode.
MOV on 386+ is not so simple. Can you say "gory nightmares"?


Other relatively simple, interactive, play-with-able assemblers
are the ones that many Forths include. Forth's stack-machine
oddness is in large part to enable that flexibility and
interactiveness. Forth itself is a machine-language monitor
for a virtual two-stack machine, usually at a fairly low performance
overhead versus straight machine code. Forths tend to come with
an assembler for the real host hardware also. osimplay is an
attempt to be as Forth-like as possible without the 2-stack
virtual machine.


osimplay is a lower-level HLA, Randy Hyde's High Level Assembler.
HLA requires Windows. I don't know if it's possible to use osimplay
under CygWin or similar. I use Linux. osimplay has some things
that aren't straight assembly, i.e. that do more than one instruction
at a whack. Those are always optional. They provide an abstraction
level somewhere between MIX and BCPL.


The classic educational assembler is probably MIX, the machine
Professor Donald Knuth created for his pivotal "The Art of Computer
Programming". The Professor feels that programmers must understand
computers at the level underlying algebraic parsers. I believe there
are emulators around for the MIX virtual machine. For other fun
machines see the "99 Bottles of Beer On the Wall" webpage. Like
INTERCAL, GNU "make", Babbage's machine...


So why did I rename MOV to "="? It's a shell script. Change it
back to MOV if you like, or change it to MOM, or DAD, or both,
or whatever has mnemonic value or is convenient to YOU. Actually,
I would have prefered the more Forth-like and less algebraic "!"
to "=", but "!" conflicts with the shell's arguments parser.


ftp://ftp.gwdg.de/pub/cLIeNUX/interim/osimplay.tgz


Rick Hohensee
rickh@capaccess.org
http://linux01.gwdg.de/~rhohen


# 13-byte PC floppy boot "sector" in osimplay, which is in GNU Bash 2
: > $listing ; : > $output # wipe the previous build
here=0 allocated=yes cell=2 # HELP! I'M AN 8086!
allot 0x7C00 # We'll dd $output so 0x7c00 is 0.
= $((512+80)) to A # BIOS INT 0x13 AH=2 + AL=sectors
= 1 to C # sector 1
zero D # head 0
= 0x7c00 to B # overlaying ourself.
submit 0x13 # BIOS left ES=0.
# loaded 2 tracks (PS/2-55 & 1997 Award work), are walking down into them.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.