I-Machine Instruction Set
Table of Contents
- 1. Introduction
- 2. List-Function Operations
- 3. Predicate functions
- 4. Numeric Operations
- 5. Data-Movement Instructions
- 6. Field-Extraction Instructions
- 7. Array Operations
- 8. Branch and Loop Instructions
- 9. Block Instructions
- 10. Function-Calling Instructions
- 11. Binding Instructions
- 12. Catch Instructions
- 13. Lexical Variable Accessors
- 14. Instance Variable Accessors
- 15. Sub primitive Instructions
- 16. References
1. Introduction
There are 211 instructions in 14 categories:
- 10 list-function
- 24 predicate
- 29 numeric
- 10 data-movement
- 8 field-extraction
- 10 array-operation
- 19 branch-and-loop
- 20 block
- 12 function-calling
- 4 binding
- 2 catch
- 24 lexical-variable-accessing
- 11 instance-variable-accessing
- 28 subprimitive.
Also note there are about 2 or 3 dozen different types of an argument. (See, e.g., the manual of a lisp machine emulator).
2. List-Function Operations
car
,cdr
,set-to-car
,set-to-cdr
,set-to-cdr-push-car
,rplaca
,rplacd
,rgetf
,member
,assoc
2.1. car
Argument(s): 1,
(car <dtp-list>)
pushes the car onto the stack (a cons cell)(car <dtp-locative>)
(a locative pointer)(car <dtp-list-instance>)
(an object reference to a list instance) pushes the car of the list instance onto the stack,(car <dtp-nil>)
(primitive data type, nil) pushes nil onto the top of the stack
If the argument is a dtp-list, then this will push the car of arg
onto
the stack.
If the type is dtp-locative, this pushes the contents of the location
arg
references onto the stack.
If the type of arg is dtp-nil, this pushes nil
onto the stack.
2.2. cdr
(cdr <dtp-list>)
pushes the cdr of the arg onto the stack(cdr <dtp-locative>)
pushes the contents of the location arg references onto the stack(cdr nil)
pushes nil onto the stack
Post trap: Type of arg is dt-list-instance
Memory reference: cdr-read, then data-read
TOS Register effects: valid afer
2.3. set-to-car
Basically (set-to-car arg)
is the same as (set! arg (car arg))
.
(set-to-car <dtp-list>)
replaces the argument with the car of the argument(set-to-car <dtp-locative>)
replaces the contents of the memory cells at location with its car
2.4. set-to-cdr
Basically (set-to-cdr arg)
is the same as (set! arg (cdr arg))
(set-to-cdr <dtp-list>)
(set-to-cdr <dtp-locative>)
(set-to-cdr <dtp-list-instance>)
(set-to-cdr <dtp-nil>)
2.5. set-to-cdr-push-car
2.6. rplaca
(rplaca arg1 arg2)
replaces the car of arg1 with arg2, i.e., it's
(set! (car arg1) arg2)
.
arg1
must be a dtp-list, dtp-locative, or dtp-list-instancearg2
can be anything
2.7. rplacd
(rplacd arg1 arg2)
replaces the cdr of arg1 with arg2, i.e.,
(set! (cdr arg1) arg2)
.
arg1
must be a dtp-list, dtp-locative, or dtp-list-instancearg2
can be anything
2.8. rgetf
Interruptible instruction
(rgetf arg1 arg2)
arg1
is any data typearg2
is a dtp-list, dtp-nil, or dtp-list-instance
Searches arg2
2 elements at a time, succeeding if the first element of
the pair is EQL to arg1
, failing if there is no match.
Upon failure, both values returned are nil.
Upon success, the first value returned is the second element of the
matching pair, and the second value returned is the tail of arg2
whose
car
is that second element.
2.9. member
- arg1 is any data type
- arg2 is a dtp-list, dtp-nil, dtp-list-instance
Returns nil
or a tail of arg2
whose car
is eql
to arg1
.
This implements the cl:member
function.
2.10. assoc
- arg1 is any data type
- arg2 is a dtp-list, dtp-nil, dtp-list-instance
Returns nil
or an element of arg2
whose car
is eql
to
arg1
. This implements the cl:assoc
function.
3. Predicate functions
- Binary predicates
- eq
- eq-no-pop
- eql
- eql-no-pop
- equal-number
- equal-number-no-pop
- greaterp
- greaterp-no-pop
- lessp
- lessp-no-pop
- logtest
- logtest-no-pop
- type-member-n (four instructions)
- type-member-n-no-pop (four instructions)
- Unary predicates
- endp
- plusp
- minusp
- zerop
3.1. eq, eq-no-pop
Operates on top two elements of the stack.
arg1
any data typearg2
any data type
Pushes t
on the stack if the operands reference the same Lisp object;
otherwise, pushes nil
on the stack.
The no-pop version leaves the first argument arg1
on the stack. (So,
presumably, arg2
is popped off the stack?)
3.2. eql, eql-no-pop
Arguments:
arg1
any data typearg2
any data type
Returns t
if the two arguments are eq
or if they are numbers of the
same type with the same value; otherwise returns nil
.
Note: for dtp-single-float
, +0
and -0
are not eql
. Also (eql 0 0.0)
is false.
3.3. equal-number, equal-number-no-pop
Tests if top two elements of the stack are equals as numeric
quantities. Note that (equal-number 0 0.0)
— which is also written
as (= 0 0.0)
— is true, in contrast to ~(eql 0 0.0) which is false.
The no-pop version leaves the first argument on the stack.
4. Numeric Operations
- add
- sub
- unary-minus
- increment
- decrement
- multiply
- quotient
- ceiling
- floor
- truncate
- round
- remainder
- rational-quotient
- max
- min
- logand
- logior (bit-by-bit inclusive or)
- logxor
- ash (this is
cl:ash
) - rot
- lsh
%32-bit-plus
%32-bit-difference
%multiply-double
%add-bignum-step
%sub-bignum-step
%divide-bignum-step
%lshc-bignum-step
%multiply-bignum-step
5. Data-Movement Instructions
- push
- pop
- movem
- push-n-nils
- push-address
- set-sp-to-address
- set-sp-to-address-save-tos
- push-address-sp-relative
- stack-bit
- stack-blt-address
6. Field-Extraction Instructions
- ldb
- dpb
- char-ldb
- char-dpb
- %p-ldb
- %p-dpb
- %p-tag-ldb
- %p-tag-dpb
7. Array Operations
- aref-1
- aset-1
- aloc-1
- setup-1d-array
- setup-force-ld-array
- fast-aref-l
- fast-aset-l
- array-leader
- store-array-leader
- aloc-leader
8. Branch and Loop Instructions
- branch
- branch-true
- branch-false
- branch-true-no-pop
- branch-false-no-pop
- branch·true-else-no-pop
- branch-false-else-no-pop
- branch-true-and-no-pop
- branch-false-and-no-pop
- branch-true-and-extra-pop
- branch-false-and-extra-pop (Pop twice if branch, pop once if no branch)
- branch-true-else-extra-pop (Pop once if branch, pop twice if no branch)
- branch-false-else-extra-pop
- branch-true·extra-pop
- branch-false-extra-pop
branch-true-and-no-pop-else-no-pop-extra-pop
is the same thing asbranch-true
branch-false-and-no-pop-else-no-pop-extra-pop
is the same thing asbranch-false
- loop-decrement-tos
- loop-increment-tos-less-than
9. Block Instructions
- %block·n-read (four instructions)
- %block-n-read-shift (four instructions)
- %block-n-read-alu (four instructions)
- %block-n-read-test (four instructions)
- %block-n-write (four instructions)
10. Function-Calling Instructions
- dtp-call-compiled-even
- dtp-call-compiled-odd
- dtp-call-indirect
- dtp-call-generic
- dtp-call-compiled-even-prefetch
- dtp-call-compiled-odd-prefetch
- dtp-call-indirect-prefetch
- dtp-call-generic-prefetch
- start-call
- finish-call-n
- finish-call-apply-n
- finish-call-tos
- finish-call-apply-tos
- entry-rest-accepted
- entry-rest-not-accepted
- locate-locals
- return-single
- return-multiple
- return-kludge
- take-values
11. Binding Instructions
- bind-locative-to-value
- bind-locative
- unbind-n
%restore-binding-stack
12. Catch Instructions
- catch-open
- catch-close
13. Lexical Variable Accessors
- push-lexical-var-n (eight instructions)
- pop-lexical-var-n (eight instructions)
- movem-Iexical-var-n (eight instructions)
14. Instance Variable Accessors
- push-instance-variable
- pop-instance-variable
- movem-instance-variable
- push-address-instance-variable
- push-instance-variable-ordered
- pop-instance-variable-ordered
- movem-instance-variable-ordered
- push-address-instance-variable-ordered
%instance-ref
%instance-set
%instance-loc
15. Sub primitive Instructions
- %ephemeralp
- %unsigned-lessp
- %unsigned-lessp-no-pop
- %allocate-list-block
- %allocate-structure-block
- %pointer-plus
- %pointer-difference
- %pointer-increment
- %read-internal-register
- %write-internal-register
- no-op
- %coprocessor-read
- %coprocessor-write
- %memory-read
- %memory-read-address
- %memory-write
- %tag
- %set-tag
- store-conditional
- %p-store-contents
- %set-cdr-code-n (two instructions)
- %merge-cdr-no-pop
- %generic-dispatch
- %message-dispatch
- %jump
- %check-preempt-request
- %halt
15.1. %allocate-list-block
Arguments:
arg1
any typearg2
is adtp-fixnum
Using three internal registers, named list-cache-area
,
list-cache-length
, and
list-cache-address
, this instruction:
- Takes an instruction exception (post trap) unless
(eq arg1 list-cache-area)
. - Computes
list-cache-length
minusarg2
. Takes an instruction exception if the result is negative. Stores the result intolist-cache-length
unless an exception is taken. - Pops the arguments and pushes the
list-cache-address
. Writes thelist-cache-address
into BAR-1 (Block-Address-Register-1). Sets the control-register trap-mode field to(max 1 current-trap-mode)
so that there can be no interrupts until storage is initialized. - Stores (
list-cache-address
+arg2
) intolist-cache-address
(arg2
must be latched since the third step may overwrite its original location in the stack).
This is useful for the implementation of the cons
function.
(defun cons (car cdr) (%set-cdr-code-normal car) (%set-cdr-code-nil cdr) (%make-pointer dtp-list (prog1 (%allocate-list-block default-cons-area 2) (%block-1-write car) (%block-1-write cdr))))
Note that %make-pointer
is %set-tag
with the arguments in reverse order.
16. References
- I-Machine Architecture Specification documents all opcodes in the instruction set.
- I-Machine instruction set descriptions PDF, omits some of the documentation.
- I-Machine Data types
- Assembly Code and Subprimitives