System Software

SIC

  • 假想電腦

  • 有 XE 版本,為進階版

  • SIC/XE 可相容 SIC 的指令 (upward compatible)

Memory

  • 1 byte = 8 bit
  • 1 word = 3 bytes
  • Total
    215
    bytes
  • byte addressable

Registers

  • Mnemonic Number Special use
    A 0 Accumulator
    X 1 Index register
    L 2 Linkage register
    PC 8 Program counter
    SW 9 Status word

Data Formats

  • Integers : 24 bit
  • Characters : 8 bit ASCII codes
  • No floating-point

Instruction Formats

      8        1               15
+-----------+-----+--------------------------+
|   opcode  |  X  |         address          |
+-----------+-----+--------------------------+

Address mode

  • Mode Indication TA
    Direct x=0 = address
    Indexed x=1 = address+ (X)

SIC/XE

Memory

  • can address 1MB (
    220
    bytes)

Registers

  • Mnemonic Number Special use
    A 0 Accumulator
    X 1 Index register
    L 2 Linkage register
    PC 8 Program counter
    SW 9 Status word
    B 3 Base
    S 4 General working
    T 5 General working
    F 6 Floating-point

Data Formats

  • 有小數可以用了!
	  1        11                  36
	+---+----------------+---------------------+
	| s |      exp       |        frac         |
	+---+----------------+---------------------+
  • Value =
    (1)s0.f2(exp1024)

Instruction Formats

  • Format 1 : 1 byte

    • ​​      	  8
      ​​  +--------------+
      ​​  |    opcode    |
      ​​  +--------------+
      
  • Format 2 : 2 bytes

    • ​​          8           4         4
      ​​  +--------------+---------+---------+
      ​​  |    opcode    |   r1    |   r2    |
      ​​  +--------------+---------+---------+
      
  • Format 3 : 3 bytes

    • ​​       6     1 1 1 1 1 1       12
      ​​  +-------------------------------------+
      ​​  |    op   |n|i|x|b|p|e| disp/address  |
      ​​  +-------------------------------------+
      ​​  e = 0
      
  • Format 4 : 4 bytes

    • ​​       6     1 1 1 1 1 1         20
      ​​  +------------------------------------------+
      ​​  |    op   |n|i|x|b|p|e|      address       |
      ​​  +------------------------------------------+
      ​​  e = 1
      
  • 定址模式

    • PC relative : b=0, p=1
      • 會先檢查這個
    • Base relative : b=1, p=0
      • 再檢查這個
    • Direct : b=0, p=0
      • (+)op c
      • (+)op m
      • c是常數
    • Indexed : n=1, i=1, x=1
      • (+)op m, X
    • Immediate : n=0, i=1, x=0
      • (+)op #c
        • c是常數
      • (+)op #m
        • 要檢查 PC-relative 和 Base-relative
    • Indirect : n=1, i=0, x=0
      • (+)op @m
      • (+)op @c
    • Simple : n=0, i=0 or n=1,i=1
      • n=0, i=0 : 相容 SIC 用的 , op m
      • (+)op m
      • (+)op c

Assembler

重要功能

  • location counter
  • Write object program
  • 2 pass

object program

  • Header record :
    • H
      • Program name
      • Starting address
      • Length of object program in bytes
  • Text record
    • T
      • Starting address
      • Length in bytes
      • Object code
  • End record
    • E
      • Address of first executable instruction

Algorithm and data structures

  • Two-pass assembler

  • OPTAB

  • SYMTAB

    • Label Addr
      FIRST 1000
      CLOOP 1003
      ENDFIL 1015
  • LOCCTR

  • Intermedia file

    • 在pass 1 與 pass 2 之間的溝通檔案
    • 放有 address, error indicators 等資料

Psudeo code

見課本

SIC/XE Assembler

  • 更多定址模式 & instruction formats

  • Program Relocation

    • START 0
  • SIC/XE 指令對應

  • Immediate op #c
    Indirect op @m
    PC-relative/Base-relative op m
    Extended format +op m
    Indexed op m,x
  • Register-to-register instructions

    • Keep the register name and value in SYMTAB
  • Large memory

    • multiprogamming and program reallocation

