Lab Manuals
Lab Manuals
DIFFERENT COMMANDS
Lab-01
Name:_______________________________
Registration no:________________________
OBJECTIVE:
Explore debugger using different commands.
THEORY:
PROGRAMMING LANGUAGE
A programming language is an artificial language that can be used to control the behavior of a machine,
particularly a computer. Programming languages, like human languages, have syntactic and semantic rules to
define meaning.
TYPES OF PROGRAMMING LANGUAGE
Programming languages can be classified into three basic categories on the basis of understanding level of users
as well as the machine to which instructions has been given:
3. MACHINE LANGUAGE
Machine language is at the lowest level, because it is the actual binary code of 1s and
0s that the computer understands. These are designed to give a better machine efficiency.
REGISTERS CLASSIFICATION: The registers inside the microprocessor are classified according to the
function they perform.
AX (ACCUMULATOR REGISTER)
• It is the preferred register to use in the arithmetic, logic and data transfer instructions because its use
generates the shortest machine code.
• In multiplication and division operations, one of the numbers involved must be in AX or AL.
• Input and output operation also requires the use of AX and AL.
BX (BASE REGISTER)
•Program loop instructions are facilitated by the use of CX register, serves as a loop counter.
•Also used as a counter in the string operations.
•CL is used as count in instructions that shift and rotate bits.
DX (DATA REGISTER)
• The basic MOV instruction is used to transfer data between registers, between and memory locations, or
to have a number directly to a register or memory location.
Syntax: MOV Destination, Sourc
EXAMPLES:
• ADD:Add the contents of source operand1 to source operand 2 and result store in the source operand1.
Tasks:
Write purpose of each register :
AH: High byte of AX; used in system calls and some interrupt functions.
AL: Low byte of AX; used for arithmetic, logic, and I/O operations.
BH: High byte of BX; helps in data addressing and offset handling.
BL: Low byte of BX; used in loops and indexing operations.
CH: High byte of CX; used in loop counters or timing delays.
CL: Low byte of CX; commonly used in shift and rotate instructions.
DH: High byte of DX; supports data and I/O-related tasks.
DL: Low byte of DX; used in port addressing and I/O operations.
AX: Accumulator register; used in arithmetic, logic, and data transfer operations.
BX: Base register; often used to hold base addresses for memory access.
CX: Count register; mainly used in loops and shift/rotate operations.
DX: Data register; used in multiplication/division and I/O port access.
CS (Code Segment): Points to the segment containing the current program code.
DS (Data Segment): Points to the segment where variables are stored.
OBJECTIVE
To understand the basic concept and functionality of Assembly Language.
ASSEMBLY LANGUAGE
Assembly language is a machine specific programming language with a one-to-one
correspondence between its statements and the computer’s native machine language. There are many different
types of assembly language, each specific to a processor or processor family. IBM-PC assembly language refers
to instruction recognized by a number of different microprocessors in the Intel family: 8086, 8088, 80186,
80286, 80386, 80486, and Pentium.
USES:
Assembly language is used most often when either communicating with the operating system or directly
accessing computer hardware.
Secondly, assembly language is used to optimize certain critical areas of application programs to speed
up their runtime execution.
ASSEMBLER
An assembler is a program that converts source code programs from the assembly language into
machine language. The assembler can optionally generate a source- listing file with line numbers, memory
addresses, source code statements and a cross-reference listing of symbols and variables used in a program.
The most popular assemblers for the Intel family are MASM (Microsoft Assembler), TASM (Turbo
Assembler).
LINKER
A companion program that combines individual files created by an assembler into a single executable
file
DEBUGGER
A program that provides a way for a programmer to trace the execution of a program, and examine
the contents of memory.
MICROPROCESSOR ARCHITECTURE
As assembly language is microprocessor specific, so before writing assembly language programs it is
required to know the architecture of that microprocessor.
8086 MICROPROCESSOR:
We will be studying the assembly language for the microprocessor 8086.
8086 microprocessor is a 16-bit microprocessor (a 16-bit microprocessor can operate on the 16-bits of
data at a time) having 16- bit registers.
16-bit data bus and 20-bit address bus.
It can access 1 MB of total memory.
To write the assembly language programs for 8086 microprocessor, we are required to know the internal
organization at least programming model.
PROGRAMMING MODEL:
The programming model of the 8086 through Pentium II is considered to be program visible because its
registers are used during application programming and are specified by the instruction.Other registers are
considered to be program invisible because they are not addressed directly during application programming, but
may be used indirectly during system programming.
REGISTERS CLASSIFICATION: The registers inside the microprocessor are classified according to the
function they perform.
In general, they are classified as
Data registers
Address registers
Segment register
Offset registers
Status register
SOME GENERAL PURPOSE REGISTERS:
General purpose register we already defined in the Lab #1.
PROGRAM SEGMENTS
A machine language program consists of instructions (code) and data.
A data structure called Stack is used by the microprocessor to implement procedure calls.
The program’s code, data and stack are loaded into different memory segments, called code segment,
data segment and the stack segment.
SEGMENT REGISTERS
To keep track of the various program segments, the 8086 microprocessor is equipped
with four segment registers to hold the segment numbers.
The CS, DS and SS registers contain the code, data and stack segment numbers respectively.
If a program needs to access a second data segment, it can use the ES (Extra Segment) register.
POINTER AND INDEX REGISTERS
The registers SP, BP, SI and DI normally points to (contain the offset address of) memory location.
These registers can be used in arithmetic and other operations.
SP (STACK POINTER)
The SP register contains the offset of the top of stack.
The SP and SS registers combine to form the complete address of the top of the stack.
BP (BASE POINTER)
The BP register contains an assumed offset from the SS register, as does the stack pointer.
The BP register is often used by a subroutine to locate variables that were passed on the stack by a
calling program.
The BP register can be used for other segment unlike SP register.
SI (SOURCE INDEX)
The SI register is used to point to memory locations in the data segment addressed by DS.
This register takes its name from the string movement instructions, in which the source string is pointed
to by the SI register.
DI (DESTINATION INDEX)
The DI register performs the same operation as the SI register.
The DI register acts as the destination for string movement instructions.
CONTROL REGISTER
IP (INSTRUCTION POINTER)
The IP register contains the offset of the next instruction to be executed within the current code segment.
The IP and CS registers combine to form the complete address of the next instruction.
FLAGS (FLAGS REGISTER)
This is a special register with individual bit positions assigned to show he status of the CPU or the
results of arithmetic operations.
Each relevant bit is given a name and others are undefined.
ASSEMBLY PROGRAM SYNTAX
Assembly language program consists of statements.
A statement is either an instruction to be executed when the program runs or a directive for the
assembler.
A program normally consists of three parts or segments.
DATA SEGMENT
Variables are declared in the data segment.
Each variable is assigned space in memory and may be initialized.
Exp:
A DW 3501H
It sets memory for a variable called A, and initialize it to 3501H.
DW - Define word (16 bits = 2 memory locations)
A DW (?) ; un- initialized variable
CODE SEGMENT
Program instructions are placed in the code segment. Instructions are actually organized into units called
procedures. Every procedure starts with a line.
Exp:
Main Proc;
Main is the name of procedure and PROC is the directive identify the start of the procedure
Main Endp;
Main is again the name of the procedure and Endp is the direcitive ; identifies the end of the
procedure
STACK SEGMENT
The stack segment is used for temporary storage of addresses and data. If no stack segment is declared,
an error message is generated, so there must be a stack segment even if the program doesn’t utilize the
stack.
These segments begin with the directives .stack, .code, and .data
PROGRAM SYNTAX
TITLE first program syntax
.Model Small ;Specifies the memory model used
.Stack 100H ;allocate 100H memory locations for stack
.Data ;start of the data segment
; Data definitions here
A DB ?
.Code ;start of the code segment
Main Proc ;start of the first procedure
; instructions here
……
Main Endp ;end of the first procedure
; Other procedures here
End Main ;end of the complete assembly program
BASIC DIRECTIVES
Following are the description of commonly used directives;
MODEL: It is used to specify the memory model used for program to identify the size of code and data
segments.
STACK: Defines the size of stack used in program
DATA: Defines the data segments for data used in the program. Mark the beginning of the data segment
CODE: Identifies the code segment which contains all the statements. Also .code marks the beginning of the
code segment.
PROC: Beginning of the procedure
ENDP: End of the procedure
END: End of assembly language program
BASIC MOV INSTRUCTION:
We already defined in the Lab#1
RESTRICTIONS:
Move between memory to memory is not allowed.
A number directly inside a segment register is not allowed.
Segment to segment registers, move is not allowed.
INPUT/OUTPUT OPERATIONS
To display a character is an output operation.
We actually want to display single character from the microprocessor to the screen.
We don’t have any instruction that perform this operation like printf in C language.
We actually use the service routines, which are already designed and assembled programs to perform the IO
operations.
There are two categories of service routines
Basic Input Output System (BIOS) routines
DOS routines
The BIOS routines are stored in ROM and interact directly with the I/O ports. We carry out basic screen
operations.
The DOS routines are the part of the operating system running into the system.
DOS routines can carry out more complex tasks, e.g. printing a character string.
DOS routines actually use the BIOS routines to perform direct I/O operations.
INT INSTRUCTION
INT instruction is used to invoke a DOS or BIOS routine. Syntax INT 10H ( BIOS routine call)
INT 21H (DOS routine call)
FUNCTION NUMBER & AH REGISTER
A routine is actually a collection of different functions.A function is a set of basic instructions, used to actually
perform the operation.
Q:When we call a routine, it means we are invoking a large number of DOS functions but which function?
A:A particular function is requested by placing a function number in the AH register and invoking INT 21H.
INT 21h:
This can be used to invoke large number of DOS functions. A particular function is requested by placing a
function number in the AH register and invoking INT 21h.
For E.g. following functions can be used in our program:
Function No. Routine
02h Single character output
Single Character Output
MOV AH,02H ; display character function
MOV DL,’?’ ; character is ‘?’
INT 21h ; character will be displayed
Sample Program
OBJECT:
Title a program that displays single character on screen.
SOURCE CODE:
.model small ;specify memory model
.stack 100h ; specify size of stack
.code ; start of the code segment
main proc ; start of the first procedure
mov ah,02h ; display a single character
mov dl,'A' ; transfer A to register dl
int 21h ; DOS routine interrupt
mov ah,4ch ; exit DOS function
int 21h
main endp
end main
Lab Task: Write a program to print single character on screen using data block. (Task performed in
class)
.model small
.data
char db 'A'
.code
start:
mov ax, @data
mov ds, ax
SCREENSHOT:
OBJECTIVE
To understand the concept of new line using carriage return, line feed and macros.
THEORY
INT 21h:
This can be used to invoke large number of DOS functions. A particular function is requested by placing a
function number in the AH register and invoking INT 21h.
For E.g. following functions can be used in our program:
Function No. Routine
1h Single key input
Examples:
Single Key Input
MOV AH,01H ; input key function
INT 21h
MACROS
A macro is a block of code that has been given a name and when the compiler encounters such name, it expands
the macro, copies the block of code at the place of invocation into the program. The text may contain
instructions or references to other macros.
The basic advantage of using a macro is to create new instructions. These macros can be a part of the program
or they can be written in a separate file and that file can be included in the program. There is a list of useful
macros which are helpful to be kept in the macro library of the assembly language compiler and these can be
used in other user programs.
These can also be written in the lines of code of the program without any name given to them.
Example:
CARRIAGE RETURN
This macro can be used for the purpose of carriage return.
CAR_RTN MACRO
MOV AH, 4CH
INT 21H
ENDM
Once declared and defined, this macro can be invoked anywhere in the program by the name CAR_RTN.The
name of the macro can be any string as defined by the user.
LINE FEED
This macro can be used to feed a new line in the output and is very useful as a new line is needed many times
during a formatted output.
NEW_LINE MACRO
MOV AH, 02H
MOV DL, 0DH
INT 21H
MOV DL, 0AH
INT 21H
ENDM
Once declared and defined, this macro can be invoked anywhere in the program to insert a new line. The name
of the macro can be any string as defined by the user.
LAB OBJECTIVE:
Task#1:Write a program that takes a single character input and displays it in a new line.(without macros)
SCREENSHOT:
Task#2:Write a program that takes a single character input and displays it in a new line.(using new_line macro)
SCREENSHOT:
LAB#4
OBJECTIVE
To understand the concept of displaying string in assembly language.
THEORY:
Function No. Routine
9h Character String Output
Example:
Character String Output
MOV AH, 09H ; input key function
MOV DX,OFFSET MSG ; moves the offset of the msg to the
register
INT 21h
STRINGS:
A string is a list of characters treated as a unit. In programming languages we denote a string constant by
using quotation marks, e.g. “Enter first number”.
In 8086 assembly language, single or double quotes may be used.
Defining String Variables
The following 3 definitions are equivalent ways of defining a string ‘abc’:
version1 db “abc” ; string constant
version2 db ‘a’, ‘b’, ‘c’ ; character constants
version3 db 97, 98, 99 ; ASCII codes
The first version uses the method of high level languages and simply encloses the string in quotes. This is the
preferred method.
The second version defines a string by specifying a list of the character constants that make up the string.
We may also combine the above methods to define a string as in the following example:message db “Hello
world”, 13, 10, ‘$’
STRING OUTPUT
MS-DOS provides subprogram number 9h to display strings which are terminated by the ‘$’ character. In order
to use it we must:
1. Ensure the string is terminated with the ‘$’ character.
2. Specify the string to be displayed by storing its address in the dx register.
3. Specify the string output subprogram by storing 9h in ah.
4. Use int 21h to call MS-DOS to execute subprogram 9h.
5.
Keyword : MSG
The message to be displayed in the output can also be declared in the data segment using the keyword
MSG, moving the string in the register DB and can be used afterwards.
MSG DB ‘HELLO!$’
The “$” marks the end of the string and is not displayed. If the string contains the ASCII code of a control
character, the control function is performed.
Sample Program
SOURCE CODE:
LAB OBJECTIVES:
TASK#1: Write a program to display your bio data using carriage return and line feed macro
LAB#5
OBJECTIVE:
THEORY
Loop
A loop is a sequence of instructions that is repeated. The number of times to repeat may be known in advance,
or it may depend on conditions i.e. it’s a count controlled loop.
FOR Loop
This is a loop structure in which the loop statements are repeated a known number of times.
KEYWORD: LOOP
A FOR loop is implemented using the LOOP instruction. The counter for the loop is the CX register, which is
initialized to loop_count, which is the number of times the loop is executed. Execution of the LOOP instruction
causes CX to be decremented automatically. If CX becomes 0,the next instruction after loop is done.
Sample Program:
SOURCE CODE:
Object:Title a program that prints a character 100 times.
.model small
.stack 100h
.code
main proc
Initialize
count
Statements
count= count - 1
False
count= 0
True
LAB OBJECTIVES:
Task #01:Write a program to print ‘*’ 100 times using linefeed and carriage return.