0% found this document useful (0 votes)
13 views10 pages

COAL Lab Practical 1+2

Uploaded by

tthetops2004
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)
13 views10 pages

COAL Lab Practical 1+2

Uploaded by

tthetops2004
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/ 10

Computer Organization and Assembly Language Department of Computer

Practical No. 1: Introduction to Assembly Language


Programming and program structure
CLO PLO LL
1 2 2

OBJECTIVE:
The objective of a lab manual on "Assembly language" likely involves teaching assembly
language to undergrads helps them understand how computers work at a deep level, write
efficient code, and debug effectively. It's key for careers in embedded systems and improves
understanding of compilers and interpreters. Plus, it offers insight into the history of computing
and sharpens critical thinking skills.

Theory Overview:
 Assembly language, a low-level programming language, emerged in the late 1940s
and early 1950s alongside the development of electronic computers. Pioneers like
Kathleen Booth and John Backus contributed significantly to its development.
 It is primarily used in situations where direct hardware manipulation or maximum
computational efficiency is required, such as embedded systems programming, device
driver development, and performance-critical applications.
 Assembly language offers unparalleled control over hardware, making it
indispensable for tasks requiring direct hardware manipulation and optimization for
performance-critical applications.
 Despite the predominance of high-level languages for general-purpose programming,
assembly language retains its significance in niche areas where efficiency and control
are paramount, such as embedded systems development and device driver
programming.
 Its foundational role in understanding computer architecture and operating systems
ensures its continued relevance in educating software engineers and computer
scientists, providing essential knowledge for understanding the underlying principles
of computing systems.

Advantages of Assembly Language


Understanding assembly language makes one aware of −
 How programs interface with OS, processor, and BIOS

Computer Organization and Assembly language 14


Computer Organization and Assembly Language Department of Computer

 How data is represented in memory and other external devices


 How the processor accesses and executes instruction
 How instructions access and process data
 How a program accesses external devices
 It requires less memory and execution time
 It allows hardware-specific complex jobs in an easier way
 It is suitable for time-critical jobs
 It is most suitable for writing interrupt service routines and other memory resident
programs.
Compile and Execute Assembly language Program
To save and execute the provided assembly code in the emu8086 emulator, follow these step-
by-step instructions:
1. Open Emu8086 Emulator: Launch the Emu8086 emulator on your computer. If you
haven't installed it yet, download and install it from a trusted source.
2. Create a New Assembly File: In the emulator's interface, open a new file or create a
new assembly file by clicking on "File" > "New".
3. Copy and Paste the Code: Copy the provided assembly code and paste it into the
new file you opened in the Emu8086 editor.
4. Save the File: Save the assembly file with a meaningful name and the extension
".asm", for example, "myprogram.asm". To do this, click on "File" > "Save As", then
specify the file name and location where you want to save it.
5. Assemble the Code: In the Emu8086 emulator, assemble the assembly code by
clicking on "Run" > "Assemble". This will compile the code and generate the
corresponding machine code.
6. Check for Errors: If there are any syntax errors or issues in your code, the assembler
will display error messages. Review and correct any errors before proceeding.
7. Load the Program: After successful assembly, load the program into the emulator by
clicking on "Run" > "Load and Run". Alternatively, you can load the program without
executing it immediately by clicking on "Run" > "Load Only".
8. Execute the Program: If you chose to load and run the program in the previous step,
the emulator will execute the program automatically. If you loaded the program only,
you can execute it manually by clicking on "Run" > "Run".

Computer Organization and Assembly language 15


Computer Organization and Assembly Language Department of Computer

9. View Output: If the program includes any output to the console (such as printing
characters), you should see the output displayed in the emulator's console window.
10. Terminate the Program: After the program has executed, you can terminate it by
closing the emulator window or clicking on "File" > "Exit".
Program Structure
Directives: Directives provide instructions to the assembler for tasks such as defining data
segments, reserving memory, or including external libraries. Directives often begin with a
period (.) or other special character.
 model small: This directive tells the assembler to generate code for a small
memory model. In this memory model, the code, data, and stack segments are
limited to 64 KB each.
 .stack 100h: This directive sets the size of the stack segment to 256 bytes (100h in
hexadecimal). This segment contains data values passed to functions and
procedures within the program.
 .data: This directive starts the data segment, where variables and constants are
declared.
 .code: This directive starts the code segment, where the program's instructions are
placed.
Comments
Comments are non-executable statements used to document code and provide explanations
for human readers. They are ignored by the assembler during program compilation.
Assembly language comment begins with a semicolon (;). It may contain any printable
character including blank.
It can appear on a line by itself, like:
; This program displays a message on screen
or, on the same line along with an instruction, like:
add ax ,bx ; adds bx to ax

Computer Organization and Assembly language 16


Computer Organization and Assembly Language Department of Computer

Basic Syntax:
.model small
.data
; declare variables here
.code
Main PROC ; executable code begins here
; (write your code here)
Exit ; return control to Operating System
main ENDP
End main

MOV Instruction
The MOV instruction that is used for moving data from one storage space to another. The
MOV instruction takes two operands.

Syntax

The syntax of the MOV instruction is −

MOV destination, source

The MOV instruction may have one of the following five forms −

MOV register, register


MOV register, immediate
MOV memory, immediate
MOV register, memory
MOV memory, register
Example:
MOV destination, source ; Move the contents of source to destination
ADD destination, source ; Add the contents of source to destination

Computer Organization and Assembly language 17


Computer Organization and Assembly Language Department of Computer

