MIDTERM HELL ULTRA PAIN Flashcards
What is RAM?
Volatile Memory: Data is lost when the power is turned off.
Read/Write: Both reading and writing operations are allowed.
Primary Memory: Used to store data and programs currently in use.
What is ROM?
Non-Volatile Memory: Retains data even when the power is off.
Read-Only: Cannot be modified easily or at all by the user.
Stored Programs: Contains essential programs for booting and operating the computer (firmware).
What is the CPU?
Central Processing Unit: The brain of the computer that performs computations and controls other components.
What is memory?
Data and Instruction Storage: Stores data and instructions for the CPU.
Types Included: Includes both RAM and ROM.
What are I/O Devices?
Input/Output Communication: Allows communication between the computer and the outside world.
Examples: Keyboard, mouse, monitor, printer.
What is the data bus?
Carries Data: Transmits actual data between CPU and other components.
Bidirectional: Data can flow both to and from the CPU.
Width (Number of Lines): Determines how much data can be transferred at once (e.g., 8-bit, 16-bit, 32-bit, 64-bit).
What is the address bus?
Carries Addresses: Transmits the addresses of memory locations where data should be read or written.
Unidirectional: Typically only sends addresses from the CPU to memory or I/O devices.
Width: Determines the maximum amount of memory the CPU can address.
What is the control bus?
Carries Control Signals: Sends control instructions (like read or write signals) from the CPU to other components.
What is the ALU?
Arithmetic Logic Unit: Performs all arithmetic and logical operations (addition, subtraction, AND, OR, NOT).
What is Pipelining?
Overlapping Phases:
While one instruction is being executed, the next instruction is fetched simultaneously.
Division of CPU: Divides the CPU into the Execution Unit (EU) and Bus Interface Unit (BIU).
What is the bus interface unit?
Function:
1. Fetches instructions from memory.
2. Reads/writes data.
3. Calculates addresses.
Instruction Queue: A buffer that stores prefetched instructions so the EU doesn’t have to wait.
What is the Execution Unit (EU)?
Function: Executes instructions provided by the Bus Interface Unit (BIU).
What are registers?
High-Speed Storage: Small storage locations within the CPU that operate at high speeds.
Usage: Hold data, addresses, and control information temporarily during instruction execution.
What are the 5 register categories?
General-Purpose Registers
Segment Registers
Pointer and Index Registers
Instruction Pointer (IP)
Flags Register
What are the general-purpose registers?
Versatile Usage: Used for arithmetic operations, data manipulation, and addressing.
Access: Each can be accessed as a 16-bit register or as two separate 8-bit registers.
Ax (Accumulator Register)
Bx (Base Register)
Cx (Count Register)
Dx (Data Register)
What does the Ax (Accumulator Register) do?
Usage: Preferred for arithmetic, logic, and data transfer operations.
What does the Bx (Base Register) do?
Usage: Often holds base addresses in memory addressing.
Utility: Useful in indexed addressing modes.
What does the Cx (Count Register) do?
Usage:
1.) Primarily used as a loop counter in iterative operations.
2.) Used in shift and rotate instructions to specify the number of bits to shift/rotate.
What does the Dx (Data Register) do?
Usage:
1.) Used in I/O operations.
2.) Utilized for extended precision arithmetic.
What are the segment registers?
Function: Hold the addresses of segments in memory.
Memory Model: The 8088/8086 uses a segmented memory model, dividing memory into segments of up to 64 KB.
CS (Code Segment Register)
DS (Data Segment Register)
SS (Stack Segment Register)
ES (Extra Segment Register)
What does the CS (Code Segment Register) do?
Usage: Points to the segment containing the current program instructions.
What does the DS (Data Segment Register) do?
Usage: Points to the segment where data variables are stored.
What does the SS (Stack Segment Register) do?
Usage: Points to the segment containing the stack.
What does the ES (Extra Segment Register) do?
Usage: Provides an additional data segment for certain string and memory operations.
What are the Pointer and Index Registers?
Function: Used for memory addressing and manipulating data within memory segments.
Pointer Registers:
SP (Stack Pointer)
BP (Base Pointer)
Index Registers:
SI (Source Index Register)
DI (Destination Index Register)
What does the SP (Stack Pointer) register do?
Function:
1.) Automatically adjusted during stack operations.
2.) Points to the last value pushed onto the stack (top of stack).
What does the BP (Base Pointer) register do?
Usage: Often used to access parameters and local variables within the stack.
What does the SI (Source Index Register) do?
Usage: Used in string operations as the source pointer.
What does the DI (Destination Index Register) do?
Usage: Used in string operations as the destination pointer.
What is the Instruction Pointer (IP) Register?
Function: Holds the offset address (within the code segment) of the next instruction to be executed. Automatically updated after each instruction fetch.
Usage: The combination of CS (segment) and IP (offset) gives the complete address of the instruction.
What is the Flags Register?
Description: A 16-bit register that indicates the status of the CPU and the outcome of arithmetic and logical operations.
Flags Included:
Carry Flag (CF)
Zero Flag (ZF)
Sign Flag (SF)
Overflow Flag (OF)
Parity Flag (PF)
Auxiliary Carry Flag (AF)
What is the Carry Flag (CF)?
Condition: Set if an arithmetic operation generates a carry out of the most significant bit (for addition) or borrow into the most significant bit (for subtraction).
Usage: Used to detect unsigned arithmetic overflows.
What is the Zero Flag (ZF)?
Condition: Set if the result of an operation is zero.
Usage: Often used in branching instructions or loops.
What is the Sign Flag (SF)?
Description: Reflects the most significant bit of the result (the sign bit).
Condition: Set if the result is negative (in two’s complement representation).
What is the Overflow Flag (OF)?
Condition: Set if there is a signed overflow.
Usage: Used to detect errors in signed arithmetic operations.
What is the Parity Flag (PF)?
Condition: Set if the number of set bits in the least significant byte of the result is even.
Usage: Used for error detection in communication.
What is the Auxiliary Carry Flag (AF)?
Condition: Set if there is a carry or borrow between the lower and upper nibble (4-bit halves) of an 8-bit operand.
Usage: Important for Binary-Coded Decimal (BCD) arithmetic operations.
What are the three components of an assembly language instruction?
Mnemonic: A symbolic name representing a machine language instruction.
Operands: Data items that the instruction manipulates.
Comments: Provide explanations or annotations.
What is the Code Segment?
Storage: Stores the executable instructions of a program.
CPU Interaction: The CPU fetches instructions from the code segment during execution.
Registers Involved: CS (Code Segment Register), IP (Instruction Pointer)
What is the Data Segment?
Storage: Stores data to be processed by the program.
Registers Used: DS (Data Segment Register)
Offset Registers:
1.) Base Register (BX)
2.) Source Index (SI)
3.) Destination Index (DI)
What is the Stack Segment?
Definition: A stack is a region of memory used for temporary storage of data during program execution.
Purpose: Provides additional storage space for the CPU beyond its internal registers, which are limited in number.
Registers Involved:
1.) SS (Stack Segment Register)
2.) SP (Stack Pointer Register)
3.) BP (Base Pointer Register)
What is the physical address?
Definition: The actual address placed on the address bus by the CPU.
What is the logical address?
Composition: Consists of a segment value and an offset value.
Format: Segment:Offset
What is the offset address?
Definition: Specifies the distance from the beginning of the segment
What is BIOS?
Functions:
1.) Initializes hardware during the boot process.
2.) Provides low-level hardware control routines.
Access: Programs and DOS can access BIOS routines via interrupts.
What is DOS (Disk Operating System)?
Functions:
1.) Manages files, memory, and devices by loading programs into RAM.
2.) Provides a layer between application programs and hardware.
How does the stack grow in memory?
Direction: Downwards, from higher to lower memory addresses.
What is a push operation?
Function: Saves data onto the stack.
Process:
1.) Decrement SP by the size of the data.
2.) Store the data at the memory location pointed to by SS:SP.
What is a Pop Operation?
Function: Retrieves data from the stack.
Process:
1.) Load data from the memory location pointed to by SS:SP.
2.) Increment SP by the size of the data.
What is Register Addressing Mode?
Definition: Both the source and destination operands are registers within the CPU.
Example: movw %dx, %bx
What is Immediate Addressing Mode?
Definition: The operand is a constant value.
Example: movw $0x2550, %ax
What is Direct Addressing Mode?
Definition: The operand resides in memory, and its offset address is specified directly within the instruction.
Example: movb 0x2400, %dl
What is Register Indirect Addressing Mode?
Definition: The operand’s memory address is held in a register.
Example: movb (%bx), %al
What is Based Relative Addressing Mode?
Definition: Combines a base register with a displacement to calculate the effective address.
Base Registers: %bx and %bp.
Example: movw 10(%bx), %cx
What is Indexed Relative Addressing Mode?
Definition: Uses an index register with a displacement to calculate the effective address.
Index Registers: %si and %di.
Example: movw 5(%si), %dx
What is Based Indexed Relative Addressing Mode?
Definition: Combines a base register, an index register, and a displacement to calculate the effective address.
Base Registers: %bx and %bp
Index Registers: %si and %di
Example: movb 8(%bx,%di), %cl
What are procedures?
Definition: Blocks of code designed to perform specific tasks.
Defining a Procedure:
1.) Start: Label the beginning of the procedure.
2.) End: Place a return instruction at the end (e.g., ret).
What is the Main Entry Point?
Unix-like Systems: _start is used as the entry point.
What is a near jump/call?
Definition: A jump/call when the target address is within the same code segment.
Effect: Only the Instruction Pointer (IP) register is updated.
What are FAR Jumps and Calls?
Definition: Used when the target address is in a different code segment.
Effect: Both the Code Segment (CS) and Instruction Pointer (IP) registers are updated.
What is a JE / JZ (Jump if Equal / Jump if Zero) jump?
Description: Jumps to label if the zero flag is set, indicating equality.
What is a JNE / JNZ (Jump if Not Equal / Jump if Not Zero) jump?
Description: Jumps to label if the zero flag is not set, indicating inequality.
What is a JG / JNLE (Jump if Greater / Jump if Not Less or Equal) jump?
Description: Jumps if the first operand is greater than the second (signed).
What is a JL / JNGE (Jump if Less / Jump if Not Greater or Equal) jump?
Description: Jumps if the first operand is less than the second (signed).
What is a JGE / JNL (Jump if Greater or Equal / Jump if Not Less) jump?
Description: Jumps if the first operand is greater than or equal to the second (signed).
What is a JLE / JNG (Jump if Less or Equal / Jump if Not Greater) jump?
Description: Jumps if the first operand is less than or equal to the second (signed).
What is a JA / JNBE (Jump if Above / Jump if Not Below or Equal) jump?
Description: Jumps if the first operand is greater than the second (unsigned).
What is a JB / JNAE (Jump if Below / Jump if Not Above or Equal) jump?
Description: Jumps if the first operand is less than the second (unsigned).
What is a JAE / JNB (Jump if Above or Equal / Jump if Not Below) jump?
Description: Jumps if the first operand is greater than or equal to the second (unsigned).
What is a JBE / JNA (Jump if Below or Equal / Jump if Not Above) jump?
Description: Jumps if the first operand is less than or equal to the second (unsigned).
What is a JC (Jump if Carry) jump?
Description: Jumps if the carry flag is set.
What is a JNC (Jump if No Carry) jump?
Description: Jumps if the carry flag is not set.
What is a JO (Jump if Overflow) jump?
Description: Jumps if the overflow flag is set.
What is a JNO (Jump if No Overflow) jump?
Description: Jumps if the overflow flag is not set.
What is a JS (Jump if Sign) jump?
Description: Jumps if the sign flag is set (negative result).
What is a JNS (Jump if Not Sign) jump?
Description: Jumps if the sign flag is not set (non-negative result).
What is a JP / JPE (Jump if Parity / Jump if Parity Even) jump?
Description: Jumps if the parity flag is set (even parity).
What is a JNP / JPO (Jump if Not Parity / Jump if Parity Odd) jump?
Description: Jumps if the parity flag is not set (odd parity).
What are all conditional jumps?
Description: Short jumps based on the evaluation of condition flags.
What are call instructions?
Function: Used to invoke subroutines or procedures within your program.
Behavior: Similar to jumps but have additional functionality to enable returning to the point of origin after the subroutine completes.
What is a near call?
Syntax: call label
Usage: When calling a procedure within the same code segment.
Return Mechanism: Only the IP is pushed onto the stack.
RET Instruction: The subroutine should end with a ret instruction to pop the return address back into the IP.
What is a far call?
Syntax: call far label or call far ptr label
Usage: When calling a procedure in a different code segment.
Return Mechanism: Both the CS and IP are pushed onto the stack.
RET Instruction: The subroutine should end with a lret (far return) instruction to pop both CS and IP from the stack.
How to add individual bytes or words while maintaining Carry?
Steps:
1.) Use an 8-bit register (e.g., %al) to accumulate the sum of bytes.
2.) Use another 8-bit register (e.g., %ah) to accumulate any carries.
3.) After each addition, check the Carry Flag (CF); if it’s set, increment the carry register.
How to add multiple words while maintaining Carry?
Steps:
1.) Break down the numbers into lower and higher words or bytes.
2.) Clear the Carry Flag using the clc instruction before starting.
3.) Use ADD for the least significant chunk (LSB).
4.) Use ADC for subsequent chunks to include the carry from the previous addition.
How does the x86 processor perform subtraction?
Steps:
1.) Invert all bits of the subtrahend (creating the 1’s complement).
2.) Add 1 to get the 2’s complement.
3.) Add the 2’s complement of the subtrahend to the minuend.
4.) Invert the Carry Flag (CF) after the operation.
How to perform Byte × Byte Multiplication?
Operands:
1.) Multiplicand: Must be in the %al register.
2.) Multiplier: Can be a register or memory operand.
Result:
The product is stored in the %ax register.
How to perform Word × Word Multiplication?
Operands:
1.) Multiplicand: Must be in the %ax register.
2.) Multiplier: Can be a register or memory operand.
Result:
1.) The 32-bit product is stored across %dx:%ax.
2.) %ax: Lower 16 bits of the result.
3.) %dx: Higher 16 bits of the result.
How to perform Byte × Word Multiplication?
Operands:
1.) Multiplicand: Must be in the %al register (byte).
2.) Multiplier: Can be a word in a register or memory.
Preparation:
1.) %ah must be zeroed before the multiplication to correctly interpret %al as a word-sized value.
Result:
1.)The product is stored in %dx:%ax.
How to perform Byte ÷ Byte Division?
Numerator:
— Must be in the %ax register, with %ah cleared to zero.
Divisor:
— Can be a register or memory operand.
Result:
— Quotient: Stored in %al.
— Remainder: Stored in %ah.
How to perform Word ÷ Word Division?
Numerator:
— Must be in the %dx:%ax register pair.
— %dx must be cleared to zero if the numerator fits in %ax.
Divisor:
— Can be a register or memory operand.
Result:
— Quotient: Stored in %ax.
— Remainder: Stored in %dx.
How to perform Word ÷ Byte Division?
Numerator:
— Must be in the %ax register.
Divisor:
— Can be a register or memory operand (byte-sized).
Result:
— Quotient: Stored in %al.
— Remainder: Stored in %ah.
How to perform Doubleword ÷ Word Division?
Numerator:
— Must be in the %dx:%ax register pair.
— %dx: High word of the numerator.
—- %ax: Low word of the numerator.
Divisor:
— Must be a word-sized register or memory operand.
Result:
— Quotient: Stored in %ax.
— Remainder: Stored in %dx.
What is the AND instruction?
Function: Performs a bitwise logical AND operation between two operands.
Syntax: AND destination, source ; destination = destination AND source
Usage:
— Masking Bits: Clearing specific bits in a register or memory location.
What is the OR instruction?
Function: Performs a bitwise logical OR operation between two operands.
Syntax: OR destination, source ; destination = destination OR source
Usage:
— Setting Bits: Forces specific bits to be 1.
What is the XOR instruction?
Function: Performs a bitwise exclusive OR (XOR) operation between two operands.
Syntax: XOR destination, source ; destination = destination XOR source
Usage:
— Clearing Registers: XORing a register with itself results in zero.
— Bit Toggling: Flips specific bits in a register or memory location.
What is the shift instruction?
Function: Moves bits left or right within a register or memory location.
Types of Logical Shifts:
— Shift Left Logical (SHL): Shifts bits to the left.
— Shift Right Logical (SHR): Shifts bits to the right.
What is the CMP Instruction?
Function: Compares two operands by performing a subtraction of the source operand from the destination operand (without storing the result).
Usage:
— Commonly used prior to conditional jumps.
— Sets up conditions for subsequent instructions.
Syntax: CMP destination, source ; Compare destination with source
What is unpacked BCD?
Definition: Each decimal digit is stored in the lower four bits of a byte.
Upper Bits: The upper four bits are typically set to zero.
What is packed BCD?
Definition: Two decimal digits are stored within a single byte.
Bit Allocation:
— Higher Four Bits: Contain one digit.
— Lower Four Bits: Contain another digit.
What about ASCII numbers?
Definition: upper four bits set to 0011.
How to convert from ASCII to unpacked BCD?
Steps:
1.) Mask the Upper Four Bits: Perform a bitwise AND with 0x0F to clear the upper four bits.
2.) Result: The lower four bits remain, representing the BCD value.
How to convert from ASCII to packed BCD?
Steps:
1) Convert ASCII to Unpacked BCD:
Mask the upper four bits by performing a bitwise AND with 0x0F to clear the upper four bits.
2.) Combine Two Unpacked BCD Digits into One Byte:
Shift the higher-order digit left by 4 bits.
Combine it with the lower-order digit using a bitwise OR.
How to convert from packed BCD to ASCII?
Steps:
1.) Separate the Two BCD Digits:
Extract the upper nibble (higher-order digit) by shifting right by 4 bits.
Extract the lower nibble (lower-order digit) by masking with 0x0F.
2.) Convert Unpacked BCD to ASCII:
Add 0x30 to each unpacked BCD digit.
How to convert from packed BCD to ASCII?
Steps:
1.) Separate the Two BCD Digits:
Extract the upper nibble (higher-order digit) by shifting right by 4 bits.
Extract the lower nibble (lower-order digit) by masking with 0x0F.
2.) Convert Unpacked BCD to ASCII:
Add 0x30 to each unpacked BCD digit.
How does Decimal Adjust After Addition work?
Steps:
1.) Lower Nibble Adjustment:
If the lower nibble (bits 0-3) is greater than 9 or the Auxiliary Flag (AF) is set, DAA adds 0x06 to the lower nibble.
2.) Upper Nibble Adjustment:
If the upper nibble (bits 4-7) is greater than 9 or the Carry Flag (CF) is set, DAA adds 0x60 to adjust the upper nibble.