Lab Manual 4
Lab Manual 4
Introduction
Overview
Memory has always had a key role to play with microprocessor based systems
since microprocessor manipulates data and memory stores it. Segmentation of memory
(Logical or physical) deals with storage of the data (or program) in memory while the
addressing modes are related with the process to retrieve that stored data from memory.
Let’s first see the segmentation of memory and the directives used to do that.
Assembler directive that defines the memory model to be used in the .MODEL
program. The memory model determines the size of the code, stack and
data segments of the program
Assembler directive that reserves a memory space called stack .STACK
segment for use of program instructions (during interrupts and
function calls)
Assembler directive that reserves a memory space called data .DATA
segment for constants and variables being used in program
Assembler directive that reserves space called code segment for .CODE
storage of program instructions in memory
Assembler directive that finishes the assembly program END
.MODEL DIRECTIVE
A few assembly language memory models are tabulated on the basis of the physical
memory they require.
Since the allowed physical memory space with an 8086 based processor is 1MB,
which means we need to have 20 bits address registers (2²⁰ = 1 MB) to retrieve data from
the memory, we only have registers that are 16 bits wide. The solution is, use segmented
memory model and generate the physical address using two registers, Segment register
and offset register. Consider the following example of address generation.
.model small
.stack 100h
.data
var1 DB 10
.code
…
…
end
In this case var1 is the offset address and data segments address is segment address so total physical
address would be
But during programming we don’t have to care about this because assembly languages addressing
modes automatically caters for this. What we have to do is to initialize segment registers in the
start of the program. This can be done by following lines of code
.STARTUP
This automatically initializes the CS and DS registers with correct location of code and data
segment respectively.
2. Calculate both the logical and physical addresses of each instruction. Put the results on the
given table.
MOV AX,@DATA
MOV DS,AX
LEA DX,MESSAGE1
MOV AH,09H
After INT 21H, IP = Before INT 21H, IP = INT21H
MOV AH, 0AH
MOV DX, OFFSET
BUF
After INT 21H, IP = Before INT 21H, IP = INT21H
LEA
DX,MESSAGE2
MOV AH,09H
MOV AH,09H
Compare instruction:
Jump Instructions:
The jump instructions are used to transfer the flow of the process to the indicated operator.
When the jump address is within the same segment, the jump is called intra- segment jump.
When this address is outside the current segment, the jump is called inter- segment jump.
An overview of all the jump instructions is given in Table 5. 2.
Like the conditional and unconditional jump instructions which can be used to
simulate the IF-Then-Else structure of any programming language, the Loop
instructions can be used to simulate the Repeat-Until and While-Do loops. These are
used as shown in the following (Table 5. 6).
TASK 2
Write a program that takes a number input between 0 and 9 and then
displays corresponding grade If grade is less than 5 it should display
Grade C If grade is less than 7 it should display Grade B If grade is
greater than or equal 7 it should display Grade A. The program should
continue to run until the user enters a negative number or a number
greater than 9. Attach screenshot of all cases.
TASK 3
Write a program that adds the following series and places results in AX.
• 95+90+85+…+5