TASK 1: Write the following program in assembly language and observe the output.

.model small
.stack 100h
.data
.code
main proc
mov bl,2
mov dl,2
mov ah,2
INT 21h
main endp
end main

Task.2 Write a program to print a single character on screen.


Task.3 Write a Program to print your name on screen with characters using mov ah, 2.

CONCLUSION:

RUBRICS:

Performance Lab Report

Description Total Marks Description Total Marks


Marks Obtaind Marks Obtained

Ability to 5 5
Conduct Structure
practical

5 5
Data Analysis &
Efficiency
Interpretation

Total Marks obtained Total Marks Obtained

Instructors Signature:

Computer Organization and Assembly language 18


Computer Organization and Assembly Language Department of Computer

Practical No. 2: Types of Registers, Service Routines, Interrupts

CLO PLO LL

OBJECTIVE: 1 1 2

To understand the different types of registers in assembly language and to demonstrate


proficiency in utilizing these registers in temporarily holding data during program execution
and the use of different interrupt service routines in program.

Overview:
Processor Registers
There are ten 32-bit and six 16-bit processor registers in IA-32 architecture. The registers are
grouped into three categories:
 General registers
 Control registers
 Segment registers
The general registers are further divided into the following groups:
 Data registers
 Pointer registers
 Index registers
Data Registers:
Four 32-bit data registers are used for arithmetic, logical and other operations. These 32-bit
registers can be used in three ways:
1. As complete 32-bit data registers: EAX, EBX, ECX, EDX.
2. Lower halves of the 32-bit registers can be used as four 16-bit data registers: AX, BX, CX
and DX.
3. Lower and higher halves of the above-mentioned four 16-bit registers can be used as eight
8-bit data registers: AH, AL, BH, BL, CH, CL, DH, and DL.

Computer Organization and Assembly language 20


Computer Organization and Assembly Language Department of Computer

Some of these data registers has specific used in arithmetical operations.


AX is the primary accumulator; it is used in input/output and most arithmetic
instructions. For example, in multiplication operation, one operand is stored in EAX,
or AX or AL register according to the size of the operand.
BX is known as the base register as it could be used in indexed addressing.
CX is known as the count register as the ECX, CX registers store the loop count in
iterative operations.
DX is known as the data register. It is also used in input/output operations. It is also
used with AX register along with DX for multiply and divide operations involving
large values.
Pointer Registers
The pointer registers are 32-bit EIP, ESP and EBP registers and corresponding 16-bit
right portions IP, SP and BP.
There are three categories of pointer registers:
 Instruction Pointer (IP) - the 16-bit IP register stores the offset address of the next
instruction to be executed. IP in association with the CS register (as CS:IP) gives the
complete address of the current
instruction in the code segment.
 Stack Pointer (SP) - the 16-bit SP register provides the offset value within the
program stack. SP in association with the SS register (SS:SP) refers to be current
position of data or address within the program
stack.
 Base Pointer (BP) - the 16-bit BP register mainly helps in referencing the parameter
variables passed to a subroutine. The address in SS register is combined with the
offset in BP to get the location of the parameter.
BP can also be combined with DI and SI as base register for special addressing.

Index Registers:
The 32-bit index registers ESI and EDI and their 16-bit rightmost portions SI and DI
are used for indexed addressing and sometimes used in addition and subtraction.

Computer Organization and Assembly language 21


Computer Organization and Assembly Language Department of Computer

There are two sets of index pointers:


 Source Index (SI) - it is used as source index for string operations
 Destination Index (DI) - it is used as destination index for string operations.

Service Routines
1= Input a character with echo
2=Output/Print a single character ‘A’
8= Input a character without echo
9=Print collection of characters/String
4ch=Exit
Interrupts
Stop the current program and allow microprocessor to access hardware to take input
or give output.
 The INT instruction executes a software interrupt.
 The code that handles the interrupt is called an interrupt handler.
Syntax:
INT number
INT 21h = Interrupt for text handling
INT 20h = Interrupt for video/graphics handling

TASKS:
Task 1: Type and save the following programs in assembly language.
Run these programs and observe their values in registers.

model small model small model small


.stack 100h .stack 100h .stack 100h
.data .data .data
.code .code .code
Main Proc Main Proc Main Proc
Mov dl,'D' Mov bl,4 Mov dl,53
Mov ah, 2 Mov dl,'A' Mov ch, ‘*’
INT 21h Mov ah, 2 Mov ah, 2
Main endp INT 21h INT 21h
End Main Main endp Main endp
End Main End Main

Computer Organization and Assembly language 22


Computer Organization and Assembly Language Department of Computer

Task.2: Write the following code


mov al, 5 ; bin=00000101b
mov bl, 10 ;bin=00001010b

Press the emulate button and single step the code.


Note the final values of registers in the following table

Register Value
AX
BX
CS
IP

Task.3: Write the following code


mov al, 5 ; al = 5
add al, -3 ; al = 2
Press the emulate button and single step the code.
Note the final values of registers in the following table.

Register Value
AX
BX
CS
IP

Computer Organization and Assembly language 23


Computer Organization and Assembly Language Department of Computer

CONCLUSION:

RUBRICS:

Performance Lab Report

Description Total Marks Description Total Marks


Mark Obtaine Mark Obtaine
s d s d
Ability 5 5
to Structure
Condu
ct
practic
al
5 5
Data Analysis &
Interpretation Efficiency

Total Marks obtained Total Marks Obtained

Instructors Signature:

Computer Organization and Assembly language 24

You might also like