0% found this document useful (0 votes)
8 views39 pages

Assembly Language Programming Experiments

This report outlines ten experiments that implement basic programming concepts using Assembly Language with Turbo Assembler (TASM) on an 8086 microprocessor. The experiments cover various topics such as input/output operations, arithmetic computations, and algorithmic logic, providing a hands-on understanding of low-level programming techniques. The report emphasizes the educational value of assembly language in computer science and includes detailed methodologies, results, and analyses for each experiment.

Uploaded by

emon.bu.cse.8
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)
8 views39 pages

Assembly Language Programming Experiments

This report outlines ten experiments that implement basic programming concepts using Assembly Language with Turbo Assembler (TASM) on an 8086 microprocessor. The experiments cover various topics such as input/output operations, arithmetic computations, and algorithmic logic, providing a hands-on understanding of low-level programming techniques. The report emphasizes the educational value of assembly language in computer science and includes detailed methodologies, results, and analyses for each experiment.

Uploaded by

emon.bu.cse.8
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

Implementation of Basic Programming

Concepts in Assembly Language (TASM)


Submitted by: [Your Name]​
Department of Computer Science and Engineering​
[Your Institution Name]​
Date: May 16, 2025

Abstract
This report documents a series of ten experiments designed to implement fundamental
programming concepts using Assembly Language with Turbo Assembler (TASM) on an 8086
microprocessor environment. The experiments cover input/output operations, arithmetic
computations, conditional logic, iterative algorithms, and mathematical series generation.
Each experiment includes objectives, theoretical background, program code, execution
procedures, outputs, results, and analysis, providing a comprehensive understanding of
low-level programming techniques. The use of TASM and DOSBox facilitated the
development and testing of these programs, reinforcing the significance of assembly
language in microprocessor interfacing and system-level programming. The report highlights
challenges, learning outcomes, and the importance of assembly language in computer
science education.

Table of Contents
1.​ Introduction
2.​ Apparatus and Software Requirements
3.​ Experiment Details​
3.1 Experiment 1: Printing "Hello World!" and Swapping Two Numbers​
3.2 Experiment 2: Arithmetic Operations​
3.3 Experiment 3: Even or Odd Number Detection​
3.4 Experiment 4: Leap Year Detection​
3.5 Experiment 5: Area Calculation (Rectangle, Circle, Triangle)​
3.6 Experiment 6: Temperature Conversion​
3.7 Experiment 7: Finding Minimum or Maximum of Two Numbers​
3.8 Experiment 8: Factorial of a Number​
3.9 Experiment 9: Fibonacci Series Generation​
3.10 Experiment 10: Sum of Series 1+2+3+...+N
4.​ General Discussion
5.​ Conclusion
6.​ References
7.​ Appendices
1. Introduction
Assembly language programming is a cornerstone of computer science, offering direct
control over hardware resources and enabling the development of efficient,
performance-critical software. The Intel 8086 microprocessor, introduced in 1978, was a
pivotal technology that powered early personal computers and remains a valuable
educational tool for understanding low-level programming. This project aims to implement
fundamental programming concepts—such as string output, arithmetic operations,
conditional logic, loops, and mathematical computations—using TASM in an 8086
environment. The experiments progressively build upon each other, starting with basic I/O
operations and advancing to complex algorithms, providing hands-on experience with
instruction sets, register operations, and interrupt handling. This report details the
methodology, results, and insights gained from these experiments, emphasizing the
educational value of assembly language in computer science and engineering.

2. Apparatus and Software Requirements


2.1 Hardware

●​ Personal Computer with a modern processor capable of running DOSBox.


●​ Optional: 8086-based microcontroller kit for hardware-based experiments.

2.2 Software

●​ Turbo Assembler (TASM): Version 5.0, used for assembling 8086 assembly code.
●​ DOSBox Emulator: Version 0.74, used to run 16-bit assembly programs in a modern
operating system.
●​ Text Editor: Notepad or Visual Studio Code for writing assembly code.

2.3 Development Environment Setup

1.​ Install DOSBox from DOSBox Official Site.


2.​ Place TASM binaries in a directory (e.g., C:\TASM).
3.​ Mount the directory in DOSBox using mount c C:\TASM.
4.​ Navigate to the directory with C:.
5.​ Write assembly code in a text editor and save with a .asm extension.
6.​ Compile and run programs using TASM commands (see experiment procedures).

3. Experiment Details
Each experiment follows a structured format with objectives, theoretical background,
program code, execution steps, outputs, results, and analysis.

3.1 Experiment 1: Printing "Hello World!" and Swapping Two Numbers


3.1.1 Objective

●​ Display the string "Hello World!" on the console.


●​ Swap the values of two numbers stored in memory.

3.1.2 Theory

●​ String Output: In 8086 assembly, the DOS interrupt INT 21H, function 09H, prints a
dollar-terminated string to the console. The LEA (Load Effective Address) instruction
loads the string’s offset into the DX register.
●​ Swapping Numbers: Swapping involves exchanging values between registers or
memory locations. The simplest method uses a temporary register, while alternatives
like XOR operations avoid extra storage but are less intuitive.

3.1.3 Program Code

Program 1: Printing "Hello World!"

.model small
.stack 100h
.data
msg db 'Hello World!$'
.code
main:
mov ax, @data ; Initialize data segment
mov ds, ax
mov ah, 09h ; DOS function to print string
lea dx, msg ; Load address of string
int 21h ; Call DOS interrupt
mov ah, 4ch ; DOS function to exit
int 21h
end main

Program 2: Swapping Two Numbers

.model small
.stack 100h
.data
num1 db 05h ; First number
num2 db 0Ah ; Second number
.code
main:
mov ax, @data ; Initialize data segment
mov ds, ax
mov al, num1 ; Load num1 into AL
mov bl, num2 ; Load num2 into BL
mov cl, al ; Store AL in temporary register CL
mov al, bl ; Move BL to AL
mov bl, cl ; Move CL to BL
mov num1, al ; Store swapped value back to num1
mov num2, bl ; Store swapped value back to num2
mov ah, 4ch ; DOS function to exit
int 21h
end main

