ScholarQuill logoScholarQuillUniversity Notes
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
Study Tools
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
Contact
ScholarQuill logo
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
ScholarQuill logoScholarQuillUniversity Notes
Study PortalCOMP3137Registers
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    COMP3137

    Computer Organization and Assembly Language

    Progress0 / 73 done
    Topics73
    1Introduction to Computer Organization2Assembly Language3Comparison of Low-Level and High-Level Languages
    4General Purpose and Special Purpose Registers5Introduction and Usage of RAM6Processor7Registers8System Bus9Instruction Execution Cycle10Assembly and Machine Language11Assembler12Linker and Link Libraries13Programmer's View of a Computer System14RISC and CISC Architecture15Physical Address Calculation16Basic Memory Organization17CPU Organization18Top Level View of Computer Function and Interconnection19Assembler Instruction Cycle20Execute Cycle21Interrupts22Interrupt Cycle23Memory Connection24Input/Output Connection25CPU Connection26MASM27MIPS28Defining Data in MASM Assembler29Elements of Assembly Language30Integer Constants31Integer Expressions32Real Number Constants33Character Constants34String Constants35Reserved Words36Identifiers37Directives38Instructions39The NOP (No Operation) Instruction40Adding and Subtracting Integer41INC and DEC Instructions42NEG Instruction43How to Move Integer Number in Register44Adding and Subtracting Numbers in Registers45Declaration and Initialization of Variables46Moving Data from Variable to Register47Data Definition Statement48BYTE and SBYTE Data49WORD and SWORD Data50Defining DWORD and SDWORD Data51Knowledge about Different Data Types52Operations, Array & Loops53Division and Multiplication in Assembly54Jumps Based on Specific Flags55Jumps Based on Equality56Simple Jump Statements57Jumps Based on Specific Condition58Code Examples59Practice on MASM60Procedures61File Operations Procedures62Labels in Procedures63Stack64Runtime Stack65Conditional Control Flow Directives66Compound Expressions67Data Representation & Conversion68Architecture69Data Path70Control Unit71Critical Path72General Principles of Pipelining73Pipelined Y86 Implementations
    7 min read
    Topic 7 of 73
    Topic Study Note Illustration
    07

    Registers

    In computer systems, registers are small, fast storage locations within the CPU (Central Processing Unit) that are used to hold data temporarily during program execution. Unlike main...

    Registers in Computer Architecture

    In computer systems, registers are small, fast storage locations within the CPU (Central Processing Unit) that are used to hold data temporarily during program execution. Unlike main memory (RAM), which is slower and larger, registers provide immediate access to data and instructions that the CPU is actively processing, making them essential for high-speed computation.

    Registers are at the core of a CPU’s ability to execute instructions quickly. They allow the processor to store intermediate results, hold data for calculations, and manage addresses for memory access.


    Types of Registers

    Registers can be broadly categorized into general-purpose registers and special-purpose registers. Each type of register plays a unique role in managing data and controlling the execution of a program.


    1. General Purpose Registers (GPRs)

    General-purpose registers (GPRs) are the registers that the CPU can use for a wide range of tasks. These registers are used to temporarily store data, variables, or intermediate results of calculations.

    Key Characteristics:

    • Flexibility: GPRs are not assigned to any specific function, meaning the programmer or the operating system can use them as needed for different operations.
    • Storage: They hold operands for arithmetic or logical operations, data being processed, and memory addresses.
    • Number: The number of GPRs can vary depending on the architecture. For example, x86 processors typically have 8 or 16 general-purpose registers, while more modern architectures (like x86-64 or ARM processors) have a larger number.

    Common GPRs:

    • AX (Accumulator): Often used to store the result of arithmetic and logical operations.
    • BX (Base Register): Used for indexing and addressing memory.
    • CX (Count Register): Primarily used for counting operations (e.g., loops or shifts).
    • DX (Data Register): Used for holding data during operations, especially when larger values need to be processed.
    • SP (Stack Pointer): Points to the top of the stack (a special area in memory for temporary storage).
    • BP (Base Pointer): Used to point to the base of the current stack frame, particularly in function calls.
    • SI (Source Index) and DI (Destination Index): Used for string and memory operations in some architectures.
    • IP (Instruction Pointer): Points to the address of the next instruction to be executed (in some architectures, this is also called the Program Counter).

    Example (in x86 Assembly):

    MOV AX, 10      ; Move the value 10 into the AX register
    MOV BX, 20      ; Move the value 20 into the BX register
    ADD AX, BX      ; Add the value in BX to AX (AX = 10 + 20 = 30)
    

    In this example:

    • AX and BX are general-purpose registers.
    • The ADD instruction performs the addition and stores the result back in AX.

    2. Special Purpose Registers (SPRs)

    Special-purpose registers have specific, predefined roles that are crucial for controlling the CPU’s operation and managing tasks such as memory addressing, program flow, and status monitoring. These registers are not used for general data storage but instead play a vital role in the functioning of the CPU.

    Key Special Purpose Registers:

    1. Program Counter (PC) (also called Instruction Pointer (IP) in some architectures):

      • Function: The Program Counter keeps track of the address of the next instruction to be executed.
      • Behavior: After each instruction is fetched, the PC is incremented (or modified if there's a jump or branch).
      • Example: If the PC holds the address 0x1000, the CPU will fetch and execute the instruction located at memory address 0x1000. Afterward, the PC will point to the next instruction (e.g., 0x1002).
    2. Stack Pointer (SP):

      • Function: The Stack Pointer points to the top of the stack in memory, which is used for function calls, local variables, and storing return addresses.
      • Behavior: It automatically changes as data is pushed to or popped from the stack.
      • Example: In function calls, the return address is pushed onto the stack, and the SP moves downward (or upward, depending on the architecture).
    3. Base Pointer (BP) (also called Frame Pointer):

      • Function: The Base Pointer is used to point to the base of the current stack frame. This is helpful for referencing local variables and function arguments.
      • Behavior: It remains fixed during function execution, allowing easy access to local variables and arguments, even if the SP changes.
      • Example: When a function is called, the BP points to the base of the function’s stack frame, and the SP moves as local variables are pushed onto the stack.
    4. Flags Register (Status Register):

      • Function: The Flags Register holds status flags that indicate the outcome of various operations (e.g., arithmetic, logical). These flags help the CPU decide what action to take next.

      • Flags include:

        • Zero Flag (ZF): Set if the result of an operation is zero.
        • Carry Flag (CF): Set if there was a carry out during an addition or a borrow during subtraction.
        • Sign Flag (SF): Set if the result is negative (for signed operations).
        • Overflow Flag (OF): Set if an arithmetic overflow occurs.
        • Parity Flag (PF): Set if the number of 1-bits in the result is even.
      • Example: After performing an addition, if the result is zero, the ZF will be set.

    5. Instruction Register (IR):

      • Function: The Instruction Register holds the instruction that is currently being executed by the CPU. The instruction is fetched from memory into the IR before decoding and execution.
      • Example: If the next instruction is MOV AX, BX, it will be fetched from memory into the IR before being executed.

    3. Other Specialized Registers

    Some processors include additional specialized registers for specific tasks:

    1. Memory Address Register (MAR):

      • Holds the address in memory where data is to be read from or written to.
    2. Memory Buffer Register (MBR) (or Memory Data Register (MDR)):

      • Holds the data that is being transferred to or from the memory location specified by the MAR.
    3. Control Registers:

      • These are used for managing various processor control features (e.g., enabling interrupts, managing execution modes, etc.).

    Why Are Registers Important?

    1. Speed: Registers are located inside the CPU and are much faster than memory (RAM). Since registers can be accessed in a single CPU cycle, they play a vital role in speeding up program execution.

    2. Data Manipulation: Registers hold the data that is being worked on by the CPU. Whether performing arithmetic operations, logic operations, or handling data transfers, registers are involved in almost every operation.

    3. Efficient Program Execution: Special-purpose registers, such as the Program Counter and Stack Pointer, are critical for managing the flow of program execution, such as looping, branching, and function calls.

    4. Memory Access: Registers like the MAR and MBR control how data is read from or written to memory, providing a bridge between the CPU and the main memory.


    Summary of Register Types

    Register Type Function Example
    General Purpose Registers Hold temporary data for processing operations AX, BX, CX, DX
    Special Purpose Registers Control and manage the execution flow of the CPU PC (Program Counter), SP (Stack Pointer), BP (Base Pointer)
    Flags Register Holds status flags indicating the results of operations Zero Flag, Carry Flag, Overflow Flag
    Control Registers Manage system operations, such as interrupt handling Control registers for interrupt management

    Conclusion

    Registers are a core part of the CPU, providing fast, temporary storage for data during computation. There are general-purpose registers used for storing intermediate data and special-purpose registers used to control and track the flow of program execution. The speed and efficiency of registers allow the processor to execute instructions at a high rate, making them critical for the overall performance of a computer system.

    ← Previous topic 6
    Processor
    Next topic 8 →
    System Bus

    Past Papers

    Open this section to view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    7mremaining
    1.3kwords
    Intermediatelevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Computer Organization and Assembly Language