Operating Systems

Ahmad Yoosofan

University of Kashan

Introduction

Course Review

  • Main Memory
    • Absolute Address
    • Relative Address
    • paging
    • Virtual Memory
    • segmentation
    • segmentation and paging combinations
    • Invert table

Making an imaginary computer step by step

Finding more about how hardware and software works

  1. It needs to go back to principles
  2. It provides clear path for what we already have
  3. Understanding that why computers works this way nowadays

The Abacus and Counting Board

Mechanical Calculator

Pascaline

Jacquard Machines

Mechanical Computer

Analog Computer

Analog vs Digital

$$\begin{align}i(t) = C \frac{dv(t)}{dt}\end{align}$$

Electro Mechanical

Digital Computer

Stored Program

Analog Chipsets for AI Applications

General Types of Computers

Imaginary Computer (YIC-10)

Different memory for code and data

Real Motherboard

Motherboard Circut

The Second Computer (YIC-10)

Uniform memory (John von Neumann)

Assembly Code and Machine Code

ADD A,B

A = A + B

; 0101011  00010101 0101010

OPcode    DATA_1    DATA_2
ADD          A               B
R1 = R2 + R3
ADD R1, R2, R3

; 010101001 0001 0010 0011

OP Code     R1    R2    R3

010101001000100100011

Instruction Set(I)

AND: Logical AND memory with AC
ADD: Arithmetic ADD memory with AC
LDA: Load from memory to AC
STA: Store AC to memory
BUN: Branch unconditional
ISZ: Increment and skip if zero
CLA: Clear AC
CLE: Clear E
CMA: Complement AC
CME: Complement E
CIR: Circulate right (AC and E)
CIL: Circulate left (AC and E)
INC:    Increment AC
SPA:    Skip if positive AC
SNA:    Skip if negative AC
SZA:    Skip if zero AC
SZE:    Skip if zero E
HLT:    Halt
OUT:    Output a character from AC
SKO:    Skip if output flag
NOP:    No operation

Instruction Set Bianary(I)

AND:    00001
ADD:    00010
LDA:    00011
STA:    00100
BUN:    00101
ISZ:    00110
CLA:    00111
CLE:    01000
CMA:    01001
CME:    01010
CIR:    01011
CIL:    01100
INC:    01101
SPA:    01110
SNA:    01111
SZA:    10000
SZE:    10001
HLT:    10010
OUT:    10011
SKO:    10100
NOP:    10101

hex pad connect to microcontroller

https://www.circuitstoday.com/interfacing-hex-keypad-to-8051

https://circuitdigest.com/microcontroller-projects/keypad-interfacing-with-avr-atmega32

Example

Other assembly

00101 00000  1010
00110 00000  1100
00111 00000  1110
01000

00000

اگر حداکثر ۳۲ دستور داشته باشیم پس پنج بیت برای دستورها نیاز داریم برای سادگی فرض می‌کنیم که طول همهٔ دستورها یکسان است یعنی هم دو بایت را می‌گیرند فرض کنید دستورها پنج بیت نیاز دارند پس ۱۱ بیت برای آدرس

حداکثر حافظهٔ این کامپیوتر چقدر می‌تواند باشد. اگر بخواهیم بایتی آدرس دهی کنیم

۲^۱۱ = ۲kB

B = Byte

اگر آدرس‌دهی را دو بایتی در نظر بگیریم

۴kB (word = 2 byte)

Main Type of Processors

Output

LED

seven segment

Output Problem

lda a
add b
sta c
out
hlt
a, 5
b, 2
c, 0
..........
..........

LB1: out
    sko
    bun LB1

...........
...........

Simple LED

circuitbasics

Seven segment display

circuitbasics askingthelot

youtu.be element14

Imaginary Computer

YIC 30

Seven segment

circuitbasics

Issues of YIC 30

Hardware insead of Software

Hardware vs Software

4 Digit 7-Segment Displays

circuitbasics

Connecting 4 Digit 7-Segment Displays

Arduino Print 4 to 7-segment

#include "SevSeg.h"
SevSeg sevseg;

void setup(){
  byte numDigits = 1;
  byte digitPins[] = {};
  byte segmentPins[] =
    {6, 5, 2, 3, 4, 7, 8, 9};
  bool resistorsOnSegments = true;

  byte hardwareConfig = COMMON_CATHODE;
  sevseg.begin(hardwareConfig,
    numDigits, digitPins, segmentPins,
    resistorsOnSegments
  );
  sevseg.setBrightness(90);
}

