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 PortalCOMP3137Assembly Language
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
    6 min read
    Topic 2 of 73
    Topic Study Note Illustration
    02

    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...

    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 view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    6mremaining
    1.1kwords
    Intermediatelevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Computer Organization and Assembly Language