XJTLU CSE101 revision note

/* This is my revision note of the CSE101 module. Hopefully you can find it somehow helpful.
------by Livingstone, 2020. */

Overview of this course

  • How the computer works at the machine code level
  • Understand some of the computer hardware
  • basic principle of data storage, and coding of information
  • the roles and organization of major kinds of system software

content:

  • Overview of computer systems: hardware and software
  • Machine architecture and instruction execution(stored program, program execution)
  • Machine-level correspondence to higher level constructs(loop, conditional, subroutines, recursions)
  • Building computers from logic: logic gates, simple circuits

Hardware and software

Downward compatibility(backward compatibility): an application developed using one version of the platform should still work in a newer version of platform(the platform should be designed to support this) //platform means both hardware and software

VHDL: Very high speed integrated circuits Hardware Description Language, used to specify both the structure and the function of hardware circuits.

Operating system: functionalities of the hardware systems can be brought out by the operating systems and offered to the user. the user interacts with the hardware through the OS.
-ease the programming;
-protects the core hardware system
-ease for non-professionals using.

Moore’s law: the amount of the transistors which can be placed on a given chip area approximately doubles every two years

4 architectural levels of computer systems: 1. assembly language level 2. instruction set architecture level 3. micro architecture level 4. digital logical level.
Advantages of hierarchical structure: easy for non-professionals to understand, easy for engineers to make changes.

WIMP: Window-Icon-Menu-Pointer, in I/O

Components: CPU, main memory, secondary storage, input devices, output devices.
The hardware of the computer can only perform simple tasks, in order to perform useful tasks, these simple steps are combined in the form of programs, known as software.

Instruction set: every CPU has its own instruction set, typically 100-200 instructions. although different CPU has similar instruction sets, there is no standard.
Machine instructions include input-output, data transfer and manipulations, program control and hardware control, machine control.
HLL(High Level Languages) are easier to understand, and more suitable for programming, however they must be translated back into machine code to run on computers.

Models of modern computers

  • Input-Process-Output model
    在这里插入图片描述
    The process part is controlled by a custom-made model. The IPO model is the fundamental structure of the current generation of digital computers.

  • Von Neumann Model (the ‘process’ part of the IPO model)

    The computer is a general-purpose machine controlled by a executable program.

    Program: a list of instructions

    Processor is the core part that executes the program.

    both program and data are stored in the memory for the processors to use. The memory is rewritable, therefore Von Neumann Model can handle different problems.
    Von Neumann bottleneck: the memory is much slower than the CPU, therefore the CPU has to continuously wait for the data to be transferred between CPU and memory.

    • Harvard architecture

    it seperates programs from data, and use different memory to store. This change can increase transfer rates and improve throughput.

To distinguish data and instructions (since they are both represented in binary code): the computer has the address of data and program, knows where to fetch them.

Programming language and Program execution

HLLs has to be translated into machine code for executing. The term semantic gap describes the enormous difference between HLL and machine code.

Compilers, Assemblers and Interpreters

translation of the HLLs is done by special programs.

  • Compilers translate the HLL instuctions into machine code before running.
  • Assmblers translate the mnemonic form of machine instructions into their corresponding machine code. Then assoiate the labels with memory addresses, finally produces a binary machine object code program.
  • Interpreters translate the HLL into tokens (intermediate code), than machine code on-the-fly(the process of translation and execution are interlaced)在这里插入图片描述
  • when compile-time error occur, we should go back find the source program and debug.

Linking–resolving external references

When the compiler is running, it can only compile one module at a time. The external references in the module will remain symbolic until the linker gets to work.

Code sharing and reuse

在这里插入图片描述

  • Source-level subroutines and macro libraries

    routines are stored in libraries, and edited into programs while being translated. However, this will cause problems while transferring the code.

  • Pre-translated relocatable binary libraries

    they could be linked into the new routines but not read or altered. However each program that uses the routine need to have a private copy of it, which is a waste of space.

  • Dynamic library (memory-resident library)

    load public routines which have already been loaded into memory. They are mapped through memory management system.

    There exists de-facto standard of dynamic libraries and dynamic linking (Microsoft active standard)

Data codes–numeric and character

Computer use binary number system both for data storage and processing of operations. However for human beings we usually use decimal number system in our daily life.

Therefore when using computers, we need to convert words/characters/number/image… into binary form and back. (为数据编解二进制码)

Binary and base n notation systems

  • bit–the basic unit of information

    one bit contains the information necessary to distinguish two alternatives.

  • Base n notation

    commonly used in computer science: n= 2, 8, 10, 16…

    conversion: multiply the weighting value by the associated digit, and then add all the results.

