Commit 36b8ce59 authored by Frode Vatvedt Fjeld's avatar Frode Vatvedt Fjeld

*** empty log message ***

parent 0460e61c
......@@ -10,7 +10,7 @@
## Author: Frode Vatvedt Fjeld <frodef@acm.org>
## Created at: Sat Jan 29 16:48:42 2005
##
## $Id:$
## $Id: README,v 1.1 2005/01/29 16:33:31 ffjeld Exp $
##
######################################################################
......@@ -22,7 +22,7 @@ for 16 and 32-bit x86 code. It is primarily intended as a backend for
the Movitz compiler. The following documents the most interesting API
operators for this package.
A few terms requires explanation. A "proglist" is a representation of
A few terms requires explanation. A "program" is a representation of
an assembly program that is reasonably convenient to work with for
humans. This is a list, whose elements are either a symbol that
represents a label, or a list that represents an instruction. The
......@@ -31,10 +31,70 @@ which means "move EAX to the memory location pointed to by EBX offset
by 1" (more on this syntax below). However, instructions are also
represented internally ia-x86 by instances of the various subclasses
of the "instruction" standard-class, and lists of such objects are
also someplaces referred to as proglists.
referred to as "proglists".
Assembly
The function read-proglist reads a program into proglist form, which
is typically the first step in producing machine code. This function
(and its helper functions, in read.lisp) defines the human-readable
syntax for assembly programs. This is an example program (or rather, a
lisp function that produces an assembly program):
(defun mkasm16-bios-print ()
"Print something to the terminal. [es:si] points to the text"
`((:movzxb (:si) :cx)
(:incw :si)
(:movb #xe :ah)
(:movw 7 :bx)
print-loop
(:lodsb)
(:int #x10)
(:loop 'print-loop)
(:ret)))
I personally tend to use keywords for instruction names, although the
instructions are recognized by name rather than identity, so any
package will do. Labels, however, are recognized by identity. Label
references are on the form (quote <label>), so that the loop
instruction above will transfer control to the print-loop label two
instructions before it. Indirect memory references are writen by
placing the pointer inside parens, such as in the first movzxb above.
If the first element of an instructon is a list (rather than an
instruction name), this is interpreted as a list of instruction
prefixes (such as REP, LOCK, etc.).
This is a more-or-less exact description of the syntax:
program ::= (<sexpr>*)
sexpr ::= ( <expr> ) | <label> | (% <inline-data> %) | (:include . <program>)
expr ::= <instro> | ( { <prefix> } ) <instro>
instro ::= <instruction> { <operand> }
operand ::= <concrete> | <abstract>
concrete ::= <immediate> | <register> | <indirect>
immediate ::= <number>
register ::= eax | ecx | ...
indirect ::= ( iexpr )
iexpr ::= <address>
| (quote <label>)
| <segment> <address>
| pc+ <offset>
| pc <address>
| { (quote <label>) } <offset> <scaled-register> <register>
scaled-register ::= <register> | ( <register> <scale> )
scale ::= 1 | 2 | 4 | 8
address ::= <number>
offset ::= <signed-number>
abstract ::= (quote <absexpr>)
absexpr ::= <label> | <number> | append-prg
append-prg ::= program
prefix ::= <segment-override> | (:size <size>)
The function proglist-encode takes a proglist and produces
machine-code in the form of e.g. a vector of 8-bit bytes.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment