---
# System prepended metadata

title: Lecture Computer Systems_Part 01
tags: [Computer Systems, Lecture HCMUS]

---

# :book: Contents Of The 2023 Final Exam Review

* **:writing_hand: ==Thông tin nội dung đề thi==**
    :::spoiler
    :::info

    - **Đề đóng** (_không sử dụng Tài Liệu_, chỉ được dùng **máy tính điện tử bỏ túi**).

    - **Thời gian:** *60 phút*

    - **Bố cục đề thi**
        + ***Phần trắc nghiệm***: *40 điểm* (= 20 câu * 2 điểm/câu), mỗi câu có 4 mục `A`,`B`,`C`,`D` và phải chọn mục **KHÔNG CÙNG TÍNH ĐÚNG SAI** với 3 mục còn lại $\to$ 40% số điểm.
        
        + ***Phần tự luận trả lời nhanh***: *30 điểm* (= 10 câu * 3 điểm/câu), đại đa số câu chỉ cần trình bày khoảng 03 dòng - không cần viết nhiều $\to$ 30% số điểm.

        + ***Phần tự luận thông thường***: *30 điểm* (= 2 câu* 15 điểm/câu), câu số 01 hỏi về mạch số, câu số 02 về lập trình Hợp ngữ (assembly language) $\to$ 30% số điểm.
    :::

* **:100: ==Nội dung Ôn thi Cuối Kỳ Computer Systems 2023==**

    :::spoiler
    :::success
    | Chapter | Content                    | Tasks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                               Status                                                |
    |:-------:|:-------------------------- |:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |:---------------------------------------------------------------------------------------------------:|
    |   01    | ==CS Overview==            | <ul><li>Definition and Basic Concepts</li><li>Etymology</li><li>Generations of computers</li><li>Types of computers</li><li>Hardware</li><li>Software</li><li>Chip manufacturing process</li><li>Moore Law</li></ul>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |:+1: <input type="checkbox" enable/>|
    |   02    | ==Data Representation==    | <ul><li>Information, Data and Representation</li><li>Numeral System<ul><li>Definition</li><li>Representing Number in Written</li><li>Converting the numeral system : Decimal, Binary, Hexadecimal</li></ul></li><li>Representing Numeral Units</li><li>Representing Binary Integers<ul><li>Representing Unsigned Integers</li><li>Big / Little Endian byte order</li><li>Representing Signed Integers<ul><li>Offset Binary (Excess-K)</li><li>Sign-Magntitude</li><li>One's Complement</li><li>Two's Complement</li></ul></li></ul><li>Calculatate based on Integers<ul><li>**Logic State:** AND, OR, XOR, NOT, Shift,...</li><li>**Numeral State:** Sum, Substract, Mutiply, Division, Number Overflow,...</li></ul></li></li><li>Representing Binary Real Numbers<ul><li>Representing Fixed - Point Numbers</li><li>Representing Floating - Point Numbers<ul><li>IEEE Standards for floating-point representation<ul><li>Single Precision (Excess_127)</li><li>Double Precision (Excess_1023)</li></ul></li><li>Converting base between binary floating-point numbers and decimal floating-point numbers.</li></ul></li></ul></li><li>Representing Text</li><li>Representing Image</li><li>Representing Audio</li><li>Representing Video</li></ul>                                                                                                                                                                                        | :+1: <input type="checkbox" enable/>|
    |   03    | ==Digital Circuit Design== | <ul><li>Boolean Algebra</li><li>Logic Gates</li><li>Combinational Logic Circuits</li><li>Sequential Logic Circuits</li><li>Designing Cuircuits from Truth Table</li></ul>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   | :+1: <input type="checkbox" enable/>|
    |   04    | ==Processor==              | <ul><li>How programs are translated into the machine</li><li>How hardware executes a programs</li><li>How CPU process an instruction</li><li>Measuring exception time</li><li>Uniprocessor :vs: Multiprocessor</li></ul>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |:+1: <input type="checkbox" enable/>|
    |   05    | ==Assembly Basics==        | <ul><li>What is Assembly Language ?</li><li>Advantages of Assemly Language</li><li>Basic Features of PC Hardware<ul><li>Data Representation Basics</li><li>Registers in IA32</li><li>Registers in all ISA</li></ul></li><li>ASM Program<ul><li>Instruction and Directive<li>Program Statement Structure</li><li>Opcodes & Operands</li><li>Types of ASM Languages<ul><li>CISC ASM</li><li>RISC ASM</li><li>DSP ASM</li><li>VLIW ASM</li></ul></li></ul></li><li>Modular Programming</li></ul>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |:+1: <input type="checkbox" enable/>|
    |   06    | ==ASM Programming==        | <ul><li>x86<ul><li>Instruction & Directive</li><li>The most basic x86 instructions<ul><li>Instruction Arguments</li><li>Move Instructions</li><li>Basic Arithmetical Instructions</li><li>Basic Logical Instructions</li><li>Compare Instruction</li><li>Unconditional Jump Instruction</li><li>Conditional Jump Instruction</li></ul><li>Declare Initialized Data</li><li>Arrays</li><li>Segment Directives</li><li>Memory Models</li><li>Some forms of ASM</li><li>Standard I/O</li></ul></li><li>MIPS<ul><li>MIPS(RISC) Design Principles</li><li>MIPS Organization</li><li>MIPS R3000 Instruction Set Architecture (ISA)</li><li>MIPS Adressing Models</li><li>MIPS Register Convention</li><li>A MIPS Sample Program</li><li>Supporting Procedures</li><li>Procedure Call Convention</li><li>MIPS 32 Context Frames</li><li>Calling Procedure: Spilling Registers</li><li>MIPS Arithmetic Instructions<ul><li>Machine Language - Add Instruction<ul><li>MIPS Immediate Instructions</li><li>How About Larger Constants ?</li><li>MIPS Mempry Access Instructions</li></ul><li>Machine Learning - Load Instruction<ul><li>Byte Address</li><li>Loading & Storing Bytes</li></ul></li>MIPS Control Flow Instructions</li><li>Specifying Branch Destinations</li><li>Other Control Flow Instructions</li><li>Branching Far Away</li><li>Instructions for Accessing Procedures</li><li>MIPS ISA - First Look</li></ul></li></ul></li></ul> |:+1: <input type="checkbox" enable/>|

    :::