Alphanumeric codes

data need to be coded, and the choice of code may be arbitrary, therefore there needs a standard.

representation of characters

  • ASCII code (American Standard Code for Information Interchange)

    It’s a 7-bit code, including printing characters and control characters.

    Most widely used by non-IBM mainframes and microcomputers

    It only used half of one byte; the another half was used as extension to represent codes of additional numbers.

    Limitation of ASCII code: the need of international character sets.

  • EBCDIC code (IBM mainframe computers)

    8-bit code, the coding sequence is discontinuous, hard to remember

    not yet commonly used

  • Unicode

    It’s recent 16-bit standard

representation of numbers

  • Integers

    Generally 4 bytes, i.e. 32 bits. Two’s complement

  • Real numbers

    IEEE 754 standard.

Declaration of variables tells the compiler to reserve correct amount of memory space to hold the variable, and the encoding/decoding method to be used.

Operating System

The most important development during past 40 years’ development of OS: Window Interface/WIMP

  • Function:

    To interpret and carry out the commands issued by user or application programs

  • Fundamental purposes:

    Management: to control and operate hardware in an efficient way

    Provide functionalities: to allow the user efficient, fair, protected access of the machine, and interact

    Onion ring model在这里插入图片描述

    • kernal is the core of OS, which deals directly with the hardware
  • properties of Modern operating systems:

    Multitasking: Allow for the simultaneous processing of multiple programs;

    in order to allow multitasking, the OS must include:

    1. memory manager: to allocate memory and other resources to each program;
    2. scheduler: allocate CPU time for each program
    3. security kernal: to maintain integrity of each program (avoid one program changing another program’s data)

    Multiuser: Support multiple users run program at the same time

  • Interaction with the OS:

    CLI (Command line interpreter)/ API在这里插入图片描述

    Network:

OS usually provide network facilities through API;

Server/Client…

Principal components of a computer

3 principal subsystems: CPU, main memory, IO units

CPU: ALU (logical and mathematical calculation) + control unit (responsible for performing machine cycle)

CPU registers: small but fast memories, that temporarily stores the data and address variables.

-coprocessors: microprocessors that performing specialized functions that CPU cannot perform well: e.g. math, graphics

Data exchanging: Buses

a bus is a bundle of wires/tracks. Typically, there are address, data and control buses.

The devices connected through buses can have access to any signal line they require. However, bus can only transfer one item of data at a time, which may leads to limit on performance, termed bus bottleneck.

Output devices: monitor,

Screen resolution: pixel…

Ports: parallel/serial port 并行/串行

USB(Universal Serial Bus)

General purpose machine/special purpose machine: a general purpose machine has an OS, can do anything but the efficiency is not very high; a special purpose machine does not have OS, but it can only do some special things with high efficiency.

Instruction set and machine cycle

Instruction set: the collection of machine language instructions that a particular processor understands.

CISC/RISC: Complex/Reduced Instruction Set Computer
RISC faster, because chip can be designed to accelerate those most common instructions;

Fetch-execute cycle (machine cycle): instruction fetch, instruction decode, execute, store results.

fetch: IP->MAR; IP++; Memory copies the content in the MAR address to IR; Decode the content in IR

execute: the execution depends on the specific instruction. MBR is used in this process to store the data being transferred to and from the memory.

Assembly language and assembler

the assembler takes a program written in assembly language as input, and translate the mnemoric form of instructions into their binary machine code form. Then the labels are associated with their memory address, finally a binary machine object code program (also called object file) was produced. To run the program, the program has to be generated executable by linking object files together and loaded into main memory and then get executed.

Labels signify the beginning of the loop, the beginning of a block of memory cells etc.

Main memory and registers

RAM (random access memory): access time is the same for all addresses.

word, byte, bit: a byte=8 bits; word may vary between different computers, 32-64

Registers:

EAX, accumulator: used as general-purpose data register during arithmetic and logical operations. AL, AH, AX, EAX

EBX, the base register: used to hold addresses that point to the base of some data structures, such as arrays.

ECX, the count register: used as the counter in loops.

EIP, the instruction pointer: holds the address of the next instruction.

ESI, the source index register: used as a pointer for string or array operations [EBX+ESI]

EDI, the destination index register, similar to ESI, but for destinations.

EBP: the stack base pointer

ESP: the stack pointer

EFLAG and Stack

EFLAG

the Flag register holds the CPU status flags. the status flags are just separate bits in EFLAG where information about important arising conditions is recorded. It is a way of communication between one instruction and subsequent instructions.

flags are set (or cleared) after an instruction is being executed.

