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 Machine Langu…
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 10 of 73
    Topic Study Note Illustration
    10

    Assembly and Machine Language

    In computer architecture, both assembly language and machine language are low-level programming languages used to directly control the hardware of a computer. These two languages are closely...

    Assembly Language and Machine Language

    In computer architecture, both assembly language and machine language are low-level programming languages used to directly control the hardware of a computer. These two languages are closely related, but they differ in terms of human readability and their relationship to machine operations.


    1. Machine Language

    Machine language is the lowest-level programming language, consisting entirely of binary code (0s and 1s). This is the language that a computer’s CPU understands and executes directly. Every CPU has its own specific machine language (also called machine code or binary code), which is tailored to the architecture of the processor.

    Key Characteristics:

    • Binary Format: Machine language instructions are written in binary (strings of 0s and 1s), corresponding to the CPU's instruction set architecture (ISA).
    • Directly Executed: Machine language instructions are directly executed by the CPU without the need for a compiler or interpreter.
    • Architecture-Specific: Each type of CPU has its own machine language format and set of instructions. For example, an Intel x86 processor uses a different machine language than an ARM processor.
    • No Human Readability: Machine code is not human-readable because it consists of long binary strings that correspond to specific operations, memory addresses, and values.

    Example:

    Here’s a simplified example of what machine language might look like for an operation like adding two numbers:

    • Instruction in Machine Language (hypothetical for an x86-like CPU):
      10111011 00000001 00000000 00000000
      
      This binary string could represent an instruction such as:
      • Opcode: 10111011 (a code that tells the CPU to perform an addition)
      • Operands: 00000001 00000000 00000000 (these could represent memory addresses or registers involved in the operation).

    2. Assembly Language

    Assembly language is a low-level programming language that is human-readable and closely tied to machine language. Assembly language uses mnemonic codes (short, symbolic names) to represent machine-level instructions, making it easier for humans to write and understand programs compared to binary machine code.

    Assembly language instructions directly correspond to machine language instructions for a specific CPU architecture. Each instruction in assembly corresponds to a binary code that the CPU will interpret and execute.

    Key Characteristics:

    • Mnemonics: Assembly language uses mnemonic codes (e.g., ADD, MOV, SUB) to represent operations. These mnemonics make the code more readable and understandable than binary machine code.
    • Architecture-Specific: Just like machine language, assembly language is specific to the architecture of the CPU. An x86 assembly program won’t run on an ARM processor without modification because the assembly languages for the two are different.
    • Requires an Assembler: To execute assembly language code, it must be translated into machine language using a program called an assembler. The assembler converts the human-readable assembly code into binary instructions that the CPU can execute.
    • Low-Level Control: Assembly language allows the programmer to control the computer hardware at a very granular level, such as directly manipulating memory addresses, registers, and performing bitwise operations.

    Example:

    The following assembly language code might represent an instruction to add two numbers in x86 assembly language:

    MOV AX, 5     ; Move the value 5 into register AX
    MOV BX, 10    ; Move the value 10 into register BX
    ADD AX, BX    ; Add the value in BX to AX (AX = AX + BX)
    
    • MOV: A mnemonic for the instruction that moves data between registers.
    • ADD: A mnemonic for the instruction that adds two values.
    • AX and BX: These are general-purpose registers in the x86 architecture.

    When the assembler translates this code into machine language, it might produce something like:

    MOV AX, 5     → 10111000 00000101
    MOV BX, 10    → 10111011 00001010
    ADD AX, BX    → 00000001 11000011
    

    Each mnemonic corresponds to a specific binary machine code that the CPU understands.


    Comparison: Machine Language vs. Assembly Language

    Aspect Machine Language Assembly Language
    Level Lowest-level, directly executed by the CPU. Low-level, human-readable code that corresponds to machine code.
    Representation Binary (0s and 1s). Mnemonics (e.g., MOV, ADD, SUB).
    Readability Not human-readable (composed of binary digits). Human-readable, but closely tied to machine operations.
    Execution Directly executed by the CPU without translation. Requires an assembler to convert into machine code.
    Portability CPU-specific; machine code differs for each architecture. Architecture-specific; assembly code differs for each CPU type.
    Control Allows the CPU to perform operations. Allows precise control over the CPU, memory, and hardware.

    From Assembly to Machine Language: The Process

    1. Write the Assembly Code: The programmer writes a program using assembly language, making use of mnemonics and registers that correspond to the target CPU architecture.

    2. Assemble the Code: The assembly code is then passed through an assembler, a program that translates the human-readable assembly code into machine code (binary code).

    3. Linking (if needed): If the program uses external libraries or calls to other functions, the assembler might generate object code. A linker then combines these object files into an executable program.

    4. Execution: The machine code is loaded into memory, and the CPU executes it.


    Why Use Assembly Language?

    • Efficiency: Assembly language gives the programmer fine-grained control over the hardware, making it possible to write highly optimized and efficient programs. It’s useful for situations where performance is critical, such as embedded systems or device drivers.

    • Access to Hardware: Assembly allows programmers to directly control hardware resources like memory and input/output devices, making it useful for low-level programming.

    • Learning Tool: Learning assembly language can help developers understand how computers work at the hardware level, as it provides insights into how the CPU processes instructions and manages memory.


    Limitations of Assembly Language

    • Complexity: Writing in assembly language is more complex and time-consuming than using higher-level programming languages like C or Python. The programmer must manage low-level details manually (e.g., register management, memory allocation).

    • Lack of Portability: Assembly language is specific to a given CPU architecture. An assembly program written for one processor (e.g., x86) will not run on a different architecture (e.g., ARM) without modification.

    • Maintenance: Programs written in assembly are harder to maintain and debug compared to those written in high-level languages. As programs grow in size, managing them in assembly becomes increasingly difficult.


    Example: Machine Code, Assembly, and Higher-Level Code

    Let’s take a look at a simple example where we add two numbers.

    In a High-Level Language (C):

    int main() {
        int a = 5, b = 10, result;
        result = a + b;
        return 0;
    }
    

    In Assembly (x86):

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

    In Machine Language:

    The assembly instructions would be translated into binary (hypothetical):

    MOV AX, 5     → 10111000 00000101
    MOV BX, 10    → 10111011 00001010
    ADD AX, BX    → 00000001 11000011
    

    Summary

    • Machine language is the lowest level of code, composed entirely of binary instructions that the CPU executes directly. It is not human-readable.
    • Assembly language is a symbolic, human-readable representation of machine language. It uses mnemonics to represent machine instructions, making it easier to write and understand than raw binary.
    • While assembly language allows programmers more control over the hardware, it is specific to a given processor architecture, and programs written in assembly are generally harder to maintain and port than higher-level languages.

    Both machine language and assembly language provide critical insights into how computers function at the hardware level, though they are often used in specific situations where performance, control, or hardware interaction is paramount.

    ← Previous topic 9
    Instruction Execution Cycle
    Next topic 11 →
    Assembler

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

    No headings found

    Study Toolkit

    Subject Portal

    Computer Organization and Assembly Language