---

# :bookmark_tabs: Review Lecture ==Computer Systems== 2023

## Chapter :one: : Computer Science Overview

### I. Definitions & basic concepts

* **Computer:** is a **machine** or **device** $\to$ performs **processes / calculations / operations** based on instructions provided by a **program**.
* The differences between **machine** and **device** are:
    * Machines: are **objects** made of many often **complex parts**, used to perform **precise work** or a series of **specialized tasks**. (> devices)
    * Devices: are **auxiliary parts**, used to **support** the operation of the **"machine"**, currently following the trend of developing **"devices"** that is increasingly compact, versatile and can be linked with other devices. (< machines)
* Functions: Computers are designed to execute applications and provide solutions by combining integrated **hardware** and **software** components. They are used as control systems for a wide range if industrial and consumer devices.
* The differences between **Computer** and **Computer System** are:
    * Computer: is any **device / machine** that processes information based on **program** processing. (Eg: SIM CARD, air conditioner remote control , ...) $\to$ be **highly specialized** for a specific purpose. 
        * Warning: Computer is only a machine / device so it cannot perform fully the task or if it can work normally, it cannot provide all applications for the users to use.
    * Computer + System: often is the system of many computers to perform general functions, as known as a **"complete"** computer (**general** computer system). A "complete" computer including :
        * Hardware: (là những vật tồn tại dưới dạng vật chất hữu hình)
            * Processing (or CPU = ALU + CU): main processor
            * Memory / Storage:
            * I/O devices (necessary peripheral equipment)
                * Chú ý: nếu đề bài hỏi là hardware gồm bao nhiêu thành phần thì trả lời là 3 thành phần (Processing (CPU) / Memory (Storage) / I/O devices) nhưng khi đề hỏi thêm với điều kiện có ALU hay CU thì gồm 4 thành phần (ALU / CU / Memory (Storage) / I/O devices).
                * Chú ý: GPU (đồ họa) = ALU + CU (thường được tích hợp).
        * Software: (là những hiện tượng, sự việc tồn tại dưới dạng phi vật chất, vô hình, ...) $\to$ computer programs (software) are designed specially for each task.
            * Data representation: mentioned in Chapter 02
            * Program: is a set of step-by-step instructions that tells or directs the computer what to do. It sequences the tasks a user wants to be done and produces the results or output needed.
            * Operating system & Apps: In Computer Architecture, we should not need to mention them $\to$ soul of computer.
        * Humanware (peopleware / liveware): is necessary for enhancing **user experience (UX)** by making improvements in the **system's user interface (UI)**. Humanware is the combination of hardware and software elements that make human interactions with a device as good as possible.
* Software and Hardware make up an actual computer.
* Often, developing humanware begins by defining who computer's potential users are what they are interested in and what they need before designing the infrastructure.
* Today, the IoT allow connecting computer devices to the Internet and to the other connected devices. Many computer can work together to share information, operation as design.
    * Chú ý: Các thiết bị IoT đều là các thiết bị kết nối từ xa, thông thường sử dụng mạng không dây (WLAN: wifi / 4G, 5G, ...)
    * Chú ý: Big Endian $\to$ Smartphone || Little Endian $\to$ Laptop, Computer,... 
* Computers have greatly affected our daily lives - helping us complete an extremely wide range of tasks by **software programs**.
* A **programmer** is the person who designs a program, converts problem solutions into instructions for the computer.
* Computer programs are created with programming languages.
* A **programming language** is a formal language, comprises a set of instructions that produce various kinds of output, used to implement **algorithms** to perform specific tasks.

### II. Generators of Computers:
* The development of electronic computers can be divided into 5 generations (until 2019) depending upon the technologies used:
    * $1^{st}$ gen: **vacuum tube** (~1940-1956)
    * $2^{nd}$ gen: **transistor** (~1956-1963)
    * $3^{rd}$ gen: **integrated circuits** (IC) (~1964-1971)
    * $4^{th}$ gen: **microprocessor** (~1971-2010)
    * $5^{th}$ gen: **artificial intelligence** (AI) (~2010 to present)
*  Future generations might be **quantum computers**. It has been figuring out algorithms at $10^8$ times the speed that a traditional computer can, and that could make a huge difference in the processing power at our disposal in the future. In addition to that, they are probably $10^{14}$ times faster than the fastest supercomputer.
*  There are several new computer types that can be used in the future: Quantum, Chemical, DNA, Optical, Spintronics-based, Wetware/Organic computer, etc

**$1^{st}$ gen computers:** used **vaccum tubes** technology
* Pros: Vaccum tubes $\to$ the only electric component available during those days $\to$ could calculate in ms $\to$ high speed to calculate.
* Cons:
    * the size: be very large
    * the weight: about 30 tones
    * the cost: be very expensive
    * the speed: be very slow
    * the data storage: be very less
    * the characteristics: be very faulty and not be versatile, used machine language only & limited programming capabilities
    * the consumption: used a large amount of energy
    * the commercial use: be limited,...
