---
title: System programming 1
---
# System Programming
NTNU 系統程式
##### [Back to Note Overview](https://reurl.cc/XXeYaE)
##### [Back to System Programming](https://hackmd.io/@NTNUCSIE112/SP110-1)
{%hackmd @sophie8909/pink_theme %}
###### tags: `SystemProgramming` `110-1` `CSIE` `選修` `NTNU`
<!-- tag順序 [學校] [系 必選] or [學程 學程名(不含學程的 e.g. 大師創業)] [課程] [開課學期]-->
<!-- 網址名稱 SP110-1_[] -->
## Ch.01 Background
### 1.1 Introduction
- Definition
- 由支持計算機操作的各種程式組成
### 1.2 System Software and Machine Architecture
### 1.3 The Simplified Instructional Computer (SIC)
- Simplified Instructional Computer(SIC)
- Comes in two versions
- The Standard model
- An XE version(extra equipments, extra expensive)
- The two versions has been designed to be **upward compatible**
#### 1.3.1 SIC Machine Architecture
- Memory
- consists of 8-bits bytes
- word: 3 consecutive bytes(24 bits)
- total: **2^15^ bytes**
- Registers
- 5 registers
- 24 bits length (each)
| 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 are stored as **24-bit binary number**
- **2’s complement** representation for negative values
- Characters are stored using **8-bit ASCII codes**(at right most bits)
- **No floating-point** hardware on the standard version of SIC
- Instruction Formats
- Standard version of SIC
- 24 bits
| opcode | x | address |
| ------ | - | ------- |
| 8 | 1 | 15 |
The flag bit $x$ is used to indicate **indexed-addressing mode**
- Buses
- Data Bus: 24/8 bits
- Address Bus: 15 bits
- Addressing Modes
- There are two addressing modes available, indicated by x bit in the instruction
| Mode | Indication | Target Address calculation |
| ------- | ---------- | -------------------------- |
| Direct | x=0 | TA=address |
| Indexed | x=1 | TA=address=($X$) |
<font color=red>($X$)</font>: the contents if register $X$
#### 1.3.2 SIC/XE Machine Architecture
- Memory
- Maximum memory available on a SIC/XE system is 1 megabyte($2^{20}$bytes)
- Instruction format
- Format 1(1 bytes)
| op |
| --- |
| 8 |
- Ex.
| Mneminic | Format | Opcode | Effect |
| -------- | ------ | ------ | ---------------------------- |
| FIX | 1 | C4 | A <- (F)[convert to integer] |
- Format 2(2 bytes)
| op | r1 | r2 |
| --- | --- | --- |
| 8 | 4 | 4 |
:::warning
Format 1 & 2 are instructions that **do not** reference memory at all.
:::
- Format 3(3 bytes)
| op | n | i | x | b | p | e | disp |
| --- | --- | --- | --- | --- | --- | --- | ---- |
| 6 | 1 | 1 | 1 | 1 | 1 | 1 | 12 |
- Format 4(4 bytes)
| op | n | i | x | b | p | e | address |
| ------------------------- | ---------- | ------------------------------------ | --- | --- | --- | --- | ------- |
| 6 | 1 | 1 | 1 | 1 | 1 | 1 | 20 |
- Addressing mode for format 3
| Mode | Indication | Target address calculation | Notes |
| ------------------------ | ---------- | --------------------------------------------- | -------------------------------------- |
| Base relative | b=1, p=0 | TA=(B)+disp <br>($0\leq disp \leq 4095$) | |
| Program-counter relative | b=0, p=1 | TA=(PC)+disp <br>($-2048\leq disp \leq 2047$) | 指令跟指令的間隔通常小於$2^{12}$ |
- Registers
- Additional registers are provided by SIC/XE
| Mnemonic | Number | Special Use |
| -------- | ------ | ----------------------------------- |
| B | 3 | Base register |
| S | 4 | General working register |
| T | 5 | General working register |
| F | 6 | Floating point accumulator(48 bits) |
- 48-bit floating-point data type (他說不重要)
- Instruction Format
- 15 bits in SIC
- 20 bits in SIC/XE
<!-- class note text book p.10 -->
:::danger
**About n, i, x, b, p, e !**
:::
- Target address
> n, i: how to use the target address(TA)
| n | i | |
| --- | --- | --------------------------------------- |
| 1 | 1 | Direct(Simple) addressing |
| 1 | 0 | Indirect addressing (尋寶遊戲) |
| 0 | 1 | Immediate addressing (no memory access) |
| 0 | 0 | 相容 SIC |
- e
| e | Format |
| --- | -------- |
| 0 | format 3 |
| 1 | format 4 |
- About TA 計算
| Mode | Indication | Target address calculation | Notes |
| ----------------------------- | ---------- | ------------------------------------------------- | -------------------------------- |
| Base relative mode | b=1, p=0 | TA=(B)+disp+(X) <br>($0\leq disp \leq 4095$) | |
| Program-counter relative mode | b=0, p=1 | TA=(PC)+disp+(X) <br>($-2048\leq disp \leq 2047$) | 指令跟指令的間隔通常小於$2^{12}$ |
#### SIC Programming Examples
```SIC=
LDA ZERO
STA INDEX
```
x = a + b * c
y = x * a
```SIC=
LDA b
MUL c
ADD a
STA x
LDA x
MUL a
STA y
```
### 1 4 Traditional (CISC) Machines
### 1.5 RISC Machines
*[Mnemonic]: 助憶符
*[upward compatible]: 向上兼容