3.1.4 Procedure

1.​ Write the code in a text editor and save as [Link] or [Link].
2.​ Open DOSBox and mount the directory containing the file.
3.​ Assemble: tasm [Link] or tasm [Link].
4.​ Link: tlink [Link] or tlink [Link].
5.​ Run: [Link] or [Link].
6.​ Observe the output or verify memory contents using a debugger.

3.1.5 Output

●​ Program 1: Displays "Hello World!" on the console.


●​ Program 2: Internally swaps num1 (05h) and num2 (0Ah) in memory, verifiable via
debugger.

3.1.6 Result

Both programs executed successfully, demonstrating string output and data manipulation.

3.1.7 Analysis

The string output program relies on DOS interrupts, which are specific to the 8086
environment. The swapping program uses a temporary register, which is straightforward but
consumes an extra register. An alternative XOR-based swap could reduce register usage
but may be less readable for beginners.

3.2 Experiment 2: Arithmetic Operations

3.2.1 Objective

Perform addition, subtraction, multiplication, and division on two-digit numbers.

3.2.2 Theory

The 8086 instruction set includes:

●​ ADD: Adds two operands, storing the result in the destination.


●​ SUB: Subtracts the source from the destination.
●​ MUL: Multiplies two unsigned numbers, storing the result in AX.
●​ DIV: Divides AX by the operand, storing the quotient in AL and remainder in AH.
3.2.3 Program Code
.model small
.stack 100h
.data
num1 db 10 ; First number
num2 db 5 ; Second number
.code
main:
mov ax, @data ; Initialize data segment
mov ds, ax
mov al, num1
add al, num2 ; Addition: AL = 10 + 5
mov al, num1
sub al, num2 ; Subtraction: AL = 10 - 5
mov al, num1
mov bl, num2
mul bl ; Multiplication: AX = 10 * 5
mov ax, 10
mov bl, 2
div bl ; Division: AL = 10 / 2, AH = remainder
mov ah, 4ch ; DOS function to exit
int 21h
end main

3.2.4 Procedure

Follow the same steps as Experiment 1, saving the file as [Link].

3.2.5 Output

●​ Addition: AL = 15
●​ Subtraction: AL = 5
●​ Multiplication: AX = 50
●​ Division: AL = 5, AH = 0

3.2.6 Result

Arithmetic operations were successfully implemented, with results verified via register
inspection.

3.2.7 Analysis

The program handles 8-bit numbers, but larger numbers require 16-bit registers to avoid
overflow. The DIV instruction requires careful setup to ensure the dividend is in AX.

3.3 Experiment 3: Even or Odd Number Detection


3.3.1 Objective

Determine whether a number is even or odd.

3.3.2 Theory

A number is even if its least significant bit (LSB) is 0. The AND instruction with 01h isolates
the LSB, where a result of 0 indicates an even number.

3.3.3 Program Code


.model small
.stack 100h
.data
num db 7 ; Number to check
.code
main:
mov ax, @data ; Initialize data segment
mov ds, ax
mov al, num
and al, 01h ; Isolate LSB
mov ah, 4ch ; DOS function to exit
int 21h
end main

3.3.4 Procedure

Follow the same steps, saving as [Link].

3.3.5 Output

For num = 7, AL = 1 (odd). For num = 8, AL = 0 (even).

3.3.6 Result

The program correctly identified the parity of the input number.

3.3.7 Analysis

Bitwise operations are efficient for parity checks. Conditional jumps could be added to
display the result explicitly.

3.4 Experiment 4: Leap Year Detection

3.4.1 Objective

Check if a given year is a leap year.

3.4.2 Theory
A year is a leap year if divisible by 4 and not by 100, or divisible by 400. The DIV instruction
computes the remainder, checked via DX.

3.4.3 Program Code


.model small
.stack 100h
.data
year dw 2024 ; Year to check
.code
main:
mov ax, @data ; Initialize data segment
mov ds, ax
mov ax, year
mov dx, 0
mov cx, 4
div cx ; Divide year by 4
cmp dx, 0 ; Check if remainder is 0
jne not_leap
not_leap:
mov ah, 4ch ; DOS function to exit
int 21h
end main

3.4.4 Procedure

Save as [Link] and follow the same steps.

3.4.5 Output

For 2024, DX = 0 (leap year).

3.4.6 Result

The program correctly identified 2024 as a leap year.

3.4.7 Analysis

The program simplifies the leap year check by omitting century-year rules, which could be
added for completeness.

3.5 Experiment 5: Area Calculation (Rectangle, Circle, Triangle)

3.5.1 Objective

Calculate the area of a rectangle, circle, and triangle.

3.5.2 Theory
●​ Rectangle: Area = length × breadth
●​ Circle: Area = π × r² (π ≈ 3.14)
●​ Triangle: Area = 0.5 × base × height

3.5.3 Program Code (Rectangle)


.model small
.stack 100h
.data
length db 5 ; Length of rectangle
breadth db 4 ; Breadth of rectangle
.code
main:
mov ax, @data ; Initialize data segment
mov ds, ax
mov al, length
mov bl, breadth
mul bl ; Area in AX
mov ah, 4ch ; DOS function to exit
int 21h
end main

3.5.4 Procedure

Save as [Link] and follow the same steps.

3.5.5 Output

Area of rectangle (5 × 4 = 20) in AX.

3.5.6 Result

The program successfully computed the rectangle’s area.

3.5.7 Analysis

Circle and triangle calculations require floating-point approximations, which are complex in
8086 assembly due to integer-based arithmetic.

3.6 Experiment 6: Temperature Conversion

3.6.1 Objective

Convert temperature from Celsius to Fahrenheit.

3.6.2 Theory

°F = (°C × 9/5) + 32
3.6.3 Program Code
.model small
.stack 100h
.data
celsius db 25 ; Temperature in Celsius
.code
main:
mov ax, @data ; Initialize data segment
mov ds, ax
mov al, celsius
mov bl, 9
mul bl ; AL = Celsius * 9
mov bl, 5
div bl ; AL = (Celsius * 9) / 5
add al, 32 ; AL = Fahrenheit
mov ah, 4ch ; DOS function to exit
int 21h
end main

