COM 323 ACTIVITY_1
COM 323 ACTIVITY_1
Task 1
2. Write a simple Hello World program using any high level language and assembly language.
print("Hello, World!")
1
Title: Introduction to Assembly Programming
Task 2
The EMU8086 assembler environment is specifically designed for programming and simulating applications
for the 8086 microprocessor. This environment provides an integrated development environment (IDE) that
facilitates the writing, debugging, and execution of assembly language programs. Below are the key features
and properties of the EMU8086 assembler environment:
1. Compatibility:
o EMU8086 is compatible with Windows operating systems, allowing it to run on most
modern PCs.
2. Small Memory Footprint:
2
o The environment is lightweight, requiring minimal system resources, making it accessible
even on older machines.
3. User-Friendly Interface:
o The interface is intuitive, making it easy for beginners to navigate and start programming
without extensive prior knowledge.
4. Customizable Settings:
o Users can customize the editor settings, such as font size and color schemes, to suit their
preferences.
5. Real-Time Execution:
o The emulator executes programs in real time, allowing users to see the results of their code
immediately.
6. Rich Documentation:
o EMU8086 comes with extensive documentation and help files that provide guidance on
using the assembler and understanding assembly language concepts.
1. Download EMU8086
3. Install EMU8086
4. Launch EMU8086
2. Open EMU8086:
o Double-click the EMU8086 icon to launch the program.
5. Using EMU8086
Title: A program to display all the 26 English alphabets on the screen, in uppercase form
Task 3
1. Write any interactive program that request for input from the user, accepts input and give an output.
4
Title: Display of 256 ASCII characters
Task 4
1. Write a program that will display output on the screen. (Numeric Output)
Task 5
5
Title: Displaying letter G on the Screen
Task 6
Task 7
In immediate addressing mode, the operand is specified explicitly within the instruction itself rather than
being stored in a register or memory location. This means that the instruction contains the actual value to be
used.
6
2. Direct Addressing Mode
Definition: In direct addressing mode, the operand's address is specified directly in the instruction. The
instruction points to a specific memory location where the operand is stored.
2. Arithmetic Instructions
o ADD: Adds two operands.
Syntax: ADD destination, source
Example: ADD AX, 5 (adds 5 to the value in AX).
o SUB: Subtracts one operand from another.
Syntax: SUB destination, source
Example: SUB AX, BX (subtracts BX from AX).
o MUL: Multiplies unsigned integers.
Syntax: MUL operand
Example: MUL BX (multiplies AX by BX, result in DX:AX).
3. Logical Instructions
o AND: Performs a bitwise AND operation.
Syntax: AND destination, source
Example: AND AX, 0FFh (performs a bitwise AND between AX and 0FFh).
o OR: Performs a bitwise OR operation.
Syntax: OR destination, source
Example: OR AL, 1 (sets the least significant bit of AL).
o XOR: Performs a bitwise XOR operation.
Syntax: XOR destination, source
Example: XOR AX, AX (clears the register AX).
7
5. Comparison Instructions
o CMP: Compares two operands.
Syntax: CMP operand1, operand2
Example: CMP AX, BX (compares AX and BX).
o TEST: Performs a bitwise AND and sets flags.
Syntax: TEST operand1, operand2
Example: TEST AX, 1 (tests if the least significant bit of AX is set).
Common Registers
1. General-Purpose Registers
o AX: Accumulator register; used for arithmetic operations.
o BX: Base register; often used for addressing data in memory.
o CX: Count register; commonly used for loop counters and string operations.
o DX: Data register; used in arithmetic operations and I/O operations.
2. Segment Registers
o CS: Code Segment; points to the segment containing the executable code.
o DS: Data Segment; points to the segment containing data variables.
o SS: Stack Segment; points to the segment containing the stack.
o ES: Extra Segment; often used for string operations.
3. Pointer Registers
o SP: Stack Pointer; points to the top of the stack.
o BP: Base Pointer; points to the base of the stack frame for the current procedure.
4. Index Registers
o SI: Source Index; used for string operations.
o DI: Destination Index; also used for string operations and data movement.
5. Instruction Pointer
o IP: Instruction Pointer; points to the next instruction to be executed.
6. Flags Register
o FLAGS: Contains status flags that indicate the outcome of operations (like zero, carry,
overflow, and sign flags).
Task 8
1. Identify the similarities and the differences observed between the two program control flow.
Similarities
1. Execution Control:
o Both branching and looping mechanisms control the flow of execution, determining which
set of instructions will be executed based on certain conditions.
2. Use of Conditions:
o Both structures often rely on conditions to determine their path. For example, branching can
depend on a specific condition (like zero or non-zero), while looping often continues until a
condition is met.
8
4. Use of Jumps:
o Both control flow types utilize jump instructions (like JMP, JE, JNE, etc.) to navigate
through code. This is foundational in assembly language for directing program flow.
Differences
1. Purpose:
o Branching: Typically used for making decisions (e.g., if-else statements) where the
program executes different code paths based on certain conditions.
o Looping: Used to repeat a block of instructions multiple times until a specific condition is
satisfied (like for-loops or while-loops).
2. Execution Frequency:
o Branching: Executes once per decision point and moves to a different part of the code
based on the outcome.
o Looping: May execute multiple times, repeatedly running the same block of instructions
until the termination condition is met.
3. Structure:
o Branching: Usually involves a single conditional check followed by multiple possible
outcomes. It may lead to different sections of code based on the condition.
o Looping: Involves an entry condition (to start the loop) and an exit condition (to terminate
the loop), and generally has a structure that allows for repeated execution of the same code
block.
4. Example Instructions:
o Branching: Instructions like JE (jump if equal), JNE (jump if not equal), and JG (jump if
greater) are typical for conditional branching.
o Looping: Instructions like LOOP, JCXZ (jump if CX register is zero), or using a
combination of CMP and JMP for creating loops.
Task 9
Display Output:
Accept Input:
9
o Usage: Set AH to 0Ah, DX to the buffer address, and call INT 21h. The first byte in the
buffer is the maximum string length.
File Operations:
Program Termination:
Memory Allocation:
Use: Reads a single character from the keyboard and displays it on the screen.
Registers:
o Set AH to 01h.
o The character entered is returned in AL.
Example:
asm
Copy code
mov ah, 01h ; Set function to read character with echo
int 21h ; Call DOS interrupt
; The character is now in AL
asm
Copy code
mov ah, 02h ; Set function to display character
mov dl, 'A' ; Character to display
int 21h ; Call DOS interrupt
10
Use: Displays a string of characters on the screen, terminated by a $ character.
Registers:
o Set AH to 09h.
o Load DX with the address of the string.
Example:
asm
Copy code
mov ah, 09h ; Set function to display string
lea dx, message ; Load address of the message
int 21h ; Call DOS interrupt
Use: Accepts a string input from the user and stores it in a buffer.
Registers:
o Set AH to 0Ah.
o Load DX with the address of the buffer (the first byte indicates the maximum length).
Example:
asm
Copy code
mov ah, 0Ah ; Set function to input string
lea dx, buffer ; Load address of the buffer
int 21h ; Call DOS interrupt
Use: Ends the program and returns control to the operating system.
Registers:
o Set AH to 4Ch.
o Optionally set AL to an exit code.
Example:
asm
Copy code
mov ah, 4Ch ; Set function to terminate program
mov al, 00h ; Exit code (optional)
int 21h ; Call DOS interrupt
Task 10
1. Write a program to accept a positive number and display it using library of common functions.
11
Title: Interrupt
Task 11
1. What are interrupt? Interrupt is a mechanism that allows the CPU to pause its current execution
and respond to an external or internal event, like input/output requests, hardware failures, or
software requests. Interrupts enable the system to handle asynchronous events effectively and
prioritize certain tasks over others.
b. What are they used for in assembly language?
Interrupts provide a way for programs to request services from the operating system. For example, in
DOS assembly language, the INT 21h interrupt gives access to a range of functions, such as reading
from or writing to files, handling input/output, and more.
Hardware interrupts allow the CPU to respond to events from external devices, like keyboards,
timers, and network interfaces. When a key is pressed, a keyboard interrupt (like INT 09h in x86)
allows the CPU to momentarily pause other tasks, read the keypress, and store it for the program to
use.
Interrupts are used to handle critical errors or exceptions, such as division by zero, invalid memory
access, or illegal instructions. When the CPU encounters such issues, it automatically invokes an
interrupt to run an error-handling routine.
Rather than constantly polling (checking) if a device needs attention, a program can wait for an
interrupt, reducing CPU load. For example, if a program is waiting for a network packet, it can
continue with other tasks and get interrupted only when data arrives, making it efficient and
responsive.
In operating systems that support multitasking, interrupts allow for task switching by periodically
saving the state of one task and loading another. Timer interrupts (like INT 08h in x86 systems)
allow the OS to manage task scheduling.
12
In real-time systems, interrupts ensure the CPU can react immediately to time-sensitive events. An
interrupt-driven response is vital in applications like embedded systems (e.g., controllers for
industrial machines, medical devices).
2. List 5 interrupt that can be flagged in assembly language & their functions
i. INT 10h - Video Services
ii. INT 13h - Disk Services
iii. INT 16h - Keyboard Services
iv. INT 17h - Printer Services
v. INT 21h - DOS Services
13