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 PortalCOMP3137Register Types General…
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 4 of 73
    Topic Study Note Illustration
    04

    Register Types (16-bit): General Purpose and Special Purpose Registers

    In a 16-bit CPU architecture , registers are used as small, fast storage locations within the Central Processing Unit (CPU) . These registers are used to hold...

    Register Types (16-bit): General Purpose and Special Purpose Registers

    In a 16-bit CPU architecture, registers are used as small, fast storage locations within the Central Processing Unit (CPU). These registers are used to hold data and addresses that are needed for computation, storing intermediate results, or controlling program flow. Registers are critical to the performance of a processor because they are much faster than memory, allowing for quick data manipulation.

    In a 16-bit system, each register typically holds 16 bits of data (or 2 bytes). There are two main types of registers: General Purpose Registers (GPRs) and Special Purpose Registers (SPRs). Let’s go over both of these in more detail:


    1. General Purpose Registers (GPRs)

    General Purpose Registers (GPRs) are used for temporary data storage during calculations or manipulation. These registers can hold intermediate results of arithmetic or logical operations, data from memory, or values to be passed between different parts of a program.

    Characteristics of General Purpose Registers:

    • Flexible Use: These registers are not dedicated to any specific function, so the programmer can use them as needed for various tasks.
    • Fast Access: They are directly accessible by the CPU and are used in nearly every instruction, which makes them essential for fast computations.
    • Can Be Read and Written to: GPRs can be read from and written to multiple times during program execution.

    Examples of General Purpose Registers in a 16-bit Architecture:

    Let’s consider a 16-bit x86 architecture for an example. The registers are named as follows:

    • AX (Accumulator Register): The AX register is commonly used for arithmetic operations. It is often used to store the result of operations like addition, subtraction, multiplication, and division.
    • BX (Base Register): BX is typically used as a base pointer for memory addressing. It can also store data.
    • CX (Count Register): CX is often used as a counter in loops and string operations. It's used for shift/rotate operations and counting iterations in loops.
    • DX (Data Register): DX is used for storing the second part of large data or intermediate results in multi-word operations. It is often used in multiplication or division operations, particularly when dealing with larger numbers.

    Each of these 16-bit registers can hold a 16-bit value (ranging from 0 to 65535 if unsigned, or -32768 to 32767 if signed).

    Here’s an example of how they might be used in assembly:

    MOV AX, 5      ; Move 5 into AX register
    MOV BX, 10     ; Move 10 into BX register
    ADD AX, BX     ; Add BX to AX; AX = AX + BX = 5 + 10 = 15
    

    In this example:

    • AX and BX are used as general-purpose registers to store data and perform an addition operation.

    Other General Purpose Registers (for 16-bit processors):

    • SP (Stack Pointer): While often considered a special-purpose register, the Stack Pointer (SP) can also be used as a general-purpose register in some cases, especially in stack operations.
    • BP (Base Pointer): BP is used to point to the base of the stack frame in function calls but can be used as a general-purpose register in some contexts.

    In some 16-bit systems, there might be more general-purpose registers, but the four above (AX, BX, CX, DX) are the most common in the x86 architecture.


    2. Special Purpose Registers (SPRs)

    Special Purpose Registers (SPRs) are registers that have a specific, dedicated function within the CPU. They are used for control purposes, managing program flow, and supporting system-level tasks.

    Key Special Purpose Registers:

    1. Program Counter (PC):

      • Function: The Program Counter (PC), also known as the Instruction Pointer (IP) in some systems, keeps track of the address of the next instruction to be executed.
      • Role in Execution: The PC points to the current instruction in memory. After each instruction is fetched, it automatically increments (or changes, depending on jumps or branches) to point to the next instruction.
      • Example: If the PC is at address 0x1000, the CPU will fetch and execute the instruction at that address. Afterward, the PC will increment (e.g., PC = PC + 1).
    2. Stack Pointer (SP):

      • Function: The Stack Pointer (SP) holds the address of the top of the stack. The stack is a section of memory used for storing temporary data, such as function parameters, return addresses, and local variables.
      • Role in Execution: It is used to manage function calls and local storage in a program. Each time a function is called, the return address and possibly some local variables are pushed onto the stack, and the SP is adjusted accordingly.
      • Example: When a function call occurs, the return address is pushed to the stack, and the SP is adjusted. After the function finishes, the SP is adjusted again to pop the return address back into the program counter (PC) to resume execution.
    3. Base Pointer (BP):

      • Function: The Base Pointer (BP) is used to point to the base of the stack frame in function calls, which helps manage local variables and arguments.
      • Role in Execution: The BP is used to reference local variables and arguments in the stack. This register typically stays constant for the duration of a function call, even if the stack pointer changes.
      • Example: In a function call, the BP typically points to the base of the stack frame, and the SP moves as local variables are pushed and popped.
    4. Flags Register (Status Register or Condition Code Register):

      • Function: The Flags Register (or Status Register) holds flags that indicate the results of operations (such as comparisons, arithmetic operations, etc.).
      • Role in Execution: The flags are used to store information like whether an operation resulted in zero (Zero flag), whether there was an overflow (Overflow flag), or if a number was negative (Negative flag).
      • Flags typically include:
        • Zero Flag (ZF): Set if the result of an operation is zero.
        • Carry Flag (CF): Set if there is a carry out of the most significant bit (in addition) or if there is a borrow (in subtraction).
        • Sign Flag (SF): Set if the result is negative (for signed operations).
        • Overflow Flag (OF): Set if an overflow occurs during an operation.
      • Example: After an addition, you may check the Carry Flag (CF) to determine if there was a carry out, which is important in multi-precision arithmetic.
    5. Instruction Register (IR):

      • Function: The Instruction Register (IR) holds the instruction that is currently being executed by the CPU.
      • Role in Execution: After the instruction is fetched from memory, it is loaded into the IR before being decoded and executed by the CPU.

    Summary: General Purpose vs. Special Purpose Registers

    Feature General Purpose Registers (GPRs) Special Purpose Registers (SPRs)
    Purpose Used for temporary data storage and computation Used for controlling execution and managing program flow
    Examples AX, BX, CX, DX, SP, BP PC (Program Counter), SP (Stack Pointer), BP (Base Pointer), Flags Register
    Flexibility Flexible; can be used for any purpose Fixed purpose; used for specific control tasks
    Role in Execution Holds data to be processed or moved Helps in controlling the flow of execution and managing system states
    Access Read and write as needed by the program Read and write based on the program flow (e.g., SP is updated during function calls)

    Conclusion

    In a 16-bit processor architecture, general-purpose registers are used for everyday data manipulation, while special-purpose registers handle more critical tasks such as managing the program flow, controlling execution, and interacting with memory. Both types of registers are essential for a processor's operation, but they serve very different roles in the CPU's architecture and performance.

    ← Previous topic 3
    Comparison of Low-Level and High-Level Languages
    Next topic 5 →
    Introduction and Usage of RAM

    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.2kwords
    Intermediatelevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Computer Organization and Assembly Language