3.6.4 Procedure

Save as [Link] and follow the same steps.

3.6.5 Output

Converts 25°C to 77°F in AL.

3.6.6 Result

The conversion was accurate using integer arithmetic.

3.6.7 Analysis

Integer arithmetic limits precision, but the result is correct for whole numbers.

3.7 Experiment 7: Finding Minimum or Maximum of Two Numbers

3.7.1 Objective

Identify the maximum of two numbers.

3.7.2 Theory

The CMP instruction compares two values, and conditional jumps (JG, JL) determine the
relationship.

3.7.3 Program Code


.model small
.stack 100h
.data
num1 db 15 ; First number
num2 db 20 ; Second number
.code
main:
mov ax, @data ; Initialize data segment
mov ds, ax
mov al, num1
cmp al, num2 ; Compare num1 and num2
jg greater
mov al, num2 ; num2 is greater
jmp done
greater:
mov al, num1 ; num1 is greater
done:
mov ah, 4ch ; DOS function to exit
int 21h
end main

3.7.4 Procedure

Save as [Link] and follow the same steps.

3.7.5 Output

Maximum (20) in AL.

3.7.6 Result

The program correctly identified the maximum.

3.7.7 Analysis

The program is efficient but could be extended to handle multiple numbers using loops.

3.8 Experiment 8: Factorial of a Number

3.8.1 Objective

Compute the factorial of a number.

3.8.2 Theory

Factorial (n!) is the product of integers from 1 to n. A loop multiplies the accumulator by the
counter.

3.8.3 Program Code


.model small
.stack 100h
.data
num db 5 ; Number for factorial
result dw 1 ; Store result
.code
main:
mov ax, @data ; Initialize data segment
mov ds, ax
mov cx, num
mov ax, 1
factorial:
mul cx ; AX = AX * CX
loop factorial
mov result, ax ; Store result
mov ah, 4ch ; DOS function to exit
int 21h
end main

3.8.4 Procedure

Save as [Link] and follow the same steps.

3.8.5 Output

Factorial of 5 (120) in result.

3.8.6 Result

The factorial was computed correctly.

3.8.7 Analysis

The program is limited by 16-bit register size, causing overflow for large inputs.

3.9 Experiment 9: Fibonacci Series Generation

3.9.1 Objective

Generate the first n terms of the Fibonacci series.

3.9.2 Theory

Fibonacci series: 0, 1, 1, 2, 3, 5, ..., where each term is the sum of the two preceding ones.

3.9.3 Program Code


.model small
.stack 100h
.data
a db 0 ; First term
b db 1 ; Second term
n db 6 ; Number of terms
.code
main:
mov ax, @data ; Initialize data segment
mov ds, ax
mov cl, n
sub cl, 2 ; Adjust for first two terms
fib_loop:
mov al, a
mov bl, b
add al, bl ; Next term
mov a, bl
mov b, al
loop fib_loop
mov ah, 4ch ; DOS function to exit
int 21h
end main

3.9.4 Procedure

Save as [Link] and follow the same steps.

3.9.5 Output

Generates terms: 0, 1, 1, 2, 3, 5.

3.9.6 Result

The series was generated correctly.

3.9.7 Analysis

The program uses minimal registers but could be extended to store the series in memory.

3.10 Experiment 10: Sum of Series 1+2+3+...+N

3.10.1 Objective

Compute the sum of the first N natural numbers.

3.10.2 Theory

Sum = 1 + 2 + ... + N. A loop accumulates the sum in a register.

3.10.3 Program Code


.model small
.stack 100h
.data
N db 10 ; Number of terms
sum dw 0 ; Store sum
.code
main:
mov ax, @data ; Initialize data segment
mov ds, ax
xor cx, cx
mov cl, N
xor ax, ax
sum_loop:
add ax, cx ; Add CX to AX
loop sum_loop
mov sum, ax ; Store sum
mov ah, 4ch ; DOS function to exit
int 21h
end main

3.10.4 Procedure

Save as [Link] and follow the same steps.

3.10.5 Output

Sum of first 10 numbers (55) in sum.

3.10.6 Result

The sum was computed accurately.

3.10.7 Analysis

The loop-based approach is efficient, but the formula N*(N+1)/2 could be implemented for
optimization.

4. General Discussion
4.1 Common Challenges

●​ Register Management: Limited registers require careful planning to avoid


overwriting critical data.
●​ Debugging: Assembly lacks high-level debugging tools, necessitating manual
inspection of registers and memory.
●​ Data Size Constraints: 8-bit and 16-bit registers limit the range of computations,
especially for multiplication and factorial.
4.2 Comparison with High-Level Languages

Unlike C or Python, assembly requires explicit control over registers and memory, offering
greater efficiency but increasing complexity. High-level languages abstract these details,
making them easier for rapid development but less suitable for hardware-level tasks.

4.3 Learning Outcomes

●​ Mastery of 8086 instruction sets and interrupt handling.


●​ Understanding of low-level data manipulation and control flow.
●​ Appreciation for the trade-offs between efficiency and abstraction in programming.

4.4 Applications

Assembly language is used in embedded systems, operating system kernels, and


performance-critical applications like device drivers and real-time systems.

5. Conclusion
These ten experiments provided a comprehensive exploration of assembly language
programming using TASM and the 8086 microprocessor. From basic I/O operations to
complex algorithms like factorial and Fibonacci series, the experiments demonstrated the
power and challenges of low-level programming. Key skills gained include register
management, instruction selection, and debugging in a resource-constrained environment.
Assembly language bridges the gap between software and hardware, offering insights into
computer architecture and system design. Future experiments could explore floating-point
arithmetic, interrupt-driven I/O, or modern assemblers like NASM.

