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 PortalDC-221Control
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    DC-221

    Computer Organization and Assembly Language

    Progress0 / 35 done
    Topics35
    1Introduction to Computer Systems2Information is Bits + Context3Programs are Translated by Other Programs4Understanding Compilation Systems5Processors Read and Interpret Instructions6Caches Matter7Storage Devices Form a Hierarchy8The Operating System Manages the Hardware9Systems Communicate Using Networks10Representing and Manipulating Information11Information Storage12Integer Representations13Integer Arithmetic14Floating Point15Machine-Level Representation of Programs16A Historical Perspective17Program Encodings18Data Formats19Accessing Information20Arithmetic and Logical Operations21Control22Procedures23Array Allocation and Access24Heterogeneous Data Structures25Understanding Pointers26Using the GDB Debugger27Out-of-Bounds Memory References and Buffer Overflow
    28Extending IA-32 to 64 Bits29Machine-Level Representations of Floating-Point Programs30Processor Architecture31The Y86 Instruction Set Architecture32Logic Design and the Hardware Control Language (HCL)33Sequential Y86 Implementations34General Principles of Pipelining35Pipelined Y86 Implementations
    7 min read
    Topic 21 of 35
    Topic Study Note Illustration
    21

    Control

    In computer organization, control refers to the mechanism by which the CPU (Central Processing Unit) manages the execution of instructions, coordinates different parts of the system, and...

    In computer organization, control refers to the mechanism by which the CPU (Central Processing Unit) manages the execution of instructions, coordinates different parts of the system, and ensures that tasks are carried out in the correct sequence. The control unit, a part of the CPU, plays a key role in managing the flow of data and instructions.

    1. Control Unit (CU)

    The Control Unit (CU) is responsible for directing the operations of the CPU by generating control signals. It orchestrates the execution of instructions by interpreting the machine code and signaling the various components of the computer (such as ALU, memory, and I/O devices) to perform the required tasks.

    Central processing unit
    Visual ReferenceCentral Processing Unit
    Wikipedia

    Main Functions of the Control Unit:

    • Instruction Fetching: The CU fetches instructions from memory.
    • Instruction Decoding: It decodes the instruction to determine what action needs to be performed.
    • Control Signal Generation: It generates control signals to coordinate the execution of instructions.
    • Execution Sequencing: It manages the sequence of execution for different instructions.

    The CU can be categorized into two types:

    • Hardwired Control Unit: Uses fixed logic circuits to produce control signals. It’s fast but inflexible.
    • Microprogrammed Control Unit: Uses a set of instructions (micro-operations) stored in memory to produce control signals. It is slower but more flexible and easier to modify.

    2. Control Flow in Computers

    Control flow refers to the order in which individual instructions are executed in a program. In assembly language, control flow allows the program to make decisions, repeat actions, and jump to different sections based on conditions.

    Types of Control Flow:

    1. Sequential Execution:
      In a simple program, instructions are executed one after the other in sequence.

      • Example:
        MOV AX, 5   ; Move 5 into AX register
        MOV BX, 10  ; Move 10 into BX register
        ADD AX, BX  ; Add AX and BX, result in AX
        

      Here, the instructions are executed one after the other.

    2. Conditional Branching:
      Conditional branching allows the program to make decisions. Based on a comparison of values (using conditional flags), the program can jump to a different instruction.

      • Example:
        CMP AX, BX   ; Compare AX and BX
        JE Label     ; Jump to Label if Equal (Zero flag set)
        MOV CX, 20   ; This line will be skipped if AX = BX
        

      In this example, the program compares the values of AX and BX, and if they are equal, it jumps to the label Label to skip the instruction that moves 20 into CX.

    3. Unconditional Branching (Jump):
      An unconditional jump allows the program to jump to a specific part of the program without any conditions.

      • Example:
        JMP Label     ; Jump to Label unconditionally
        MOV CX, 30    ; This line will be skipped
        
    4. Loops (Repetition):
      Loops allow the program to repeat a set of instructions until a certain condition is met. Loops are controlled using conditional and unconditional jumps.

      • Example:
        MOV CX, 0    ; Initialize counter
        LoopStart:
        INC CX       ; Increment CX
        CMP CX, 10   ; Compare CX with 10
        JL LoopStart ; Jump back to LoopStart if CX < 10
        

      This program uses a loop to increment the value of CX from 0 to 10.

    5. Function Calls:
      Function calls allow a program to call a subroutine (function), execute it, and then return to the point where the call was made. This is managed by a call stack.

      • Example:
        CALL MyFunction    ; Call a subroutine
        MOV AX, 100        ; This line is executed after returning from MyFunction
        

      A function call typically involves saving the return address (where to continue after the function call) on the stack, executing the function, and then returning to the saved address when the function is done.

    3. Control Instructions in Assembly Language

    Control instructions in assembly language are used to manipulate the flow of execution. These instructions include jump operations, loops, and condition checks.

    Types of Control Instructions:

    • Jump Instructions (Unconditional):

      • JMP (Jump): Causes the program to jump to a specified label, causing a change in the flow of execution.
        • Example:
          JMP LoopStart   ; Unconditionally jump to LoopStart
          
    • Conditional Jump Instructions: Conditional jumps depend on the status of flags set after a comparison operation.

      • JE (Jump if Equal): Jump if the Zero flag is set (i.e., the two values compared were equal).

        • Example:
          CMP AX, BX  ; Compare AX and BX
          JE EqualLabel ; Jump if AX equals BX
          
      • JNE (Jump if Not Equal): Jump if the Zero flag is not set (i.e., the values compared were not equal).

        • Example:
          CMP AX, BX  ; Compare AX and BX
          JNE NotEqualLabel ; Jump if AX is not equal to BX
          
      • JG (Jump if Greater): Jump if the result of a comparison shows that the first value is greater.

        • Example:
          CMP AX, BX   ; Compare AX and BX
          JG GreaterLabel ; Jump if AX > BX
          
      • JL (Jump if Less): Jump if the result of a comparison shows that the first value is less.

        • Example:
          CMP AX, BX   ; Compare AX and BX
          JL LessLabel   ; Jump if AX < BX
          
    • Loop Instructions:

      • LOOP: This instruction decrements the counter and jumps to the label if the counter is not zero.
        • Example:
          MOV CX, 5  ; Set loop counter
          LoopStart:
          ; Loop body
          LOOP LoopStart  ; Decrement CX and loop back to LoopStart
          
    • CALL and RET (Function Call and Return):

      • CALL: This instruction pushes the return address onto the stack and jumps to the function.

        • Example:
          CALL MyFunction   ; Call the function
          
      • RET: The RET instruction pops the return address from the stack and jumps back to that address.

        • Example:
          RET  ; Return from the function
          

    4. Control Flags

    The control flags are special flags in the CPU that help manage the control flow based on the results of arithmetic and logical operations. These flags are set or cleared based on the outcome of instructions like compare (CMP) and test (TEST).

    • Zero Flag (ZF): Set if the result of an operation is zero. It is commonly used in conditional jumps like JE (Jump if Equal).

    • Carry Flag (CF): Set if there is a carry out or borrow in an arithmetic operation (for unsigned numbers). It is used in conditional jumps like JC (Jump if Carry).

    • Sign Flag (SF): Set if the result is negative (for signed numbers).

    • Overflow Flag (OF): Set if there is an overflow in an arithmetic operation for signed numbers (i.e., the result cannot be represented within the available bits).

    • Parity Flag (PF): Set if the number of 1s in the result is even (used for error detection).

    5. Control in Multitasking and Operating Systems

    In modern computers, control also involves managing multiple tasks or processes at the same time. The operating system's scheduler uses control instructions to switch between processes in multitasking environments. Key mechanisms include:

    • Context Switching: The process of saving the state of a running process and loading the state of the next process to be executed.

    • Interrupts: Interrupts allow the CPU to be temporarily diverted from its current task to handle a more urgent task (like input/output). Once the interrupt is handled, control returns to the interrupted task.

    Conclusion

    The control unit and control flow mechanisms are crucial in ensuring that a computer follows the correct sequence of instructions and responds to conditions during execution. Control instructions in assembly language, such as jumps, loops, and function calls, provide the flexibility to implement decision-making and repetitive tasks in programs. Additionally, control flags help in managing the outcomes of operations, and modern systems use control techniques like multitasking and interrupts to handle multiple processes efficiently.

    ← Previous topic 20
    Arithmetic and Logical Operations
    Next topic 22 →
    Procedures

    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