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

    Assembly and Machine Language

    7 minread
    1,255words
    Intermediatelevel

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

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