6. References
●​ Irvine, K. R. (2014). Assembly Language for x86 Processors (7th ed.). Pearson.
●​ Intel Corporation. (n.d.). 8086 Microprocessor Manual. Available: Intel 8086 Manual.
●​ Borland International. (n.d.). TASM User’s Guide. Available: Borland TASM.
●​ Ralf Brown. (n.d.). Interrupt List. Available: Ralf Brown’s Interrupt List.

7. Appendices
Appendix A: Sample Program Listings

●​ All program codes are listed in Section 3.

Appendix B: Flowchart for Factorial Calculation


Ste Description
p
1 Initialize AX = 1, CX =
num

2 Multiply AX by CX

3 Decrement CX

4 If CX > 0, repeat step 2

5 Store result in result

Appendix C: Additional Resources

●​ Online tutorials on 8086 assembly programming.


●​ TASM documentation for advanced features.

Implementation of Basic Programming


Concepts in Assembly Language (TASM)
Submitted by: [Your Name]​
Department of Computer Science and Engineering​
[Your Institution Name]​
Date: May 16, 2025

Abstract
This report documents a series of ten experiments designed to implement fundamental
programming concepts using Assembly Language with Turbo Assembler (TASM) on an 8086
microprocessor environment. The experiments cover input/output operations, arithmetic
computations, conditional logic, iterative algorithms, and mathematical series generation.
Each experiment includes objectives, theoretical background, program code, execution
procedures, outputs, results, and analysis, providing a comprehensive understanding of
low-level programming techniques. The use of TASM and DOSBox facilitated the
development and testing of these programs, reinforcing the significance of assembly
language in microprocessor interfacing and system-level programming. The report highlights
challenges, learning outcomes, and the importance of assembly language in computer
science education.

Table of Contents
1.​ Introduction
2.​ Apparatus and Software Requirements
3.​ Experiment Details​
3.1 Experiment 1: Printing "Hello World!" and Swapping Two Numbers​
3.2 Experiment 2: Arithmetic Operations​
3.3 Experiment 3: Even or Odd Number Detection​
3.4 Experiment 4: Leap Year Detection​
3.5 Experiment 5: Area Calculation (Rectangle, Circle, Triangle)​
3.6 Experiment 6: Temperature Conversion​
3.7 Experiment 7: Finding Minimum or Maximum of Two Numbers​
3.8 Experiment 8: Factorial of a Number​
3.9 Experiment 9: Fibonacci Series Generation​
3.10 Experiment 10: Sum of Series 1+2+3+...+N
4.​ General Discussion
5.​ Conclusion
6.​ References
7.​ Appendices

1. Introduction
Assembly language programming is a cornerstone of computer science, offering direct
control over hardware resources and enabling the development of efficient,
performance-critical software. The Intel 8086 microprocessor, introduced in 1978, was a
pivotal technology that powered early personal computers and remains a valuable
educational tool for understanding low-level programming. This project aims to implement
fundamental programming concepts—such as string output, arithmetic operations,
conditional logic, loops, and mathematical computations—using TASM in an 8086
environment. The experiments progressively build upon each other, starting with basic I/O
operations and advancing to complex algorithms, providing hands-on experience with
instruction sets, register operations, and interrupt handling. This report details the
methodology, results, and insights gained from these experiments, emphasizing the
educational value of assembly language in computer science and engineering.

2. Apparatus and Software Requirements


2.1 Hardware

●​ Personal Computer with a modern processor capable of running DOSBox.


●​ Optional: 8086-based microcontroller kit for hardware-based experiments.

2.2 Software

●​ Turbo Assembler (TASM): Version 5.0, used for assembling 8086 assembly code.
●​ DOSBox Emulator: Version 0.74, used to run 16-bit assembly programs in a modern
operating system.
●​ Text Editor: Notepad or Visual Studio Code for writing assembly code.

2.3 Development Environment Setup


1.​ Install DOSBox from DOSBox Official Site.
2.​ Place TASM binaries in a directory (e.g., C:\TASM).
3.​ Mount the directory in DOSBox using mount c C:\TASM.
4.​ Navigate to the directory with C:.
5.​ Write assembly code in a text editor and save with a .asm extension.
6.​ Compile and run programs using TASM commands (see experiment procedures).

3. Experiment Details
Each experiment follows a structured format with objectives, theoretical background,
program code, execution steps, outputs, results, and analysis.

3.1 Experiment 1: Printing "Hello World!" and Swapping Two Numbers

3.1.1 Objective

●​ Display the string "Hello World!" on the console.


●​ Swap the values of two numbers stored in memory.

3.1.2 Theory

●​ String Output: In 8086 assembly, the DOS interrupt INT 21H, function 09H, prints a
dollar-terminated string to the console. The LEA (Load Effective Address) instruction
loads the string’s offset into the DX register.
●​ Swapping Numbers: Swapping involves exchanging values between registers or
memory locations. The simplest method uses a temporary register, while alternatives
like XOR operations avoid extra storage but are less intuitive.

3.1.3 Program Code

Program 1: Printing "Hello World!"

.model small
.stack 100h
.data
msg db 'Hello World!$'
.code
main:
mov ax, @data ; Initialize data segment
mov ds, ax
mov ah, 09h ; DOS function to print string
lea dx, msg ; Load address of string
int 21h ; Call DOS interrupt
mov ah, 4ch ; DOS function to exit
int 21h
end main
Program 2: Swapping Two Numbers

.model small
.stack 100h
.data
num1 db 05h ; First number
num2 db 0Ah ; Second number
.code
main:
mov ax, @data ; Initialize data segment
mov ds, ax
mov al, num1 ; Load num1 into AL
mov bl, num2 ; Load num2 into BL
mov cl, al ; Store AL in temporary register CL
mov al, bl ; Move BL to AL
mov bl, cl ; Move CL to BL
mov num1, al ; Store swapped value back to num1
mov num2, bl ; Store swapped value back to num2
mov ah, 4ch ; DOS function to exit
int 21h
end main

3.1.4 Procedure