Most often used flags:

  • S: sign flag.
  • Z: zero flag, set when the result being 0.
  • C: carry flag, set indicates an arithmetic carry.
  • O: Arithmetic overflow error,

CMP: compare two values without result, just setting flags.

Stack

the order of storing and retrieving the values for the stack can be described as LIFO(last in first out)

the ESP register stores the address of the item that is on top of the stack, stack grows downwards in the memory.

two operations: PUSH: decrement the ESP, and using the ESP address to write the item into stack.
POP: read the item using ESP address, then increment the ESP address.

we can use stack as temporary storage. e.g. we can temporarily use the stack to store ecx while using ecx register for other purposes.

Using stack for passing parameters

e.g. push eax - call printf - add esp, 4

Structure of instructions and addressing modes (Assembly)

operation, operands, result

machine instructions are encoded with district bit fields in the prefix to contain information about the operation, the location and type of the operands.

the length of the instruction can vary depending on the operation and address needed

addressing modes

effective address is teh address of operand used by instruction.

  • immediate mode: using directly the value
  • data register direct: using the register that contains the operand (fastest)
  • Memory direct: decode the address into the CPU register, then go to main memory to load the data needed
  • Indexed register indirect with displacement: [ebx+eax] ebx[eax]

Inline assembly programming

Output and input in inline assembly

we use printf and scanf for outputing and inputing in inline assembly. printf(“format”, variable, variable) 把格式字符串push进栈的时候用lea字符数组

%i is used to denote signed decimal number

e.g.

push myint
lea eax, format
push eax
call printf ;notice that printf will not pop values in the stack
add esp, 8

scanf(“format”, %variable)记得将变量地址push进栈

Controlling program flow

  • Jump: changing program control from one location to another

    unconditional jump: JMP <address of the target instruction>(Usually by using label)

    conditional jumps: check the condition, if true then jump, otherwise continue.

    ​ JCXZ, JZ, JC/JB(carry flag is set), JNC/JNB, JE/JZ (zero flag is set), JS/JNS, JO/JNO

    ​ JG/JGE, JL/JLE

  • Loops: set counter, then use LOOP LABEL to loop. ecx will decrement by 1 each loop

    mov ecx, 200
    loopthis: 
    ...
    loop loopthis
    

    also there are LOOPNE…

Subroutines

subroutine is a part of the code, which can be used repeatedly within the program that is being executed.

call of subroutines from different part of program should return to different addresses.在这里插入图片描述
In the picture above, ‘label’ represents the name of the procedure.

CALL: pushes the current value of EIP as return address into stack, and place the required subroutine address to EIP.

RET: pop the last address stored in the stack, and put it into EIP.

Passing parameters

two main forms of parameters:

  • Value parameters: the program just need the value, without changing its value.
  • Reference parameters: the program need to change the value of the variable.

methods to pass parametes: through registers/stack
Registers are limited, therefore better use stack for a large number of parameters.

Stack frame: the area of stack which holds all data related to one subroutine call.
Those data includes: parameters of the subroutine, return addresses, local variables.
several stack frames may be present at the same time, therefore two registers are used to work with them:

EBP: point to the base of the current stack frame

ESP: the stack pointer, hold the address of the top of the stack

When calling subroutine:

parameters, return address, EBP are pushed on the stack. Then a new stack frame is created, the current address of the top of the new stack frame is saved in EBP, the local variables now will be installed on the new stack.

When returning:

the local variables are poped out, the EBP is restored, the return address is poped out and saved in the EIP. the parameters of the subroutine is cleaned up.在这里插入图片描述

Recursive subroutines

a subroutine may call itself to perform some job. mutual recursion…在这里插入图片描述

Numeric encoding and calculations

Numeric encoding

  • unsigned integers: just store the number in binary.

    BCD (Binary-coded decimal): each decimal digit is individually converted into binary and stored. It requires 4 bits per digit.

    However less economical, more difficult for calculations than binary represetations. However, translating from BCD to character form is much easier.

  • Signed integers: sign-and-magnitude representation-> complementary representations.

  • floating point numbers: representing numbers in the form of a × b n a\times b^n a×bn

    The base of the exponent and the location of the binary point are standardised, do not need to be stored.

    mantissa+exponent+sign. exponent is represented by complementary form. For maximized precision, numbers are stored with no leading zeros(also, as the first bit in this representation will always be 1(1.xxxxxxxxx), this bit can be omitted too). The transformation of the number (transform into the format above) is called normalisation.

    32bit floating point numbers: IEEE754 1 bit for sign, 8bits for excess-127 notation(-127-127, 128reserved for NaN and infinity), 23bits for mantissa.

    double-precision: 1 bit sign+11bit exponent (excess-1023 notation) +52bit fraction