* Example: The ENIAC computers consisted of
    * **20.000** vacuum tubes
    * **10.000** capacitors
    * **70.000** resistors
    * Weight: over 30 tons
    * Size: take up a lot of space $\to$ huge size $\to$ requiring a large room to house it.

**$2^{nd}$ gen computers:** were based on **transistor**
* Pros: 
    * size: the **size** of electron component **decreased** $\to$ reduced the computer size
    * **less energy** & **not produce as much heat** as first generation
    * language coding: **assembly language**
    * cost: low
    * speed: better
    * portability: better (tính di động)
    * more reliable as compared $1^{st}$ gen
    * the commercial use: be wider
* Cons:
    * cooling system, constant maintenance was required
    * only used for specific purposes
    * commercial production was difficult
* Example: 
    * The **first** computer to use **transistors** was the **TX-0(1956)**
    * Others: IBM 7070, Philco Transac S-1000, RCA 501, ...

**$3^{rd}$ gen computers:** were based on IC (IC - Integrated Circuit: was a single component containing number of transistors) $\to$ use SSI or MSI technology
* Pros:
    * cheaper
    * faster
    * more reliable
    * smaller
    * IC $\to$ reduces the computer size $\to$ improves the performance
    * has big storage capacity
    * mouse & keyboard are used for input devices (instead of punch cards)
    * caculate in ns 
* Cons:
    * IC chips are difficult to maintain
    * air conditioning iss required
    * highly sophisticated technology required for the manufacturing of IC chips.
* Examples: IC digital, IC analog, IC mixture, 

**$4^{th}$ gen computers:** were based on the micro-processors (CPU). ICs, chips and CPU are built by LSI (Large-scale integration) or VLSI (Very large-scale integration) technology $\to$ helped make it possible for desktop PC and laptop.
* Pros:
    * fastest in computation
    * size get reduced
    * less maintenance as compared to be the previous generation of computer
    * all types of high-level programming language can be used
* Cons:
    * the micro-processor design and fabrication are very complex
    * air conditioning is required in many cases due to ICs
    * advance technology is required

**$5^{th}$ gen computers:** were based on AI. 
* AI devices can responds to natural language input and are capable of learning and self-organization.
* ULSI (Ultra Large Scale Integration) technology $\to$ the production of micro-processor chips having 10 millions electronic component.
* Example: The 7nm _"Qualcomm Cloud AI 100"_ chip can hit "far greater" than 100 TOPs (the _Snapdragon_ 855 maxes out at around 7 TOPs), it is a power - efficient edge and cloud computing chip purpose-built for machine learning and big data workloads.
* Today, focusing on developing AI chips and applications. Furthermore, emergence of quantum computing and increase in implementation of AI chips in robotics drive the growth of the global AI chip market.
    * AI chip market was valued at $6.638 million in 2018, and is projected to reach $91.185 million by 2015
* Pros:
    * more reliable
    * works faster
    * available in diffirent sizes and unique features
    * provides computers with more user-friendly interfaces with multimedia features.
* Cons:
    * need very low-level languages, may make the human brains dull and doomed

**$6^{th}$ gen computer:**:
* **Quantum computing** and **nanotechnology** are pioneers in the sixth generation of computers. These technologies possess the power to meet the demands of intense computational power. 
* Quantum computing uses 64-qubits that support simultaneous existence and hence speed up the processing powers.
    *  Quantum with 64-qubit is faster than traditional electric computer with 64-bit CPU very very much: up to $2^{64}$ = 18 billion times
    *  Reason: quantum mechanics allows the qubit to be in a coherent superposition of both states/levels simultaneously
* This technology is still in its initial stages and has the potential to be improved further.

* Pros:
    * The computers of this generation have tremendous processing power and speed. They use quantum computing and parallel processing thus increasing the speed of processing and performing tasks exponentially.

    * With advancements in technology, we now see greater memory capacity in computers. Apart from almost infinite cloud storage, computers now feature storage in GBs and TBs. hence we have more enhanced memory capacity in the computers.

    * Artificial Intelligence has improved considerably with more advanced algorithms and learning capabilities. This helps computers continuously learn, adapt, and improve their performance with time. This has led to more accurate predictions and decision-making.

    * Virtual reality and augmented reality have changed the way we see the world in many ways. It has heavily transformed the entertainment industry and is bringing new experiences with itself.

    * The sixth generation of computers is made more energy efficient with longer battery life and quality. This has not only improved energy efficiency but also promotes sustainability of the environment.
* Challenges:
    * Privacy and security concerns – Artificial intelligence (AI) requires a huge amount of data for training. Quantum computing offers a significant advancement in existing cryptography and encryption methods. But the data stays vulnerable and the security of the data is still a threat. Security and privacy of data available on the internet is a major concern as it could lead to misuse and fraud. Ensuring transparency as to how the data is being used and how AI is making decisions is essential for accountability.

    * Automation and job displacement – The inclusion of AI in various sectors has a significant impact on society. Automation is reducing the need for human effort and making machines more useful and reliable. This is resulting in job displacement and becoming a threat to the working class. Hence ensuring that there are always enough jobs is becoming a task for both employer and employee.

    * Ethical implications of artificial intelligence – As AI is being used more and more for decision-making, there is a need to ensure that it conforms to ethical norms and human values at all times. There is a need to keep in check that the decisions are not biased. Accountability and transparency need to be ensured at all times. There should be a balance between human control and machine autonomy at all times to ensure reliability.

    * Digital divide and accessibility issues – Digital equipment is costly and requires a fair bit of understanding to be used for benefits. While some regions benefit from advanced technology, there are socioeconomic barriers to technology adaption. Ensuring that this technology is accessible to all segments of society and increasing knowledge about their use is the way to truly benefit from these innovations as a whole.

