lab 2
lab 2
USES:
• Assembly language is used most often when either communicating with the operating
system or directly accessing computer hardware.
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.
SEGMENT AND OFFSET REGISTERS:
• Address registers store addresses of instructions and data in memory.
• These values are used by the microprocessor to access memory locations.
• Every memory location is actually identified by an address of 20-bit.
• We are have the registers of 16-bits son that over 20-bit address (Physical Address) is store
into two parts in two 16-bit registers called segment number and offset
• A memory segment is a block of 2^16 (64 K) consecutive memory bytes.
• A segment number, called segment address (starting with 0) identifies each segment.
• A segment number is 16 bits so the highest segment number is FFFFh.
• Within segment, giving an offset number called the offset identifies a memory location.
• This is the number of bytes from the beginning of the segment.
• With a 64KB segment, the offset can be given as a 16-bit number.
• The first byte in a segment has offset 0.
• The last offset in a segment is FFFFh.
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.
• 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.
• 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 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.
• 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 ?
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:
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)