0% found this document useful (0 votes)
135 views4 pages

Unit-5 Notes (C.o.a)

Uploaded by

Sita Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
135 views4 pages

Unit-5 Notes (C.o.a)

Uploaded by

Sita Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

MAHARISHI UNIVERSITY OF

INFORMATION TECHNOLOGY

DIGITAL NOTES
[Department of Computer Application]

Subject : C.O.A
Name
Subject : BCA-302
Code
Course : BCA
Branch :
Semester : 3RD
Prepared by :

SESSION 2024-25
Assembly Language and Programming
1. Assembly Language
• Definition: Assembly language is a low-level programming language that is closely
related to machine language. It uses symbolic representations of a computer's machine
code instructions, making it easier to program than binary code.
• Characteristics:
o Machine-Dependent: Each assembly language is specific to a particular
computer architecture (e.g., x86, ARM).
o Mnemonic Codes: Uses mnemonics to represent instructions (e.g., MOV, ADD,
SUB).
o Direct Control: Provides direct control over hardware and memory, allowing for
efficient programming.
• Structure: An assembly language program consists of instructions, which can be
classified as data, directives, and executable instructions.

2. Assembler
• Definition: An assembler is a program that converts assembly language code into
machine code that the CPU can execute.
• Types of Assemblers:
o One-Pass Assembler: Scans the source code once to generate machine code.
This type may require forward references to be handled specially.
o Two-Pass Assembler: Scans the source code twice; the first pass collects labels
and symbols, while the second pass generates the machine code using this
information.
• Functions of an Assembler:
o Translation: Converts assembly language instructions to machine code.
o Symbol Resolution: Maps symbolic labels to memory addresses.
o Error Detection: Identifies syntax errors in the assembly code.
3. Assembly Level Instructions
• Types of Instructions:
o Data Movement Instructions: Transfer data between registers and memory
(e.g., MOV, PUSH, POP).
o Arithmetic Instructions: Perform arithmetic operations (e.g., ADD, SUB, MUL,
DIV).
o Logical Instructions: Perform bitwise operations (e.g., AND, OR, XOR, NOT).
o Control Flow Instructions: Alter the flow of execution (e.g., JMP, CALL, RET,
NOP).
Example Instructions:
• MOV: Moves data from one location to another.
o Syntax: MOV destination, source
• ADD: Adds two operands.
o Syntax: ADD destination, source
• JMP: Jumps to a specified address unconditionally.
o Syntax: JMP label
4. Macros
• Definition: A macro is a sequence of instructions that can be defined once and used
multiple times within an assembly program.
• Purpose of Macros:
o Code Reusability: Enables the reuse of code blocks, reducing redundancy.
o Abstraction: Simplifies complex operations by encapsulating them in a single
instruction.
• Macro Definitions:
o A macro is defined using a specific syntax, usually starting with a keyword like
MACRO and ending with ENDM.
Example:
assembly
Copy code
SUM MACRO a, b
MOV AX, a
ADD AX, b
ENDM
• Usage:
o To use a macro, simply call its name with the required parameters:
assembly
Copy code
SUM 5, 10
5. Use of Macros in I/O Instructions
• I/O Operations: Macros can simplify the coding of I/O operations by abstracting the
repetitive code needed for setting up device control registers or handling interrupts.
• Example:
assembly
Copy code
PRINT MACRO msg
MOV DX, OFFSET msg
MOV AH, 09h
INT 21h
ENDM
• Invocation:
assembly
Copy code
PRINT "Hello, World!"
6. Program Loops
• Definition: A loop is a programming structure that repeats a block of code multiple times
until a certain condition is met.
• Types of Loops:
o Unconditional Loops: Continue indefinitely until externally interrupted (e.g.,
JMP).
o Conditional Loops: Execute based on a condition (e.g., LOOP, JZ, JNZ).
Example of a Loop:
assembly
Copy code
MOV CX, 10 ; Set loop counter to 10
START_LOOP:
; Code to execute
DEC CX ; Decrement counter
JNZ START_LOOP ; Repeat until CX is zero
7. Arithmetic and Logic Subroutines
• Subroutine Definition: A subroutine is a block of code that performs a specific task and
can be called from multiple points in a program.
• Purpose: Facilitates code organization, reuse, and modularity.
• Call and Return:
o Use CALL to invoke a subroutine and RET to return to the calling code.
Example of a Subroutine:
assembly
Copy code
SUM_SUBROUTINE PROC
ADD AX, BX
RET
SUM_SUBROUTINE ENDP

; Calling the subroutine


CALL SUM_SUBROUTINE
8. Input/Output Programming
• I/O Operations: In assembly language, interacting with hardware for input/output
typically involves using specific instructions or invoking system calls.
• Accessing I/O Ports: Direct access to hardware I/O ports may involve using IN and
OUT instructions.
Example of Input/Output:
assembly
Copy code
; Reading a byte from port 60h (keyboard)
IN AL, 60h

; Sending a byte to port 3F8h (COM1)


OUT 3F8h, AL
• Using Interrupts for I/O: Many systems use interrupts for I/O operations, allowing the
CPU to perform other tasks while waiting for I/O operations to complete.
o Example: Using DOS interrupt INT 21h for file handling or printing to the screen.
9. Conclusion
Assembly language programming allows for low-level control over hardware, making it essential
for performance-critical applications. Understanding the assembler's role, instruction types, the
use of macros, and the implementation of loops and subroutines is crucial for effective
programming. Input/output operations are fundamental for interacting with the external
environment, and mastering these concepts enhances a programmer's ability to work closely
with computer architecture.

You might also like