ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Computer Organization and Assembly Language
    COMP3137
    Progress0 / 73 topics
    Topics
    1. Introduction to Computer Organization2. Assembly Language3. Comparison of Low-Level and High-Level Languages4. Register Types (16-bit): General Purpose and Special Purpose Registers5. Introduction and Usage of RAM6. Processor7. Registers8. System Bus9. Instruction Execution Cycle10. Assembly and Machine Language11. Assembler12. Linker and Link Libraries13. Programmer's View of a Computer System14. RISC and CISC Architecture15. Physical Address Calculation16. Basic Memory Organization17. CPU Organization18. Top Level View of Computer Function and Interconnection19. Assembler Instruction Cycle20. Execute Cycle21. Interrupts22. Interrupt Cycle23. Memory Connection24. Input/Output Connection25. CPU Connection26. MASM27. MIPS28. Defining Data in MASM Assembler29. Elements of Assembly Language30. Integer Constants31. Integer Expressions32. Real Number Constants33. Character Constants34. String Constants35. Reserved Words36. Identifiers37. Directives38. Instructions39. The NOP (No Operation) Instruction40. Adding and Subtracting Integer41. INC and DEC Instructions42. NEG Instruction43. How to Move Integer Number in Register44. Adding and Subtracting Numbers in Registers45. Declaration and Initialization of Variables46. Moving Data from Variable to Register47. Data Definition Statement48. BYTE and SBYTE Data49. WORD and SWORD Data50. Defining DWORD and SDWORD Data51. Knowledge about Different Data Types52. Operations, Array & Loops53. Division and Multiplication in Assembly54. Jumps Based on Specific Flags55. Jumps Based on Equality56. Simple Jump Statements57. Jumps Based on Specific Condition58. Code Examples59. Practice on MASM60. Procedures61. File Operations Procedures62. Labels in Procedures63. Stack64. Runtime Stack65. Conditional Control Flow Directives66. Compound Expressions67. Data Representation & Conversion68. Architecture69. Data Path70. Control Unit71. Critical Path72. General Principles of Pipelining73. Pipelined Y86 Implementations
    COMP3137›Register Types (16-bit): General Purpose and Special Purpose Registers
    Computer Organization and Assembly LanguageTopic 4 of 73

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

    7 minread
    1,241words
    Intermediatelevel

    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 load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time7 min
      Word count1,241
      Code examples0
      DifficultyIntermediate