CS 271 Midterm
Converting unsigned decimal to hexadecimal
Repeatedly divide by 16 and retain each remainder as a hexadecimal digit. The last digit retained is the most-significant in the hexadecimal number.
Translate unsigned decimal integers to binary
Repeatedly divide by 2, saving each remainder as a binary digit. The most-significant bit will be the last digit saved.
Two's complement of a hexadecimal number
Reverse the bits by subtracting each digit from 15 (F), then add 1.
Lower 16 bits of ESI (EDI, EBP, ESP)
SI
Auxiliary Carry flag (AC)
Set when an arithmetic operation causes a carry from bit 3 to bit 4 in an 8-bit operand.
Sign flag (SF)
Set when an arithmetic or logical operation generates a negative result. Sign Flag is a copy of the destination operand's highest bit.
Zero flag (ZF)
Set when an arithmetic or logical operation generates a result of zero.
Overflow flag (OF)
Set when the result of a signed arithmetic operation is too large or too small to fit into the destination.
Carry flag (CF)
Set when the result of an unsigned arithmetic operation is too large to fit into the destination. Either: (Addition) Result is larger than bits available, so MSB flips from 1 to 0 (Subtraction) A larger number is subtracted from a smaller number
Wait states
Empty clock cycles, caused by a processor waiting on other components
Three basic steps of the instruction execution cycle
Fetch, decode, execute
Static RAM
High-speed memory chips that do not have to be refreshed to hold their data. Cache memory is constructed from static RAM.
Register
High-speed storage location inside the CPU, designed to be accessed at much higher speed than conventional memory.
Segment registers function
Hold pointers to segment descriptor tables. Segments hold: Program instructions (code) Variables (data) Local function variables and function parameters (stack)
Instruction queue
Holding area for instructions that are about to execute
Address bus
Holds the addresses of instructions and data when the currently executing instruction transfers data between the CPU and memory.
Converting signed binary to decimal
If the highest bit is 0: the number is positive, so proceed as if it's an unsigned integer. If the highest bit is 1: the number is negative, so you need to create its two's complement to get the positive equivalent, then proceed as if it's an unsigned integer.
Range of an unsigned integer with n bits
0 to 2^n - 1
Instruction execution cycle
1. CPU fetches the instruction from the instruction queue and increments the instruction pointer 2. CPU decodes the instruction, which may contain operands. 3. If operands are involved, the CPU fetches the operands from registers and memory (sometimes involves address calculations) 4. CPU executes the instruction and updates status flags 5. If an output operand was part of the instruction, the CPU stores the result of its execution in the operand.
Steps to load and execute a program
1. OS searches for the program's filename 2. If program is found, OS retrieves basic information about the program's file 3. OS determines next available memory location, allocates a block of memory, enters information about program into a descriptor table. 4. OS begins execution of the program's first machine instruction (entry point). Program is now called a process. 5. Process runs by itself, tracked by the OS 6. When process ends it is removed from memory.
Steps for reading from memory
1. Place the address of the value on the address bus 2. Assert (change the value of) the processor's RD (read) pin 3. Wait one clock cycle for the memory chips to respond 4. Copy the data from the data bus into the destination operand
Number of bits in a Double quadword
128
Number of bits in a Word
16
First 5 powers of 16 (hexadecimal digits)
16^0 = 1 16^1 = 16 16^2 = 256 16^3 = 4096 16^4 = 65,536 16^5 = 1,048,576
KiB (kilobyte)
2^(10), or 1024 bytes
MiB (megabyte)
2^(20), or 1,048,576 bytes
GiB (gigabyte)
2^(30), or 1024^3, or 1,073,741,824 bytes
TiB (terabyte)
2^(40), or 1024^4 bytes
PiB (petabyte)
2^(50), or 1024^5 bytes
exabyte
2^(60), or 1024^6 bytes
zettabyte
2^(70), or 1024^7 bytes
yottabyte
2^(80), or 1024^8 bytes
Number of bits in a Doubleword
32
How large of an address space does a 32-bit processor running in protected mode have?
4 GiB
Number of bits in a Quadword
64
Number of bits in a Byte
8
Four general-purpose register names
EAX EBX ECX EDX
Four multi-purpose register names
EBP ESP ESI EDI
Precedence of Boolean operators
( ) NOT AND OR
Range of a signed integer with n bits
-2^(n-1) to +2^(n-1) - 1
Multiplexer
A digital component that uses a selector bit (S) to select from a set of inputs. If n is the number of inputs, you need log_2(n) selector bits.
Interpretation
As the L1 program runs, each of its instructions is decoded and executed by a program written in L0. The L1 program begins running immediately, but each instruction must be decoded before it can execute, causing a delay.
ECX function
Automatically used as a counter by the CPU.
Machine Language
A numeric language specifically understood by a computer's processor.
Bus
A parallel transfer path that moves data from one part of a computer to another. A computer system usually has four types: data, input/output (I/O), control, and address.
String
A sequence of one or more characters
Virtual machine
A software program that emulates the functions of some other physical or virtual computer.
ASCII digit string
A string of ASCII characters representing a number, such as "123" or "65". Can use decimal, hexadecimal, binary, octal.
Null-terminated string
A string of characters followed by a single byte containing zero.
Operand
A value that is either an input or an output to an operation.
8-bit segments of the lower 16 bits of EAX
AH AL
Lower 16 bits of EAX
AX
EAX function
Automatically used by multiplication and division instructions. Often called the Extended Accumulator register.
ESP function
Addresses data on the stack. Often called the Extended Stack Pointer register.
Binary integer
An integer stored in memory in its raw format. Stored in multiples of 8 bits.
Unpacked BCD
Binary-coded decimal format with one digit per byte. For example, 1,234,567 can be stored as an array of bytes (shown in hex): 01, 02, 03, 04, 05, 06, 07.
Packed BCD
Binary-coded decimal format with two digits per byte. For example, 1,234,567 can be stored as an array of bytes (shown in hex): 01, 23, 45, 67
Memory Storage Unit
CPU component in which instructions and data are held while a computer program is running.
16-bit segment registers
CS SS DS ES FS GS
Status flag names
Carry Overflow Sign Zero Auxiliary Carry Parity
Control flags
Control the CPU's operation - can cause CPU to break after every instruction is executed, interrupt when overflow is detected, enter different modes.
Converting signed decimal to binary
Convert the absolute value to binary If the original decimal was negative, create the two's complement of the binary number.
Converting signed decimal to hexadecimal
Convert the absolute value to hexadecimal If the decimal was negative, create the two's complement of the hexadecimal number.
Control Unit
Coordinates the sequencing of steps involved in executing machine instructions.
Converting signed hexadecimal to decimal
If the highest digit >= 8, the number is negative. Create the two's complement, then convert that number to decimal. If the highest digit <=7, the number is positive. Convert to decimal as if it were an unsigned integer.
Real-address mode
Implements the programming environment of an early Intel processor. Only 1MiB of memory can be addressed and only one program can be run at a time. Allows programs to access any memory location, including addresses directly linked to system hardware.
EIP function
Instruction pointer - contains the address of the next instruction to be executed
Four levels of machine
Level 1: A computer's digital logic hardware Level 2: ISA (machine language) Level 3: Assembly language Level 4: High-level language
Program entry point
Memory address at which the program is to begin execution.
Cache
Memory inside the CPU that can hold recently used copies of instructions and data. Level-1 cache (primary): stored right on the CPU Level-2 cache (secondary): attached to CPU by a high-speed data bus
Random Access Memory (RAM)
Memory that can be accessed in any order, using individual addresses.
Dynamic RAM
Memory that must be constantly refreshed. Slower but cheaper.
Registers
Named storage locations in the CPU that hold intermediate results of operations.
Is assembly language portable?
No, assembly language is designed for a specific processor family.
Assembly Language
Programming language that has the same structure and set of commands as machine languages but allows programmers to use symbolic representations of numeric machine code.
Relationship between machine code and micro-instructions
One machine instruction can map to multiple micro-instructions.
Relationship between high-level languages and assembly/machine language
One-to-many. A single statement in a high-level language expands into multiple assembly language or machine instructions.
Relationship between assembly language and machine language
One-to-one. Each assembly instruction corresponds with exactly one machine instruction.
Big-endian order
Ordering of binary bits with high-order bit at the end.
Little-endian order
Ordering of binary bits with the low-order bit at the end.
Arithmetic Logic Unit (ALU)
Performs mathematic operations such as addition and subtraction and logical operations such as AND, OR, and NOT.
3 primary modes of an x86 processor
Protected mode Real-address mode System management mode
System management mode
Provides the OS with a mechanism for implementing functions such as power management and system security.
Two's complement representation of a binary number
The negative equivalent of a positive binary value can be obtained by reversing its bits and adding the value 1. The two's complement is the additive inverse of the original binary number.
EFL function
Status register (EFLAGS, Flags) - consists of individual binary bits that control the operation of the CPU or select the outcome of some CPU operation.Con
High-frequency clock
Synchronizes the internal operations of the CPU with other system components.
Machine cycle/clock cycle
The basic unit of time for machine instructions. The length of a clock cycle is the time required for one complete clock pulse (time between one falling edge and the next)
Central Processing Unit (CPU)
The core component of a computer that executes machine instructions. Components: Registers High-frequency clock Control Unit Arithmetic Logic Unit (ALU)
Instruction Set Architecture (ISA)
The design of a computer's central processing unit (CPU).
Translation
The entire L1 program is converted into an L0 program by an L0 program designed for that purpose. Then the resulting L0 program can be executed directly.
Protected mode
The native state of the processor. Programs are given separate memory areas named segments (each up to 4 GiB), and the processor prevents programs from referencing memory outside their assigned segments.
I/O Bus
Transfers data between the CPU and the system input/output devices
Data bus
Transfers instructions and data between the CPU and memory
EBP function
Used by high-level languages to reference function parameters and local variables on the stack. Often called the Extended Frame Pointer register.
ESI and EDI function
Used by high-speed memory transfer instructions. Sometimes called Extended Source Index Extended Destination Index registers.
Control Bus
Uses binary signals to synchronize actions of all devices attached to the system bus.
Linker
Utility program that combines individual object files created by an assembler into a single executable program
Assembler
Utility program that converts source code programs from assembly language into machine language
Program loader
Utility program that loads other programs into memory before they are executed
How to find b, the number of binary bits you need to represent an unsigned decimal value n
b = floor(log_2n + 1)