1.​ Write the code in a text editor and save as [Link] or [Link].
2.​ Open DOSBox and mount the directory containing the file.
3.​ Assemble: tasm [Link] or tasm [Link].
4.​ Link: tlink [Link] or tlink [Link].
5.​ Run: [Link] or [Link].
6.​ Observe the output or verify memory contents using a debugger.

3.1.5 Output

●​ Program 1: Displays "Hello World!" on the console.


●​ Program 2: Internally swaps num1 (05h) and num2 (0Ah) in memory, verifiable via
debugger.

3.1.6 Result

Both programs executed successfully, demonstrating string output and data manipulation.

3.1.7 Analysis

The string output program relies on DOS interrupts, which are specific to the 8086
environment. The swapping program uses a temporary register, which is straightforward but
consumes an extra register. An alternative XOR-based swap could reduce register usage
but may be less readable for beginners.
3.2 Experiment 2: Arithmetic Operations

3.2.1 Objective

Perform addition, subtraction, multiplication, and division on two-digit numbers.

3.2.2 Theory

The 8086 instruction set includes:

●​ ADD: Adds two operands, storing the result in the destination.


●​ SUB: Subtracts the source from the destination.
●​ MUL: Multiplies two unsigned numbers, storing the result in AX.
●​ DIV: Divides AX by the operand, storing the quotient in AL and remainder in AH.

3.2.3 Program Code


.model small
.stack 100h
.data
num1 db 10 ; First number
num2 db 5 ; Second number
.code
main:
mov ax, @data ; Initialize data segment
mov ds, ax
mov al, num1
add al, num2 ; Addition: AL = 10 + 5
mov al, num1
sub al, num2 ; Subtraction: AL = 10 - 5
mov al, num1
mov bl, num2
mul bl ; Multiplication: AX = 10 * 5
mov ax, 10
mov bl, 2
div bl ; Division: AL = 10 / 2, AH = remainder
mov ah, 4ch ; DOS function to exit
int 21h
end main

3.2.4 Procedure

Follow the same steps as Experiment 1, saving the file as [Link].

3.2.5 Output

●​ Addition: AL = 15
●​ Subtraction: AL = 5
●​ Multiplication: AX = 50
●​ Division: AL = 5, AH = 0

3.2.6 Result

Arithmetic operations were successfully implemented, with results verified via register
inspection.

3.2.7 Analysis

The program handles 8-bit numbers, but larger numbers require 16-bit registers to avoid
overflow. The DIV instruction requires careful setup to ensure the dividend is in AX.

3.3 Experiment 3: Even or Odd Number Detection

3.3.1 Objective

Determine whether a number is even or odd.

3.3.2 Theory

A number is even if its least significant bit (LSB) is 0. The AND instruction with 01h isolates
the LSB, where a result of 0 indicates an even number.

3.3.3 Program Code


.model small
.stack 100h
.data
num db 7 ; Number to check
.code
main:
mov ax, @data ; Initialize data segment
mov ds, ax
mov al, num
and al, 01h ; Isolate LSB
mov ah, 4ch ; DOS function to exit
int 21h
end main

3.3.4 Procedure

Follow the same steps, saving as [Link].

3.3.5 Output

For num = 7, AL = 1 (odd). For num = 8, AL = 0 (even).

3.3.6 Result
The program correctly identified the parity of the input number.

3.3.7 Analysis

Bitwise operations are efficient for parity checks. Conditional jumps could be added to
display the result explicitly.

3.4 Experiment 4: Leap Year Detection

3.4.1 Objective

Check if a given year is a leap year.

3.4.2 Theory

A year is a leap year if divisible by 4 and not by 100, or divisible by 400. The DIV instruction
computes the remainder, checked via DX.

3.4.3 Program Code


.model small
.stack 100h
.data
year dw 2024 ; Year to check
.code
main:
mov ax, @data ; Initialize data segment
mov ds, ax
mov ax, year
mov dx, 0
mov cx, 4
div cx ; Divide year by 4
cmp dx, 0 ; Check if remainder is 0
jne not_leap
not_leap:
mov ah, 4ch ; DOS function to exit
int 21h
end main

3.4.4 Procedure

Save as [Link] and follow the same steps.

3.4.5 Output

For 2024, DX = 0 (leap year).

3.4.6 Result
The program correctly identified 2024 as a leap year.

3.4.7 Analysis

The program simplifies the leap year check by omitting century-year rules, which could be
added for completeness.

3.5 Experiment 5: Area Calculation (Rectangle, Circle, Triangle)

3.5.1 Objective

Calculate the area of a rectangle, circle, and triangle.

3.5.2 Theory

●​ Rectangle: Area = length × breadth


●​ Circle: Area = π × r² (π ≈ 3.14)
●​ Triangle: Area = 0.5 × base × height

3.5.3 Program Code (Rectangle)


.model small
.stack 100h
.data
length db 5 ; Length of rectangle
breadth db 4 ; Breadth of rectangle
.code
main:
mov ax, @data ; Initialize data segment
mov ds, ax
mov al, length
mov bl, breadth
mul bl ; Area in AX
mov ah, 4ch ; DOS function to exit
int 21h
end main

3.5.4 Procedure

Save as [Link] and follow the same steps.

3.5.5 Output

Area of rectangle (5 × 4 = 20) in AX.

3.5.6 Result

The program successfully computed the rectangle’s area.


3.5.7 Analysis

Circle and triangle calculations require floating-point approximations, which are complex in
8086 assembly due to integer-based arithmetic.

3.6 Experiment 6: Temperature Conversion

3.6.1 Objective

Convert temperature from Celsius to Fahrenheit.

3.6.2 Theory

°F = (°C × 9/5) + 32

3.6.3 Program Code


.model small
.stack 100h
.data
celsius db 25 ; Temperature in Celsius
.code
main:
mov ax, @data ; Initialize data segment
mov ds, ax
mov al, celsius
mov bl, 9
mul bl ; AL = Celsius * 9
mov bl, 5
div bl ; AL = (Celsius * 9) / 5
add al, 32 ; AL = Fahrenheit
mov ah, 4ch ; DOS function to exit
int 21h
end main

3.6.4 Procedure