### III. Hardware

-- The term `hardware` covers all of those parts of a computer that are tangible physical objects.

-- ***Circuits***, ***chips***, ***graphic cards***, ***sound cards***, ***RAM***, ***mobo***, ***displays***, ***PSUs*** (PSU (Power Supply Unit) thường được gọi là nguồn máy tính. Đây là một phần cứng của máy tính có nhiệm vụ nhận chuyển đổi dòng điện từ AC thành DC cung cấp năng lượng cho các linh kiện máy khác. Tất Cả các phần cứng máy tính như: CPU, mainboard, ổ cứng, card màn hình hay bàn phím, chuột đều sử dụng nguồn điện 1 chiều DC. Nguồn máy tính chuyền từ điện AC( điện xoay chiều) từ bên ngoài và chuyển thành điện DC theo các đầu Pin.), ***cables***, ***printers***, ***keyboards***, and ***"mice"*** input devices are all hardware.

-- A **general purpose computer** has 4 main components: ***ALU***, ***CU***, ***Memory***, ***I/O devices***. *(cũng có thể nói là gồm 3 bộ phận chính: CPU, Memory, I/O devices)*. These part are interconnected by buses (wires or build-in board)

-- Inside these parts are thounsands to trillions of ***electrical circuits* that can be turned on / off (means bit 1 / bit 0) by ***electronic switches***.

-- The circuits are arranged in ***logic gates*** so that one or more circuits can control the state of other circuits.

1. Input / Output Devices: are all peripheral hardware, and they are usually connected to a computer by cables, or wireless networks (most of them use 2.4GHz band as the preferred frequency range for communication)

* **Output devices:** 
    * An **output device** is any peripheral that receives data from a computer.
    * Some examples of output devices are:
        * Monitor / TV / Video card
        * Speaker / Headphone / Sound card
        * Projector
        * Printer

* **Input devices:**
    * When unprocessed data is sent to the computer with the help of input devices, the data is processed and sent to output devices.
    * The input devices may be hand-operated or automated. The act of processing is mainly regulated by the CPU.
    * Some examples of input devices are:
        * ***Keyboard***: Standard input device. The keys on a keyboard can be divided into several groups based on their functions:
            * `Typing (alphanumeric) keys`: These keys include the same letter, number, punctuation, and symbol keys found on a traditional typewriter.
            * `Control keys`: These keys are used alone or in combination with other keys to perform certain actions. The most frequently used control keys are Ctrl, Alt, the Windows logo key Picture of the Windows logo key, and Esc.
            * `Function keys`: The function keys are used to perform specific tasks. They are labeled as F1, F2, F3, and so on, up to F12. The functionality of these keys differs from program to program.
            * `Navigation keys`: These keys are used for moving around in documents or webpages and editing text. They include the arrow keys, Home, End, Page Up, Page Down, Delete, and Insert.
            * `Numeric keypad`: The numeric keypad is handy for entering numbers quickly. The keys are grouped together in a block like a conventional calculator or adding machine.
        * **Mouse / Trackball / TouchSccreen**: A hand-sized device to move the mouse cursor.
        * **Microphone**:
        * **Digital camera**: Capture images from the real world and put them on the computer. 
        * **Webcam & Camera**: Record images from the real world to your computer.
        * **Video recorder**: to record the video
        * **Scanner**: Convert documents into digital images.
        * **Joystick**: is an input device that can be used for controlling the movement of the cursor or a pointer in a computer device.
        * **Air Mouse (with Keyboard and Mic)**: Chuột không khí là chuột máy tính điều khiển con trỏ bằng công nghệ cảm ứng chuyển động và không cần bàn. Bạn có thể điều khiển con trỏ bằng cách vẫy chuột trong không khí như thể bạn đang trỏ đến nơi bạn muốn con trỏ đi đến.
        * **Drawing Tablet**: Use a stylus to draw on the electronic board.
        * **Barcode Reader**: Used to read barcodes (encrypted numbers).
3. Memory:
4. CPU: The CU, ALU, and registers are collectively known as a central processing unit (CPU)

-- Early CPUs were composed of many separate components but since the 1970s CPUs have been constructed on a single integrated circuit called a **microprocessor**.

-- Nowadays, general purpose computers often use multicore processors. A multicore processor is a single integrated circuit that contains two or more separate processing units, called cores, each core can read and execute program instructions, as if the computer had several processors.

