\( \newcommand\D{\mathrm{d}} \newcommand\E{\mathrm{e}} \newcommand\I{\mathrm{i}} \newcommand\bigOh{\mathcal{O}} \newcommand{\cat}[1]{\mathbf{#1}} \newcommand\curl{\vec{\nabla}\times} \newcommand{\CC}{\mathbb{C}} \newcommand{\NN}{\mathbb{N}} \newcommand{\QQ}{\mathbb{Q}} \newcommand{\RR}{\mathbb{R}} \newcommand{\ZZ}{\mathbb{Z}} \)
UP | HOME

I-Machine Instruction Set

Table of Contents

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

  1. car,
  2. cdr,
  3. set-to-car,
  4. set-to-cdr,
  5. set-to-cdr-push-car,
  6. rplaca,
  7. rplacd,
  8. rgetf,
  9. member,
  10. 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-instance
  • arg2 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-instance
  • arg2 can be anything

2.8. rgetf

Interruptible instruction

  • (rgetf arg1 arg2)
  • arg1 is any data type
  • arg2 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
    1. eq
    2. eq-no-pop
    3. eql
    4. eql-no-pop
    5. equal-number
    6. equal-number-no-pop
    7. greaterp
    8. greaterp-no-pop
    9. lessp
    10. lessp-no-pop
    11. logtest
    12. logtest-no-pop
    13. type-member-n (four instructions)
    14. type-member-n-no-pop (four instructions)
  • Unary predicates
    1. endp
    2. plusp
    3. minusp
    4. zerop

3.1. eq, eq-no-pop

Operates on top two elements of the stack.

  • arg1 any data type
  • arg2 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 type
  • arg2 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

  1. add
  2. sub
  3. unary-minus
  4. increment
  5. decrement
  6. multiply
  7. quotient
  8. ceiling
  9. floor
  10. truncate
  11. round
  12. remainder
  13. rational-quotient
  14. max
  15. min
  16. logand
  17. logior (bit-by-bit inclusive or)
  18. logxor
  19. ash (this is cl:ash)
  20. rot
  21. lsh
  22. %32-bit-plus
  23. %32-bit-difference
  24. %multiply-double
  25. %add-bignum-step
  26. %sub-bignum-step
  27. %divide-bignum-step
  28. %lshc-bignum-step
  29. %multiply-bignum-step

5. Data-Movement Instructions

  1. push
  2. pop
  3. movem
  4. push-n-nils
  5. push-address
  6. set-sp-to-address
  7. set-sp-to-address-save-tos
  8. push-address-sp-relative
  9. stack-bit
  10. stack-blt-address

6. Field-Extraction Instructions

  1. ldb
  2. dpb
  3. char-ldb
  4. char-dpb
  5. %p-ldb
  6. %p-dpb
  7. %p-tag-ldb
  8. %p-tag-dpb

7. Array Operations

  1. aref-1
  2. aset-1
  3. aloc-1
  4. setup-1d-array
  5. setup-force-ld-array
  6. fast-aref-l
  7. fast-aset-l
  8. array-leader
  9. store-array-leader
  10. aloc-leader

8. Branch and Loop Instructions

  1. branch
  2. branch-true
  3. branch-false
  4. branch-true-no-pop
  5. branch-false-no-pop
  6. branch·true-else-no-pop
  7. branch-false-else-no-pop
  8. branch-true-and-no-pop
  9. branch-false-and-no-pop
  10. branch-true-and-extra-pop
  11. branch-false-and-extra-pop (Pop twice if branch, pop once if no branch)
  12. branch-true-else-extra-pop (Pop once if branch, pop twice if no branch)
  13. branch-false-else-extra-pop
  14. branch-true·extra-pop
  15. branch-false-extra-pop
  16. branch-true-and-no-pop-else-no-pop-extra-pop is the same thing as branch-true
  17. branch-false-and-no-pop-else-no-pop-extra-pop is the same thing as branch-false
  18. loop-decrement-tos
  19. loop-increment-tos-less-than

9. Block Instructions

  1. %block·n-read (four instructions)
  2. %block-n-read-shift (four instructions)
  3. %block-n-read-alu (four instructions)
  4. %block-n-read-test (four instructions)
  5. %block-n-write (four instructions)

10. Function-Calling Instructions

  1. dtp-call-compiled-even
  2. dtp-call-compiled-odd
  3. dtp-call-indirect
  4. dtp-call-generic
  5. dtp-call-compiled-even-prefetch
  6. dtp-call-compiled-odd-prefetch
  7. dtp-call-indirect-prefetch
  8. dtp-call-generic-prefetch
  9. start-call
  10. finish-call-n
  11. finish-call-apply-n
  12. finish-call-tos
  13. finish-call-apply-tos
  14. entry-rest-accepted
  15. entry-rest-not-accepted
  16. locate-locals
  17. return-single
  18. return-multiple
  19. return-kludge
  20. take-values

11. Binding Instructions

  1. bind-locative-to-value
  2. bind-locative
  3. unbind-n
  4. %restore-binding-stack

12. Catch Instructions

  1. catch-open
  2. catch-close

13. Lexical Variable Accessors

  1. push-lexical-var-n (eight instructions)
  2. pop-lexical-var-n (eight instructions)
  3. movem-Iexical-var-n (eight instructions)

14. Instance Variable Accessors

  1. push-instance-variable
  2. pop-instance-variable
  3. movem-instance-variable
  4. push-address-instance-variable
  5. push-instance-variable-ordered
  6. pop-instance-variable-ordered
  7. movem-instance-variable-ordered
  8. push-address-instance-variable-ordered
  9. %instance-ref
  10. %instance-set
  11. %instance-loc

15. Sub primitive Instructions

  1. %ephemeralp
  2. %unsigned-lessp
  3. %unsigned-lessp-no-pop
  4. %allocate-list-block
  5. %allocate-structure-block
  6. %pointer-plus
  7. %pointer-difference
  8. %pointer-increment
  9. %read-internal-register
  10. %write-internal-register
  11. no-op
  12. %coprocessor-read
  13. %coprocessor-write
  14. %memory-read
  15. %memory-read-address
  16. %memory-write
  17. %tag
  18. %set-tag
  19. store-conditional
  20. %p-store-contents
  21. %set-cdr-code-n (two instructions)
  22. %merge-cdr-no-pop
  23. %generic-dispatch
  24. %message-dispatch
  25. %jump
  26. %check-preempt-request
  27. %halt

15.1. %allocate-list-block

Arguments:

  • arg1 any type
  • arg2 is a dtp-fixnum

Using three internal registers, named list-cache-area, list-cache-length, and list-cache-address, this instruction:

  1. Takes an instruction exception (post trap) unless (eq arg1 list-cache-area).
  2. Computes list-cache-length minus arg2. Takes an instruction exception if the result is negative. Stores the result into list-cache-length unless an exception is taken.
  3. Pops the arguments and pushes the list-cache-address. Writes the list-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.
  4. Stores (list-cache-address + arg2) into list-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

Last Updated 2023-09-19 Tue 09:44.