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›Assembly Language
    Computer Organization and Assembly LanguageTopic 2 of 73

    Assembly Language

    6 minread
    1,103words
    Intermediatelevel

    Assembly Language

    Assembly Language is a low-level programming language that is very close to machine code but is easier for humans to read and write. It serves as an intermediary between high-level programming languages (like Python or Java) and the binary code (machine code) that the CPU actually understands and executes.

    Let's break it down into manageable parts:


    1. What is Assembly Language?

    Assembly language consists of a set of human-readable instructions that correspond directly to machine code instructions. Each assembly language instruction typically represents a single operation, like adding two numbers, moving data between registers, or jumping to another part of the program.

    Unlike high-level programming languages, which are more abstract and user-friendly, assembly language is specific to a given type of CPU architecture (like Intel x86 or ARM). This means that assembly language programs are often not portable between different systems. A program written for one type of CPU will need to be rewritten (or at least modified) to work on another.


    2. Why Use Assembly Language?

    • Performance: Assembly language allows the programmer to write highly efficient code that can directly control the hardware, leading to faster execution of critical tasks.

    • Control: It gives the programmer more control over the hardware. For example, you can manipulate memory locations directly and use special CPU features.

    • Low-Level Access: Assembly is often used for programming embedded systems, operating system kernels, device drivers, or other system-level software where precise control over hardware is necessary.


    3. Basic Components of Assembly Language

    • Mnemonics: These are symbolic names for machine-level instructions. For example:

      • MOV: Move data from one place to another (e.g., a register or memory location).
      • ADD: Add two numbers together.
      • SUB: Subtract one number from another.
      • JMP: Jump to another instruction (used for loops or conditional execution).
      • NOP: No operation (it does nothing, often used for timing or debugging).
    • Registers: These are small, fast storage locations inside the CPU. Assembly language allows you to specify operations on registers. For example, on x86 CPUs, you might use registers like AX, BX, CX, etc.

    • Labels: Labels are identifiers used to mark a specific point in the code. They are often used for jump instructions. For example:

      START:
          MOV AX, 5   ; Move 5 into register AX
          ADD AX, 10  ; Add 10 to AX
          JMP START   ; Jump back to the START label (this would create an infinite loop)
      
    • Operands: These are the values that instructions operate on. In the instruction MOV AX, 5, the operands are AX (the register) and 5 (the immediate value).

    • Comments: Comments are non-executable lines in assembly code that are used to explain what the code does. In most assembly languages, comments start with a semicolon (;).


    4. Examples of Assembly Language Instructions

    Here are a few simple examples to help you understand how assembly language works.

    Example 1: Moving Data Between Registers

    MOV AX, 5    ; Move the value 5 into the AX register
    MOV BX, 10   ; Move the value 10 into the BX register
    

    In this example, we are putting the values 5 and 10 into the registers AX and BX, respectively.

    Example 2: Adding Two Numbers

    MOV AX, 5    ; Move 5 into register AX
    MOV BX, 10   ; Move 10 into register BX
    ADD AX, BX   ; Add the value in BX (10) to AX (5), so AX = 15
    

    This code will add the values in AX and BX and store the result in AX.

    Example 3: Conditional Jump

    MOV AX, 5
    MOV BX, 10
    CMP AX, BX   ; Compare AX with BX
    JL LessThan   ; Jump to the "LessThan" label if AX < BX
    
    MOV CX, 1    ; This would execute only if AX >= BX
    
    LessThan:
    MOV CX, 0    ; This would execute if AX < BX
    

    In this example, the program compares the values in AX and BX. If AX is less than BX, it jumps to the LessThan label.


    5. Basic Structure of Assembly Language Programs

    An assembly program generally follows a basic structure:

    1. Data Section: This is where you define variables and constants.

      • Example: msg db 'Hello, World!', 0
    2. Code Section: This is where you write the actual instructions that the CPU will execute.

    3. End Section: Marks the end of the program. In many assemblers, you’ll use a special directive (e.g., END in x86) to indicate the program’s end.


    6. Assembly Language vs. Machine Code

    • Machine Code: This is the binary code that the CPU directly executes. Each instruction is represented as a sequence of binary digits (0s and 1s).

    • Assembly Language: This is a human-readable representation of machine code. Assembly uses mnemonics, making it easier to write and understand, but still corresponds closely to the machine code instructions.

    For example, an instruction in machine code might look like this:

    10110000 00000101
    

    In assembly, the same instruction might look like this:

    MOV AL, 5
    

    In this example, the MOV AL, 5 instruction tells the computer to move the value 5 into the AL register, which is part of the CPU. The binary sequence 10110000 00000101 is the corresponding machine code that the CPU actually executes.


    7. Advantages and Disadvantages of Assembly Language

    Advantages:

    • Efficiency: You have more control over how the program interacts with the hardware, which can lead to highly optimized code.
    • Speed: For certain tasks, assembly language programs can run faster than programs written in high-level languages because they are more direct.
    • Low-Level Access: It allows programmers to work with system resources and hardware directly, useful for writing system software like operating systems and drivers.

    Disadvantages:

    • Complexity: Writing in assembly is more difficult and time-consuming than using high-level languages like Python, Java, or C.
    • Portability: Programs written in assembly are often tied to specific hardware (architecture), meaning you can't easily run them on different types of processors.
    • Maintenance: Assembly code is harder to maintain, debug, and understand, especially as the program grows in size.

    Summary:

    Assembly language is a low-level programming language that provides a direct interface between software and hardware. It allows you to write programs that can run very efficiently and give you full control over the CPU's operations. However, because it is specific to a given type of CPU and is more difficult to write and maintain than high-level languages, it's typically used only in situations where performance or hardware control is critical, such as embedded systems or operating systems.

    In simpler terms, assembly language is like a detailed map of how the CPU works, and while it gives you a lot of control, it's not the easiest way to write code.

    Previous topic 1
    Introduction to Computer Organization
    Next topic 3
    Comparison of Low-Level and High-Level Languages

    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 time6 min
      Word count1,103
      Code examples0
      DifficultyIntermediate