void loop(){
  sevseg.setNumber(4);
  sevseg.refreshDisplay();
}

Segment Pin

Arduino Pin

A

6

B

5

C

2

D

3

E

4

F

7

G

8

DP

9

circuitbasics

The common segment displays

YIC 40 - BSA

  1. LED output code
  2. 7 segment code
  3. Printer
  4. output selector
  5. Adding porecedures
  6. Device Drivers
  7. Adding more devices
  8. No error checking
  9. Send data
  10. API (protocol)

Epson WideCarriage Line Printer

https://en.wikipedia.org/wiki/Dot_matrix_printing

Dot matrix example text

https://en.wikipedia.org/wiki/Dot_matrix_printing

Dot-matrix display

1969 Braille display

split flap display(I)

http://arduinomania.com/tag/split%20flap%20display

Split-flap display(II)

Enlarged inner workings of a split-flap clock

Airport Board with Split-Flip Display

Flip-Dot-Display

5x7 LED module

Printer Function

Process along Printer Function

Jump to Printer Procedure

Return from Printer Procedure

Display and Printer Procedure

Adding procedurs to memory

User Process (P)

               

0

800

2048

    P    

       

LED Procedure

0

648

1024

2048

    P    

     

LED

7 segment

0

456

1024

1048

1096

2048

    P    

           

LED

7

printer

       

0

456

1024

1048

1096

1256

2048

Users (programmers) should know where these precedures are

YIC50 - Array of Addresses

P

           

array

LED

7

printer

       

0

456

1000

1024

1048

1096

1256

2048

Array

1024

1048

1096

1256

0

1

2

3

4

YIC60 - Input Devices

       ORG 0
START, BSA READ1
       STA BYTE1
       LDA BYTE1
       BSZ OUTCH
       HLT

READ1, HEX 0
RDCNT, SKI
       BUN RDCNT
       INP
       BUN (READ1)

OUTCH, HEX 0
       OUT
       BUN (OUTCH)

BYTE1, DEC     0
       END

Tape

Simple Input Output Code - YIC60

1         ORG     0
2 START,  BSA     INPUT
3         STA     NUM1
4 
5         BSA     INPUT
6         STA     NUM2
7 
8         LDA     NUM1
9         ADD     NUM2
10         STA     RESULT
11 
12         BSA     OUTPUT
13 
14         HLT
15 INPUT,  HEX     0
16 POLL,   SKI
17         BUN     POLL
18         INP
19         BUN     (INPUT)
20 
21 OUTPUT, HEX     0
22 OUT_P,  SKO
23         BUN     OUT_P
24         OUT
25         BUN     (OUTPUT)
26 
27 // Data Section
28 NUM1,   DEC     0
29 NUM2,   DEC     0
30 RESULT, DEC     0
31 
32         END

YIC60 - Array of Addresses

P

           

array

LED

7

printer

       

0

456

1000

1024

1048

1096

1256

2048

Array

1024

1048

1096

1256

0

1

2

3

4

YIC60 code with array(I)

1 START   BSA     (PVT_INPUT)
2         STA     NUM1
3         BSA     (PVT_INPUT)
4         STA     NUM2
5         LDA     NUM1
6         ADD     NUM2
7         STA     RESULT
8         BSA     (PVT_OUTPUT)
9         HLT
10 NUM1,   DEC     0
11 NUM2,   DEC     0
12 RESULT, DEC     0
13 
14         ORG     150
15 PVT_INPUT,  HEX 200
16 PVT_OUTPUT, HEX 220
17 
18         ORG     200
19 INPUT,  HEX     0
20 IN_POLL,SKI
21         BUN     IN_POLL
22         INP
23         BUN     (INPUT)
19         ORG     220
20 OUTPUT, HEX     0
21         STA     TEMP_OUT
22 
23 OUT_POLL,SKO
24         BUN     OUT_POLL
25         LDA     TEMP_OUT
26         OUT
27         BSA     (PVT_DELAY)
28         BUN     (OUTPUT)
29 
30         ORG     240
31 DELAY,  HEX     0
32         LDA     DELAY_COUNT
33         STA     DELAY_CTR
34 
35 DELAY_LOOP,
36         LDA     DELAY_CTR