Save as [Link] and follow the same steps.

3.6.5 Output

Converts 25°C to 77°F in AL.

3.6.6 Result

The conversion was accurate using integer arithmetic.

3.6.7 Analysis
Integer arithmetic limits precision, but the result is correct for whole numbers.

3.7 Experiment 7: Finding Minimum or Maximum of Two Numbers

3.7.1 Objective

Identify the maximum of two numbers.

3.7.2 Theory

The CMP instruction compares two values, and conditional jumps (JG, JL) determine the
relationship.

3.7.3 Program Code


.model small
.stack 100h
.data
num1 db 15 ; First number
num2 db 20 ; Second number
.code
main:
mov ax, @data ; Initialize data segment
mov ds, ax
mov al, num1
cmp al, num2 ; Compare num1 and num2
jg greater
mov al, num2 ; num2 is greater
jmp done
greater:
mov al, num1 ; num1 is greater
done:
mov ah, 4ch ; DOS function to exit
int 21h
end main

3.7.4 Procedure

Save as [Link] and follow the same steps.

3.7.5 Output

Maximum (20) in AL.

3.7.6 Result

The program correctly identified the maximum.

3.7.7 Analysis
The program is efficient but could be extended to handle multiple numbers using loops.

3.8 Experiment 8: Factorial of a Number

3.8.1 Objective

Compute the factorial of a number.

3.8.2 Theory

Factorial (n!) is the product of integers from 1 to n. A loop multiplies the accumulator by the
counter.

3.8.3 Program Code


.model small
.stack 100h
.data
num db 5 ; Number for factorial
result dw 1 ; Store result
.code
main:
mov ax, @data ; Initialize data segment
mov ds, ax
mov cx, num
mov ax, 1
factorial:
mul cx ; AX = AX * CX
loop factorial
mov result, ax ; Store result
mov ah, 4ch ; DOS function to exit
int 21h
end main

3.8.4 Procedure

Save as [Link] and follow the same steps.

3.8.5 Output

Factorial of 5 (120) in result.

3.8.6 Result

The factorial was computed correctly.

3.8.7 Analysis

The program is limited by 16-bit register size, causing overflow for large inputs.
3.9 Experiment 9: Fibonacci Series Generation

3.9.1 Objective

Generate the first n terms of the Fibonacci series.

3.9.2 Theory

Fibonacci series: 0, 1, 1, 2, 3, 5, ..., where each term is the sum of the two preceding ones.

3.9.3 Program Code


.model small
.stack 100h
.data
a db 0 ; First term
b db 1 ; Second term
n db 6 ; Number of terms
.code
main:
mov ax, @data ; Initialize data segment
mov ds, ax
mov cl, n
sub cl, 2 ; Adjust for first two terms
fib_loop:
mov al, a
mov bl, b
add al, bl ; Next term
mov a, bl
mov b, al
loop fib_loop
mov ah, 4ch ; DOS function to exit
int 21h
end main

3.9.4 Procedure

Save as [Link] and follow the same steps.

3.9.5 Output

Generates terms: 0, 1, 1, 2, 3, 5.

3.9.6 Result

The series was generated correctly.

3.9.7 Analysis
The program uses minimal registers but could be extended to store the series in memory.

3.10 Experiment 10: Sum of Series 1+2+3+...+N

3.10.1 Objective

Compute the sum of the first N natural numbers.

3.10.2 Theory

Sum = 1 + 2 + ... + N. A loop accumulates the sum in a register.

3.10.3 Program Code


.model small
.stack 100h
.data
N db 10 ; Number of terms
sum dw 0 ; Store sum
.code
main:
mov ax, @data ; Initialize data segment
mov ds, ax
xor cx, cx
mov cl, N
xor ax, ax
sum_loop:
add ax, cx ; Add CX to AX
loop sum_loop
mov sum, ax ; Store sum
mov ah, 4ch ; DOS function to exit
int 21h
end main

3.10.4 Procedure

Save as [Link] and follow the same steps.

3.10.5 Output

Sum of first 10 numbers (55) in sum.

3.10.6 Result

The sum was computed accurately.

3.10.7 Analysis
The loop-based approach is efficient, but the formula N*(N+1)/2 could be implemented for
optimization.

4. General Discussion
4.1 Common Challenges

●​ Register Management: Limited registers require careful planning to avoid


overwriting critical data.
●​ Debugging: Assembly lacks high-level debugging tools, necessitating manual
inspection of registers and memory.
●​ Data Size Constraints: 8-bit and 16-bit registers limit the range of computations,
especially for multiplication and factorial.

4.2 Comparison with High-Level Languages

Unlike C or Python, assembly requires explicit control over registers and memory, offering
greater efficiency but increasing complexity. High-level languages abstract these details,
making them easier for rapid development but less suitable for hardware-level tasks.

4.3 Learning Outcomes

●​ Mastery of 8086 instruction sets and interrupt handling.


●​ Understanding of low-level data manipulation and control flow.
●​ Appreciation for the trade-offs between efficiency and abstraction in programming.

4.4 Applications

Assembly language is used in embedded systems, operating system kernels, and


performance-critical applications like device drivers and real-time systems.

5. Conclusion
These ten experiments provided a comprehensive exploration of assembly language
programming using TASM and the 8086 microprocessor. From basic I/O operations to
complex algorithms like factorial and Fibonacci series, the experiments demonstrated the
power and challenges of low-level programming. Key skills gained include register
management, instruction selection, and debugging in a resource-constrained environment.
Assembly language bridges the gap between software and hardware, offering insights into
computer architecture and system design. Future experiments could explore floating-point
arithmetic, interrupt-driven I/O, or modern assemblers like NASM.

6. References
●​ Irvine, K. R. (2014). Assembly Language for x86 Processors (7th ed.). Pearson.
●​ Intel Corporation. (n.d.). 8086 Microprocessor Manual. Available: Intel 8086 Manual.
●​ Borland International. (n.d.). TASM User’s Guide. Available: Borland TASM.
●​ Ralf Brown. (n.d.). Interrupt List. Available: Ralf Brown’s Interrupt List.