Address translation

  • PC-relative : -2048 ~ 2047

  • Base-relative : 0 ~ 4095

  • Assembler 會先試 PC-relative, 失敗才試 Base-relative

  • 如果還不夠用就用 format 4,有20 bit

  • ex 1 :

    • ​​  ;10	1000
      ​​  FIRST	STL RETADR		;17202D
      ​​  ;RETADR = 30h; STL = 14h
      
    • disp = RETADR - (PC) = 30 - 3 = 2Dh

    • opcode = 00010100b

    • nixbpe = 110010

    • ​​      opcode    nixbpe     disp
      ​​  +---------------------------------+
      ​​  | 000101   |110010|   (02D)h      |
      ​​  +---------------------------------+
      ​​  (17202D)h
      
  • ex 2 :

    • ​​  ;40	0017
      ​​  J	CLOOP		;3F2FEC
      ​​  ;CLOOP = 6; J = 3Ch
      
    • disp = 6 - 1A = -14 = -(0000 0001 0100)b = (1111 1110 1100)b = (FEC)b

    • opcode = 00111100

    • nixbpe = 110010

    • ​​      opcode    nixbpe     disp
      ​​  +---------------------------------+
      ​​  | 001111   |110010|   (FEC)h      |
      ​​  +---------------------------------+
      ​​  (3F2FEC)h
      
  • ex 3 :

    • ​​  ;160	104E
      ​​  STCH	BUFFER,X		;57C003
      ​​  ;(B) = 0033; opcode = 54; BUFFER = 0036
      
    • disp = 0036 - 104E(PC) = -1018 <- 超過了

    • disp = 0036 - 0033(B) = 3

    • __不用處理 X __

    • nixbpe = 111100

    • ​​      opcode    nixbpe     disp
      ​​  +---------------------------------+
      ​​  | 010101   |111100|   (003)h      |
      ​​  +---------------------------------+
      ​​  (57C003)h
      
  • ex 4 :

    • ​​  ;12 0003
      ​​  LDA	#LENGTH		;69202D
      ​​  ;opcode = 68; LENGTH = 0033
      
    • 有變數操作,要用relative

    • disp = 0033 - 0006 = 02D

    • nixbpe = 010010

    • ​​      opcode    nixbpe     disp
      ​​  +---------------------------------+
      ​​  | 011010   |010010|   (02D)h      |
      ​​  +---------------------------------+
      ​​  (69202D)h
      
  • ex 5 :

    • ​​  ;70 002A
      ​​  J @RETADR		;3E2003
      ​​  ;opcode = 3C
      

Program relocation

  • HOW TO :
    • COPY START 0
    • In SIC/XE :
      • Format 1 2 3
        • Not affect
      • Format 4
        • 要改
    • In SIC :
      • Format 3 with address field
        • 要改
  • 要怎麼改?
    • Modification record
      • M
      • Starting loc of addr to be modified
      • length to be modified, in half-bytes
      • e.g. :
        • M 000007 05
        • 真實況下沒有空白
        • 雖然打7,但實際上是7.5

Symbol-defining

Label v.s. Symbols

  • label : 連結 addr
  • symbols : 似 C 裡的 #define ,可以定義很多東西

Usage

  • symbol EQU value

How it works?

  1. pass 1
    • 遇到直接先寫入 SYMTAB
  2. pass 2
    • 把值讀回來

Program blocks

把變數宣告和程式碼本身分開,讓 assembler 自行排列,可避免存取過遠的位置及增加讀取效率

  • 預設為 default block

  • USE CBLCK

  • 每個 block 都有自己的 LOCCTR

  • Pass 1 :

    • 針對每個 block 計算相對於其開頭的 address
  • Pass2 :

    • 計算 object code

    • 對於 abslute symbol (非相對),沒有 block number

      • e.g :
      • 107 1000 MAXLEN EQU BUFEND-BUFFER
    • ex :

      • ​​​  ;20 0006 0
        ​​​  LDA	LENGTH	;032060
        ​​​  ;~~~~
        ​​​  ;100 0003 1
        ​​​  LENGTH RESB 4096
        
      • LENGTH = (block 1 start)+0003 = 0066+0003=0069

      • LOCCTR = (block 0 start)+0009 = 0009

      • PC-relative : disp = 0069 - 0009 = 0060

  • Object code 沒有被動到

  • USE 的時候 Text record 會開新的一行(個)

Control section

  • 相當於 Java 裡的 import 及 JavaScripts 的 export
  • external reference === import
  • CSECT tag 可供全域跳躍
  • 一定要用 format 4
  • Define record :
    • D
    • Name1 relative address1
    • Name2 relative address2
  • Refer record
    • R
    • Name1 Name2
  • Modification record
    • M
    • start address
    • length to modify
    • +/-
    • external symbol