YIC60 code with array(II)

1 DELAY,  HEX     0
2         LDA     DELAY_COUNT
3         STA     DELAY_CTR
4 
5 DELAY_LOOP,
6         LDA     DELAY_CTR
7         SZA
8         BUN     CONTINUE_DELAY
9         BUN     (DELAY)
10 
11 CONTINUE_DELAY,
12         DEC
13         STA     DELAY_CTR
14         BUN     DELAY_LOOP
15 
16         ORG     300
17 TEMP_OUT,   DEC     0
18 DELAY_COUNT,DEC     10
21 DELAY_CTR,  DEC     0
22 PVT_DELAY,  HEX     52
23         END

YIC70 - Adding Loader

Loader

P

           

array

LED

7

printer

       

0

100

556

1000

1024

1048

1096

1256

2048

Array

1024

1048

1096

1256

0

1

2

3

4

1 START,  BSA     READ_COUNT
2         STA     BYTE_COUNT
3         BSA     INIT_LOAD 
4         BSA     LOAD_LOOP 
5         BSA     EXECUTE   
6         BUN     0        
7         HLT               
8 
9 READ_COUNT, HEX 0
10 RD_CNT, SKI               
11         BUN     RD_CNT
12         INP               
13         BUN     READ_COUNT I 
14 
15 INIT_LOAD, HEX 0
16         LDA     ZERO
17         STA     LOAD_PTR   
18         STA     CURRENT_IDX
19         BUN     INIT_LOAD I
20 
21 LOAD_LOOP, HEX 0
22         LDA     CURRENT_IDX
21         SUB     BYTE_COUNT
22         SPA              
23         BUN     LOAD_BYTE
24         BUN     LOAD_LOOP I
25 
26 LOAD_BYTE,
27         BSA     READ_BYTE
28         STA     TEMP_BYTE
29         
30         LDA     LOAD_PTR
31         STA     STORE_PTR
32         LDA     TEMP_BYTE
33         STA     STORE_PTR I 
34         
35         LDA     LOAD_PTR
36         INC
37         STA     LOAD_PTR
1         STA     LOAD_PTR
2         LDA     CURRENT_IDX
3         INC
4         STA     CURRENT_IDX
5         BUN     LOAD_LOOP  
6 
7 READ_BYTE, HEX 0
8 RD_BYT, SKI             
9         BUN     RD_BYT
10         INP             
11         BUN     READ_BYTE I 
12 
13         ORG     128
14 EXECUTE, HEX 0
15         
16         LDA     ZERO
17         STA     RESULT
18         BUN     EXECUTE I
19         
20         ORG     64     
21 ZERO,       DEC     0
21 BYTE_COUNT, DEC     0  
22 LOAD_PTR,   HEX     128
23 CURRENT_IDX,DEC     0  
24 TEMP_BYTE,  DEC     0  
25 STORE_PTR,  HEX     0  
26 RESULT,     DEC     0  
27 
28         END

YIC75 Relative Address

address binding, absolute and relocate loader

YIC80 - Interrupt

YIC90 - Memory and CPU Protection

  1. System Call ?
  2. Change registers by the running process

Software Interrupt

mov ah, 0x0e    ; function number = 0Eh : Display Character
mov al, '!'     ; AL = code of character to display
int 0x10        ; call INT 10h, BIOS video service

System Call

C System Call

Simple Parameters

Pentium 4 (ESCR)

CPU protection

Timer interrupt

Cpu Scheduler

YIC100 - Adding Keyboard & Disk

YIC105 - Function call

Stack From end

YIC110 - Multiprogramming

Simple computer simulator

Simple Computer Simulator Instruction Set

When a controller rapidly turns on LEDs in one row at a time

https://www.nutsvolts.com/magazine/article/create-an-led-sign-controller

GET THE DOTS, FORM A LETTER using ROM

https://www.nutsvolts.com/magazine/article/create-an-led-sign-controller

Showing Character D

https://www.deviceplus.com/arduino/display-characters-with-leds-how-to-use-a-matrix-led/

Showing Character D (real refresh)

https://www.deviceplus.com/arduino/display-characters-with-leds-how-to-use-a-matrix-led/

Card reader instead of Hex pad input

Display

IBM 3270 Display Terminal

BIOS

Boot sequence

Context Switch

END

1