7. Appendices
Appendix A: Sample Program Listings

●​ All program codes are listed in Section 3.

Appendix B: Flowchart for Factorial Calculation


Ste Description
p

1 Initialize AX = 1, CX =
num

2 Multiply AX by CX

3 Decrement CX

4 If CX > 0, repeat step 2

5 Store result in result

Appendix C: Additional Resources

●​ Online tutorials on 8086 assembly programming.


●​ TASM documentation for advanced features.

Assembly Language: Chapters 1-5 Flashcards and Detailed Notes

Chapter 1: Microcomputer Systems

Key Concepts:

●​ Microcomputer Components: CPU, Memory, I/O Ports​

●​ Memory:​

○​ Byte = 8 bits​

○​ Word = 2 bytes (16 bits)​

○​ Each byte has a unique address​


○​ Memory is either RAM (volatile) or ROM (non-volatile)​

●​ CPU:​

○​ Executes instructions in a Fetch-Decode-Execute cycle​

○​ Consists of EU (Execution Unit) and BIU (Bus Interface Unit)​

○​ ALU performs arithmetic and logic​

○​ IP (Instruction Pointer) holds address of next instruction​

●​ Buses:​

○​ Address bus, Data bus, Control bus​

●​ Instruction Format:​

○​ Opcode + Operands (e.g., MOV AX, BX)​

●​ I/O Ports:​

○​ Allow communication with external devices​

○​ Can be Serial (1 bit at a time) or Parallel (8+ bits at a time)​

●​ Assembly vs High-Level Language:​

○​ Assembly = faster, hardware-level control​

○​ High-Level = abstract, portable, easier to maintain​

Flashcards (20 Q&A):

Q1: What are the 3 main components of a microcomputer?​


A: CPU, Memory, I/O Ports

Q2: What is a byte?​


A: A group of 8 bits.

Q3: What does the BIU do?​


A: Handles communication between CPU and memory/I/O.

Q4: What are the two kinds of memory?​


A: RAM and ROM

Q5: What does the ALU do?​


A: Performs arithmetic and logic operations.
Q6: What is the purpose of the IP register?​
A: Holds the address of the next instruction.

Q7: What is the role of the EU?​


A: Executes instructions.

Q8: What is a word in memory?​


A: A group of 2 bytes or 16 bits.

Q9: Define ROM.​


A: Read-Only Memory, retains data without power.

Q10: Define RAM.​


A: Random Access Memory, loses data when powered off.

Q11: How does CPU communicate with memory?​


A: Via address, data, and control buses.

Q12: What is the difference between serial and parallel ports?​


A: Serial sends 1 bit at a time, parallel sends multiple.

Q13: Define fetch-execute cycle.​


A: Process by which CPU executes instructions.

Q14: What is the function of the motherboard?​


A: Holds CPU, memory, and expansion cards.

Q15: Define opcode.​


A: Part of instruction that tells the CPU what to do.

Q16: What is the purpose of I/O ports?​


A: Interface between CPU and peripherals.

Q17: How many bits are in a word?​


A: 16 bits

Q18: What are buses in a microcomputer?​


A: Connections carrying data, addresses, and control signals.

Q19: Why use assembly language?​


A: For faster, low-level hardware access.

Q20: What is machine language?​


A: Binary code directly executed by the CPU.

Chapter 2: Number and Character Representation

Key Concepts:
●​ Number Systems:​

○​ Binary (base 2), Decimal (base 10), Hexadecimal (base 16)​

●​ Conversions:​

○​ Binary <-> Decimal​

○​ Binary <-> Hex (4-bit = 1 hex digit)​

●​ Signed Numbers:​

○​ Positive: normal binary​

○​ Negative: Two's Complement​

●​ Character Representation:​

○​ ASCII (7-bit standard)​

○​ Example: 'A' = 65 = 41h​

Flashcards (20 Q&A):

Q1: What is the ASCII code for 'A'?​


A: 65 or 41h

Q2: What is Two's Complement used for?​


A: Representing negative binary numbers.

Q3: Convert Decimal 15 to Binary.​


A: 1111

Q4: Convert Binary 1010 to Decimal.​


A: 10

Q5: What is the base of hexadecimal system?​


A: 16

Q6: What is the binary of hex F?​


A: 1111

Q7: How do you convert hex to binary?​


A: Replace each hex digit with its 4-bit binary.

Q8: What is the decimal of binary 1001?​


A: 9
Q9: What is the two's complement of 0001?​
A: 1111 (in 4-bit system)

Q10: Which number systems are used in Assembly?​


A: Binary, Hexadecimal, Decimal

Q11: What is 1 KB in bytes?​


A: 1024 bytes

Q12: What does 0Ah mean in decimal?​


A: 10

Q13: Convert 11001011 to hex.​


A: CB

Q14: Convert 1Ch to binary.​


A: 00011100

Q15: What is a nibble?​


A: 4 bits

Q16: How are characters stored in memory?​


A: Using ASCII codes

Q17: What is the hex value for space character?​


A: 20h

Q18: Is 255 representable in 1 byte?​


A: Yes (FFh)

Q19: What is 2's complement of 5 in 8 bits?​


A: 11111011

Q20: How do you represent -1 in 8-bit 2’s complement?​


A: 11111111

(Chapters 3–5 expansion will follow in next update.)

Assembly Language: Chapters 1-5 Flashcards and Detailed Notes

Chapter 1: Microcomputer Systems

[... existing content for Chapter 1 and Chapter 2 ...]

Chapter 3: Organization of the IBM Personal Computers


Key Concepts:

●​ Intel 8086 Family: Includes 8086 and 8088 microprocessors​

●​ CPU Components:​

○​ General Registers: AX, BX, CX, DX​

○​ Segment Registers: CS, DS, SS, ES​

○​ Pointer/Index Registers: SP, BP, SI, DI​

○​ IP (Instruction Pointer), FLAGS register​

●​ PC Memory Organization: Segmented memory model​