Calculations

  • negation: 每一位反转后+1

  • addition: 直接相加,无视进位

  • substraction: negation then addition.

    Testing overflow: both inputs has the same sign, but the output sign is different, overflow.

    Sign: the two’s complement system is unevenly divided. Numbers that begins with 0 are considered to be positive, while Numbers begins with 1 are considered to be negative.

Data storage

Memory

Main memory: the computer can only manipulate the data/ execute the instruction that is loaded into the main memory.

two types of RAM:

  • DRAM (Dynamic RAM): cheaper, slower, need to be refreshed(because it is implemented by capacitors, which will leak charge over time)
  • SRAM (Static RAM): no need for refreshing

both types of RAM are volatile, which means the data saved will be lost when cut off from the power.

ROM: Read-only memory, the software stored inside is also known as firmware

Cache memory: quick access memory to the processor

Massive storage

Hard disks, Optical (光学的) disks, USB disks

HDD(Hard disk drive): most important type of permanent storage.

###Storing real-world data in digital

sampling rate

Address of the memory

maximal memory length depends on address width, which is the number of lines in the address bus, and equals to the number of bits in the CPU address registers such as MAR, IP.

Memory mapping: usually prefix dicides which chip to look for.

Memory Hierarchy

The cache memory contains a copy of the portion of main memory.在这里插入图片描述
When in need of some information, the processor will first check the cache, then memory.

the idea of cache memory exploits Localisation of Memory Access principle: computers tend to spend periods of time accessing the same locality of memory (saving a group of data together, and using loops) .

Hardware of Computers

Disks

  • HDD

platter has its information recorded on both surfaces. each platter has two heads. the information is recorded in concentric circles called tracks (磁道). each track is broken down into smaller pieces called sectors(512 bytes each).在这里插入图片描述
addressing mode: CHS(Cylinder, Head, Sector), LBA(Large Block Addressing, the absolute number of the sector)

Disk cache : a portion of the main memory is used as a buffer to temporarily hold the data for the disk. (because the disks write operations are clustered, and the data written out may be needed again)

Virtual memory : using low-level memory to expand high-level memory. The area on disk reserved for this purpose is known as the swap area.
Main memory and executable program are both divided into frames(pages) often 4KB, and when executing, the necessary pages are loaded into the memory, and the rest are copied into the disk area. when need a page that is not loaded into the main memory yet, the least used frame will be freed to load the new page. Swapping

Logical circuits

Computer is basically a complex electrical circuit. During the operation of the machine, current may flow along the physical connections. The presence of the current is used to present 1, while absence of current represents 0.

This kind of circuit is called digital electronic circuit, since the relevant characteristic is the presence or absence of current, rather then the amount of the current flowing.

Analog systems: analog signal is a continuously changing value

All operations that a computers perform may be difined in terms of basic biilean functions, operating on bits.
Gates:在这里插入图片描述在这里插入图片描述
XOR represents exclusive-or, the result is true only when the inputs are different.

Use filter to control data flow (this means the data can or cannot flow through the circuit): simple, just use an AND gate, and a control signal.

  • Selector circuit:在这里插入图片描述
    The logical expression of the selector circuit: (S&&A)||(~S&&B)

  • Data selector:
    在这里插入图片描述The circuit above selects data. Using two-line decoder for the control signal is more efficient and can prevent some possible errors.
    在这里插入图片描述Two-line decoder is easy to implement.

TO implement a funtion:

easiest: use and/not gate to implement every input that the function gives one; then connect the outputs of them together to a OR gate.

Adders:

在这里插入图片描述This is a half adder, which does the job for one bit of addition.
在这里插入图片描述
By combining half adders, we get a full adder.

Sequential logical circuits

Combinational logical circuits: the output at any moment depends only on the input as the same moment.

Sequential logical circuits: the output depends also on the state of the circuit. the state of the circuit is somehow stored in the circuit(the circuit has memory.)

Basic memory element: flip-flop, or latch

  • SR (Set-reset) flip-flop在这里插入图片描述
  • SR flip-flop must avoid cases where S and R are both 0. S=R=1 is the stable state, as long as the S and R are remained 1. when one of them changes, the circuit may switch the state.

In one word, the SR flip-flop remembers which input was set momentarily to 0 last.在这里插入图片描述

  • D flip-flop
    在这里插入图片描述
    D flip-flops can be used to copy data.

Finally, about the exam:

Generally speaking, the exam is way more easier than my expectation. All the MCQs are covered in the note above. There is even a question that has no answer correct in the MCQ. So do not overestimate the difficulty of the exam… Good luck!

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值