* ALU (Arthmetic Logic Unit): 
    * The set of arithmetic operations that a particular ALU supports may be addition, subtraction, multiplication, division, sine, cosine, square roots, ... Some can only operate on integers.
    * However, any computer an be programmed to perform any arithmetic operation (but it will take more time to do so if its ALU doesn't directly support.)
    * An ALU may also compare numbers or perform other logic operations (AND / XOR / OR / NOT) and return boolean truth values.
    * Computers may contain multiple ALUs, allowing them to process several instructions simultaneously.
    * Graphics processor and components with SIMD and MIMD features often contain ALUs that can perform arithmetic on vectors and matrices.
* CU (Control Unit - control system / central controller): reads and interprets (decodes) the program instructions, transforming them into control signals that active other computer parts.
    * A key component is the program counter (PC), a special register that keeps track of which location in memory the next instruction is to be read from.
    * The control system's function is as follow:
        * Read the code for the next instruction by the PC.
        * Decode the numerical code for the instruction into a set of commands
        * Increment the PC so it points to the next instruction.
        * Read whatever data the instruction requires (the location stored within code) Provide the necessary data to an ALU or register.
        * If the instruction requires an ALU or specialized hardware to complete, instruct the hardware to perform the requested operation.
        * Write the result from ALU back to memory location /register /output device. 
        * Jump back to step (1).
    * Chú ý:
        * PC thuộc thành phần CU (control unit) trong CPU (kiến trúc phần cứng) (chủ yếu) hay GPU (đồ họa).
        * PC là một thanh ghi (register là một vùng nhớ nằm trong con chips xử lý). Nó là thành ghi vì dùng để lưu địa chỉ của các lệch kế tiếp trong bộ nhớ (địa chỉ của nó là con số).
        * PC hay còn được gọi là instruction pointer (IP) trong kiến trúc CPU Intel x86
        * Kiến trúc CPU có bao nhiêu bits thì Program counter (thanh ghi) thường có kích thước là bấy nhiêu bits.

* Đoạn dùng để chứa mã lệnh là code segment
* Đoạn chứa dữ liệu là data segment
* Đoạn dùng để chứa các thông tin ngăn xếp nằm ở thanh ghi là stack segment
* Đoạn để chứa thêm thông tin là ES (expend segment)
* Thanh ghi CS: chỉ số đoạn chứa lệnh
* Thanh ghi IP: vị trí ô trong đoạn.
* Các linh kiện quan trọng trên motherboard (system board / main board / PCB is an important component of any PC, connects all other components): 
* Cổng màu đen: USB 1 chấm
* Cổng màu xanh: USB 3 chấm
* Cổng màu đỏ: USB 2 chấm (sài điện sau khi tắt máy)

Cổng âm thanh:
* Màu đỏ: micro
* Màu xanh lá cây: non
* Màu xanh dương là chuyển âm thanh 

Version USB:
* 1.1: tốc độ 12Mbps
* 2.0: tốc độ 480Mbps = 3.6GBpm (b là bit, B là byte)
* 3.0: tốc độ Gbps
* 3.1:
* 3.2:

***

## Chapter :two: : Data Representation

Số nào cũng 4 bytes hết.
Kết quả phải chuyển về hex
hệ 1 không thể có (vì hệ cơ số 1 chỉ có đúng một chữ số 0 nên ko thể biểu diễn nhiều số được)

### I. Data - Information & Representation:

#### 1. Data - Information - Knowledge:

-- Often the terms **data**, **information** and **knowledge** are used **synonymously**. However, they are not the same !!!
* **Data**: is **physical representation** of **information**, usually in the form of letters, numbers, and other symbols. In computing, data is information that has been translated into an efficient form of **moving** or **processing**. Data is **raw**, **unprocessed**, and **unorganize**. Data can be something simple and seemingly random and unless until it is organized.
* **Information**: is data when it is **processed**, **organized**, **structured** or **presented** in a given context or meaning so as to make it useful. It can be created from Data. Data has no meaning until it is turned into information.
* **Knowledge**: is a **combination** of **information**, **experience** and **insight** that may **benefit** the individual or the organization.

#### 2. Information Coding & Decoding:

-- Humans senses deal with a variety of information (signals).

-- Input devices of computer translates these information into electrical signals.

-- Electrical signals are then translatedd into digital signals based on universal format (0s, 1s), this is known as coding.

-- After processing, output devices transform back data into their original form, this is known as decoding.

#### 3. Representation:

-- The common types of Data / Information: Text, Number, Image, Audio, Video.

-- All data and everything stored in the computer is in binary form, because computer is based on technology of storing and reading only 2 states.

### II. Numeral Systems:

#### 1. Definition:

-- A number is a mathematical object used to count, measure, and label. The original examples are the natural numbers 1, 2, 3, 4, ...

-- A written symbol like "5" that represents a number is called a numeral(chỉ số / chữ số). A numeral system is an organized way to write and manipulate (vận dụng) this type of symbol, for example the Hindu - Arabic numeral system allows combinations of numerical digits like "5" and "0" to represent larger numbers like "50".

-- In common usage, number may refer to a symbol, a word or phrase, or the mathematical object.

-- A numeral system is a collection of symbols and rules for representing numbers and determining values of them.

-- The total number of digits or symbols of a numeral system is called a radix or base, denoted by b. A numeric value will be represented as a base by a numeral system. In general, people mainly use the decimal system (base 10 - using 10 digits (0, 1, 2 , ... 9))

#### 2. Representing Number in Written:
##### 2.1. Integers:
-- The general form to show the value of a number with n numeric digits in radix of b is: $\overline{a_{n-1}a_{n-2}a_{n-3}...a_2a_1a_0}$

-- Value of this representation is: $\sum_{k = 0}^{n - 1}a_kb^k$
($a_k$ is the $k^{th}$ numeric digits in a right-to-left order).

-- Examples: $2389_d = 2.10^3 + 3.10^2 + 8.10^1 + 9.10^0$

##### 2.2. Real Numbers:
-- More overall, any real number representation is: $\overline{a_{n-1}a_{n-2}a_{n-3}...a_2a_1a_0.a_{-1}a_{-2}...a_{-m}}$

-- Value of this representation is: $\sum_{k = -m}^{n - 1}a_kb^k$

-- Examples: $123.456_d = 1.10^2 + 2.10^1 + 3.10^0 + 4.10^{-1} + 5.10^{-2} + 6.10^{-3}$

#### 3. Convert Base:
##### 3.1. Integers:
-- When we have an integer $\overline{a_{n-1}a_{n-2}a_{n-3}...a_2a_1a_0.a_{-1}a_{-2}...a_{-m}}$ in base b, we can:
* Take its value and then divided by b, we will have remainder $a_0$.
* The quotient will be kept on being divided by b and then we will have the next remainder $a_1$ and so on ...
* Keep repeating two above steps until the quotient equals 0, then we can obtain all $n$ numeric digits $a_0, a_1, a_2, ..., a_{n-1}$

-- Examples: 
1. In order to conver 89 in base 10 to base 8, we can follow steps:
    * Lấy 89 chia cho 8 ta được thương = 11 và số dư là 1 $\to$ $a_0 = 1$
    * Lấy tiếp 11 chia 8 ta được thương = 1 và số dư là 3 $\to$ $a_1 = 3$
    * Lấy tiếp 1 chia cho 8 ta được thương = 0 và số dư = 1 $\to$ dừng thuật toán và $a_2 = 1$
    * Suy ra 89 in base 8 là: 131
2. In order to convert 89 in base 10 to base 4, we can follow this steps:
    * Lấy 89 chia cho 4 ta được thương = 22 và số dư = 1 $\to$ $a_0 = 1$
    * Sau đó, ta lấy thương 22 chia cho 4 được thương mới = 5 và số dư mới = 2 $\to a_1 = 2$
    * Tiếp theo, ta lấy thương 5 chia cho 4 được thương = 1 và số dư là 1 $\to a_2 = 1$
    * Cuối cùng, ta lấy 1 chia cho 4 được thương = 0 và số dư là 1 $\to a_4 = 1$
    * Suy ra: 89 in base 4 is: 1211

##### 3.2. Real Numbers:
-- About the real number, when we have $m$ numeric digits, we can:
* Take its value & then nultiplied by b, we will have real part $a_{-1}$.
* The given fractional part will be kept on being multiplied by b and then we will have $a_{-2}$. Keep repeating until the fractional part to be 0, we can obtain all m numeric digits $a_{-1}, a_{-2}, ... ,a_{-m}$

#### 4. Binary Number System:
-- The binary number system is a numbering system that represents numeric values using two unique digits (0 & 1). Mosting computing devices use binary numbering to represent electronic circuit voltage state (on / off switch), which considers 0 voltage input as off and 1 input as on.

-- This is also known as base 2 number system, or the binary number system. With the word "**b**inary dig**it**", we can call "bit" for short.

-- To represent a number that is expressed in base 2, we can write the letter b, or add the number "2" to the end at a slightly lower position.

-- Examples: Cho số nhị phân như sau: 1101.101 . Hãy chuyển đổi sang hệ decimal.

$1101.101_b = 1.2^3 + 1.2^2 + 0.2^1 + 1.2^0 + 1.2^{-1} + 0.2^{-2} + 1.2^{-3} = 13.625_d$

#### 5. Hexadecimal Number System:

-- The hexadecimal numeral system, often shortened to "hex", is a numeral system made up of 16 symbols (base 16).

-- There are no numerical symbols that represent values greater than nine, so letters takes from the English alphabet are used, so numeric digits in base 16 respectively are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

-- To represent a number that is expressed in base 16, we can write the letter h (the abbreviation of the word “hexa”), or add the number “16” to the end at a slightly lower position.

-- The most convenient way is that using hexadecimal system, the form of representation will be shorter and the conversion between it and the binary will be extremely easy and fast.

-- Examples:
* B40 + B52 = 1692
* CAFE + DA = CBD8
* CAFEDA + F16 = CB0DF0

#### 6. Binary & Hexadecimal Conversion:

-- To convert a number that is expressed in base 2 to base 16 system, we may not need to calculate anything. Just simply group each 4 numeric didits cluster in the base 2 system in order from right to left and then rewrite with the corresponding base 16 system.

-- Otherwise, to convert a number that is expressed in base 16 system to base 2, we need to follow those above steps in reverse order by replacing each hexa number with a corresponding base 2 representation to 4 numeric digits.

-- Examples: 
* $1A_h = 00011010_b = 2^1 + 2^3 + 2^4 = 26_d$
* $2019_d = 0000 0111 1110 0011_b = 7E3_h$
* $7B.2_h = 01111011.0010_b = 123.125_d$

### III. Representing Units:

#### 1. Fundamentals of Data Representation:
-- The language that a computer understands is very simple, that it has only 1 and 0.

-- A 1 or 0 is called a bit (which is short for BInary DigiT). This is the fundamental unit of information.

-- Everything you see on a computer, images, sounds, games, text, videos, spreadsheets, websites etc. Whatever it is, it will be stored as a string of 1s and 0s.

-- Byte is a standard unit to measure computer memory, usually consisting of a group of 8 bits.

-- Historically, the byte was the number of bits used to encode a single character of text in a computer, and for this reason it is the smallest addressable unit of memory in many computer architectures.

-- Typically, the symbol B means Byte, and the b means bit.

#### 2. Unit multiples - Prefix:

### IV. Representing Floating-Point Numbers:

#### 1. The floating-point number:

* Any real number R can be expressed: $R = M.B^E$ (where M is the mantissa, E is the exponent and B is the base).


mov => gán
add => cộng
sub => trừ
mul => nhân

AX = AL + AH (32 bits)
(16 bits) (16 bits)

```python
.Model Small

.Code

    mov AH, 2
    init 21h
    mov DL, 'A' #x86.16b
    
    

End
```

---

## :heartpulse: Chapter :four: : PROCESSOR

:diamond_shape_with_a_dot_inside: ==**What will you learn ?**==
:::spoiler
:::info
* How programs are translated into the machine language
* How hardware executes a program
* How CPU process an instruction
* Measuring execution time
* Uniprocessor vs Multiprocessor
:::

### I. Instruction:
* The sequence bit that contains the request that processor must make.
* An instruction consists of 2 part:
    * Opcode: the operation ALU must take
    * Operand: objects affected by the action contained in the code

### II. Instruction Set Architecture (ISA)
* The format and behavior of a machine - level program is defined by the instruction set architecture (ISA).
* Different computers have different instruction sets but with many aspects in common.
* Commonly ISA:
    * MIPS : used in embedded system
    * ARM : A64, A32, T32
    * Power PC
    * IA - 16 : 16 - bits processor (Intel 8086, 80186, 80826)
    * IA - 32 : 32 - bits processor (Intel 80386 - i386, 80486 - i486, Pentium II, Pentium III, ...)
    * IA 64 : 64 bits processor (Intel x86 64, Pentium D, ...)
* ISA Design: CISC & RISC
    * Completed Instruction Set Computer (CISC) : includes many instructions, from simple to complex.
    * Reduced Instruction Set Computer (RISC) : consists of only simple instructions.
    $\Rightarrow$ Which one is better ?
        * :::spoiler
    * The choice between Complex Instruction Set Computing (CISC) and Reduced Instruction Set Computing (RISC) architectures depends on the specific requirements of the application and the design goals. Both CISC and RISC architectures have their advantages and trade-offs.
        * **CISC (Complex Instruction Set Computing):**
            * **Advantages:**
                -   CISC architectures typically have a large set of instructions, some of which can perform complex operations in a single instruction.
                -   This can reduce the number of instructions a program needs, potentially improving code density.
                -   CISC architectures may be more suited for general-purpose computing where a variety of tasks need to be performed.
            * **Disadvantages:**
                -   The complex instructions can make the pipeline more challenging to implement and lead to longer cycle times.
                -   The complexity of the instruction set can make the processor more challenging to design, and it may be harder to achieve high clock speeds.
                -   CISC architectures can be less power-efficient than RISC architectures.
        * **RISC (Reduced Instruction Set Computing):**
            * **Advantages:**
                -   RISC architectures have a smaller set of instructions, each designed to execute in a single clock cycle.
                -   This simplicity allows for pipelining and easier optimization, potentially leading to higher clock speeds and better performance.
                -   RISC architectures are often more power-efficient.
            * **Disadvantages:**
                -   Code may be less dense, as some complex operations may require multiple instructions.
                -   RISC architectures might not be as well-suited for tasks that heavily rely on complex instructions.

    * **Which is "better" depends on the context:**
        -   For general-purpose computing and tasks where a variety of complex instructions are needed, CISC architectures may be more suitable.
        -   For tasks that require high performance, efficiency, and can be parallelized well, RISC architectures may be preferred.
        - In modern computing, the boundaries between CISC and RISC architectures have blurred, and many processors incorporate features from both. Additionally, factors such as compiler technology, memory hierarchy, and system architecture play crucial roles in overall system performance. Therefore, the choice between CISC and RISC is just one aspect of the broader system design.
        :::

<center>
    <img src = https://scontent.fsgn2-7.fna.fbcdn.net/v/t1.15752-9/395097458_927514762046756_8272189672216192557_n.png?_nc_cat=100&ccb=1-7&_nc_sid=8cd0a2&_nc_ohc=DgI2z45y4LsAX-uF1nI&_nc_ht=scontent.fsgn2-7.fna&oh=03_AdRaIUM1_GndclttdDK4nP9_RT2Cy_cng0iAf3KzcnLjug&oe=65B07CE2>
</center>

### III. Assembly Language

* A symbolic representation of machine code, clearer than in machine code
* Each assembly instruction represents exactly one machine instruction
* Ex: Save the value 5 decimal in the register $4
    * Machine code:  00110100 0000100 00000000 00000101
    * Assembly code:
        ```p=
        ori        $4,        $0,     5
        opcode  dest reg    src reg    immediate
        ```
* Since each processor has its own register structure and instruction ser when setting the assembly, it must be clear which processor is set, or the family or the processor.
* Ex:
    * Assembly for MIPS
    * Assembly for the line of Intel 8086 processors

### IV. Compiler
* A program that translates ==high-level language statements== into **assembly language statements**.
* Belong to:
    * The system hardware architecture below which it is running.
    * The high-level language which it compiles.
* Ex:
    * Compiler for C <> Compiler for Java
    * Compiler for "C on Windows" <> "C on Linux"
### V. Assembler
* A program that translates ==a symbolic version of instructions== into the **machine code**.
* A single processor (1 set of definitions) can have multiple assemblers from different vendors running on different operating systems.
* Ex: list of assembler for x86 architecture
> A86, GAS, TASM, MASM, NASM
* The Assembly program depends on the assembler it uses.
### VI. Linker & Loader
* Who will compile the compiler ? (It's also a program)
    :::spoiler
    **$\Rightarrow$ Assembler**
    :::
* How the hardware execute a program?
    :::spoiler
    **$\Rightarrow$ Loader & Linker**
    :::
* Linker: A systems program that combines independently assembled machine language programs (object file) and resolves all undefined lables into an executable file.
* Loader: A systems program that places an object program in main memory so that it is ready to execute.
### VII. Create executable file

<center>
    <img src = https://scontent.fsgn2-9.fna.fbcdn.net/v/t1.15752-9/413204182_1420505778845409_5876020044815835181_n.png?_nc_cat=103&ccb=1-7&_nc_sid=8cd0a2&_nc_ohc=iPs8Er0JHR8AX-C1UI3&_nc_ht=scontent.fsgn2-9.fna&oh=03_AdR2L3XXfelp6rVhLzRi4Syhn19A2nPu3cC_DqE2a8U6yg&oe=65B05E29>
</center>

### VIII. Translation hierarchy
* A translation hierarchy for C
    <center>
        <img src = https://scontent.fsgn2-6.fna.fbcdn.net/v/t1.15752-9/410621811_1383897775664928_7248329358588008900_n.png?_nc_cat=110&ccb=1-7&_nc_sid=8cd0a2&_nc_ohc=uxhNny8lI4cAX_1Zbga&_nc_ht=scontent.fsgn2-6.fna&oh=03_AdTMMFtVjcvVZWKnjI6_6X8NHlt_CHvOKHc80TlOZk_eeA&oe=65B0650B>
    </center>
* A translation hierarchy for Java
    <center>
        <img src = https://scontent.fsgn2-9.fna.fbcdn.net/v/t1.15752-9/412793620_1271155313562431_8115806509949237899_n.png?_nc_cat=106&ccb=1-7&_nc_sid=8cd0a2&_nc_ohc=qUOMeplCDkcAX8oju2l&_nc_ht=scontent.fsgn2-9.fna&oh=03_AdQ9tuAuy7hS15_yRaAT-lq9sdXKBzpy1OWV4a9spNCf8Q&oe=65B090A0>
    </center>
### IX. Realistic Model
<center>
    <img src = https://scontent.fsgn2-6.fna.fbcdn.net/v/t1.15752-9/411850992_414415494250456_118362469775841148_n.png?_nc_cat=111&ccb=1-7&_nc_sid=8cd0a2&_nc_ohc=Ns9Tx6T-yh4AX99DnRW&_nc_ht=scontent.fsgn2-6.fna&oh=03_AdRfpDiTA7JuO5JA3th5O9zAFIlHu-pIWzeQbGmGUMuh3Q&oe=65B08F3B>
</center>

* Compiler and assembler can be skipped in the certain cases.
* In fact, there are several compilers that can create executables on a variety or underlying architecture platforms (cross - platform compiler).
* Ex: Compiler for Java, Cygwin, Code::Block Studio

### X. Instruction Processing
<center>
    <img src = https://scontent.fsgn2-11.fna.fbcdn.net/v/t1.15752-9/410855251_1104866364024173_788414870681181731_n.png?_nc_cat=105&ccb=1-7&_nc_sid=8cd0a2&_nc_ohc=yBDs_Gzxnw4AX8GSVhG&_nc_ht=scontent.fsgn2-11.fna&oh=03_AdRgLv9NY2IzqeDTz9zh0cRaOdM4uc2sVF3-oo9z-npo6g&oe=65B08C3F>
</center>

* Instruction Cycle : consists of 2 phases
    * Fetch Cycle: Transfer data from memory to registers.
        :::spoiler
        * PC (Program Counter): Store the next instruction's address.
        * MAR (Memory Address Register) : Store the address of a location in memory (output to address bus)
        * MBR (Memory Buffer Register): A word of data to be written to memory or the word most recently read (output to data bus)
        * IR (Instruction Register): Contain the most recently fetched instruction.
        <center>
            <img src = https://scontent.fsgn2-6.fna.fbcdn.net/v/t1.15752-9/403646990_1159862968730526_9041950893417851224_n.png?_nc_cat=111&ccb=1-7&_nc_sid=8cd0a2&_nc_ohc=jYObcRY1EeIAX8HB2d8&_nc_ht=scontent.fsgn2-6.fna&oh=03_AdSuRa2UcLiWHzPcmio53Ja2qOJMUvqRYn2BG8JgQmbR0Q&oe=65B07BF8>
        </center>
        
        * The control unit move the instruction which has address in PC registers to IR $\to$ Default update PC reg : PC += size of the fetched instruction
        * The fetched instruction is loaded into an IR, where the opcode and operand are analyzed.
        * Data are exchanged with memory using the MAR and MBR. 
        
        <center>
            <img src = https://scontent.fsgn2-5.fna.fbcdn.net/v/t1.15752-9/403399509_1119089699252734_1195427585499614105_n.png?_nc_cat=104&ccb=1-7&_nc_sid=8cd0a2&_nc_ohc=5KYRI7hTWk8AX8Fmoq_&_nc_ht=scontent.fsgn2-5.fna&oh=03_AdTldFAlE9BGcNN0aHnyb7iyhwR7fBtcAVL7ggdR7AHoFg&oe=65B07B26>
        </center>
        
        * Examples:
        <center>
            <img src = https://scontent.fsgn2-9.fna.fbcdn.net/v/t1.15752-9/410424767_752654893572357_1666171474208794272_n.png?_nc_cat=106&ccb=1-7&_nc_sid=8cd0a2&_nc_ohc=G4qZ8wivfTcAX-YS-TO&_nc_ht=scontent.fsgn2-9.fna&oh=03_AdRacEvcEmA_9tnKRimUdua7uJS3e39OT023Jeu-TQZ9tA&oe=65B081F6>
        </center>
        :::
    * Execute Cycle: Decode the instruction and execute the requirements of it.
        :::spoiler
        <center>
            <img src = https://scontent.fsgn2-6.fna.fbcdn.net/v/t1.15752-9/412707497_1136421081097742_6738058042355426542_n.png?_nc_cat=111&ccb=1-7&_nc_sid=8cd0a2&_nc_ohc=7YPeyZhIob4AX-Kp_BJ&_nc_ht=scontent.fsgn2-6.fna&oh=03_AdRIlWKsV3CgCJfpLKHdi_TMaIZLIRobQl99YlNfuWYpgQ&oe=65B075E8>
        </center>
        
        * Measuring execution time:
            * Elasped time:
                * Total response time, including all aspects: processing, i/o, idle time, OS overhead
            * CPU time:
                * Time spent processing a given task
                * Comprise user CPU time and system CPU time
                * Different program are affected differently by CPU and system performance.
        :::