●​ I/O Ports and Addresses: Assigned to devices​

●​ BIOS & DOS Interaction: Start-up process and booting​

Flashcards (20 Q&A):

Q1: What are the 4 general-purpose registers in 8086?​


A: AX, BX, CX, DX

Q2: What do CS and DS stand for?​


A: Code Segment and Data Segment

Q3: What does IP do?​


A: Holds the address of the next instruction

Q4: Name the pointer and index registers.​


A: SP, BP, SI, DI

Q5: What is the FLAGS register?​


A: Holds status flags like Zero, Sign, Carry

Q6: What is the segment-offset addressing?​


A: Physical address = Segment * 16 + Offset

Q7: How many bytes can be accessed in 20-bit addressing?​


A: 1 MB (2^20)

Q8: What is the function of SS register?​


A: Stack Segment pointer

Q9: What happens at PC start-up?​


A: BIOS executes POST and boot sequence
Q10: What is the memory limit of segment in 8086?​
A: 64 KB

Q11: What is an I/O port?​


A: A hardware interface assigned an address

Q12: What is ES used for?​


A: Extra Segment

Q13: How is memory organized in IBM PC?​


A: Using segments: code, data, stack

Q14: What is the role of BIOS?​


A: Provides basic I/O services

Q15: Difference between 8086 and 8088?​


A: 8086 has 16-bit bus, 8088 has 8-bit bus

Q16: What address is stored in IP after instruction fetch?​


A: Next instruction address

Q17: What are physical addresses made of?​


A: Segment and offset

Q18: Define SP.​


A: Stack Pointer

Q19: How many segment registers are in 8086?​


A: 4 (CS, DS, SS, ES)

Q20: What is the operating system's role?​


A: Manage memory, I/O, and program execution

Chapter 4: Introduction to IBM PC Assembly Language

Key Concepts:

●​ Syntax Fields: Name, Operation, Operands, Comments​

●​ Defining Data: DB (byte), DW (word), Arrays​

●​ Constants: EQU, Labels, Directives like .MODEL, .STACK, .DATA, .CODE​

●​ Instructions:​

○​ Data Transfer: MOV, XCHG​


○​ Arithmetic: ADD, SUB, INC, DEC, NEG​

●​ Memory Models: Tiny, Small, Medium, etc.​

●​ Program Segments: Data, Stack, Code​

●​ INT 21h Services: Used for I/O (DOS Interrupt)​

●​ Creating & Running Programs: Using TASM/MASM, LINK, and DOSBox​

Flashcards (20 Q&A):

Q1: What is the .MODEL SMALL directive?​


A: Specifies small memory model (64K data + 64K code)

Q2: What does DB define?​


A: Byte data

Q3: What instruction swaps two registers?​


A: XCHG

Q4: What is .STACK 100h?​


A: Declares a 256-byte stack

Q5: What does INT 21h do?​


A: Calls DOS functions

Q6: What is the function of MOV AX, @DATA?​


A: Loads address of data segment into AX

Q7: How do you define a word variable?​


A: With DW

Q8: What is a comment in assembly?​


A: Anything after ; is ignored

Q9: What is the purpose of END MAIN?​


A: Marks program end

Q10: What does CALL do?​


A: Jumps to a subroutine

Q11: What does RET do?​


A: Returns from subroutine

Q12: How is a string displayed in DOS?​


A: INT 21h with AH=09h
Q13: What does EQU define?​
A: A constant

Q14: What register is used to output a character?​


A: DL (with AH=02h)

Q15: What directive defines code section?​


A: .CODE

Q16: What is a procedure in assembly?​


A: A named block of code with PROC/ENDP

Q17: What is INC AL?​


A: Increments AL by 1

Q18: What is the result of NEG AL if AL=5?​


A: -5 (in 2’s complement)

Q19: What does DEC BL do?​


A: Decrements BL by 1

Q20: Why use segment registers?​


A: For organizing memory access

Chapter 5: The Processor Status and the FLAGS Register

Key Concepts:

●​ FLAGS Register: Stores status/control flags affected by operations​

●​ Important Flags:​

○​ Carry (CF), Zero (ZF), Sign (SF), Overflow (OF), Parity (PF), Auxiliary Carry
(AF), Direction (DF), Interrupt (IF), Trap (TF)​

●​ Flag Effects:​

○​ Arithmetic and logic operations change flag values​

●​ Testing with DEBUG: Use D, T, R, G commands​

●​ Program Debugging: Observe flag changes after each instruction​

Flashcards (20 Q&A):


Q1: What does the FLAGS register do?​
A: Holds CPU status after operations

Q2: What does CF (Carry Flag) mean?​


A: A carry occurred from the most significant bit

Q3: When is ZF set?​


A: When result = 0

Q4: What does SF indicate?​


A: Sign of result (1 = negative)

Q5: What causes OF (Overflow Flag)?​


A: Signed overflow

Q6: What is PF?​


A: Set if number of 1s in result is even

Q7: When is AF (Auxiliary Carry) set?​


A: Carry from bit 3 to bit 4

Q8: What does IF (Interrupt Flag) control?​


A: Whether maskable interrupts are allowed

Q9: What does DF affect?​


A: Direction of string operations

Q10: What does TF (Trap Flag) enable?​


A: Single-step execution for debugging

Q11: What happens when ZF=1?​


A: The result was zero

Q12: What does ADD do to flags?​


A: May change CF, ZF, SF, OF, AF, PF

Q13: What flag helps detect signed overflow?​


A: OF

Q14: How do you check a flag in DEBUG?​


A: Use R to display FLAGS

Q15: What flag would be set if AL becomes 00h after SUB?​


A: ZF (Zero Flag)

Q16: Which flag is used in conditional jumps?​


A: ZF, SF, CF, OF depending on instruction

Q17: Which flag is used for BCD operations?​


A: AF
Q18: What does clearing IF do?​
A: Disables interrupts

Q19: How do you clear a flag?​


A: Use CLC for CF, CLD for DF, etc.

Q20: What is the size of FLAGS register?​


A: 16 bits

You might also like