Practical Lab 7
Practical Lab 7
Practical Lab 7
Modes
Introduction:
Objectives:
Addressing Modes:
The following table summarizes all addressing modes used by the 8086 processor.
.STACK
Assembler directive that reserves a memory space for program instructions
in the stack
.DATA
Assembler directive that reserves a memory space for constants and variables
.CODE
Assembler directive that defines the program instructions
END
Assembler directive that finishes the assembler program
Each of the segments is called a logical segment. Depending on the memory, the code
and data segments may be in the same or in different physical segments according to
table 7.2.
Memory
Model Size of Code and Data
Memory allocation:
Code Segment:
- Directive is .code for code segment
- The "program" resides here
End of Program:
- Directive is End
- Tells assembler that this is the end of the program
Note:
The sequence of instructions at the beginning of a program used to assign the data
segment:
MOV AX, @DATA
MOV DS, AX
.STARTUP
which assigns both DATA and CODE segments, and hence no warning will be issued
by the assembler. However, it should be noted that the program would start at address
CS:0017h. The Startup directive occupies the bytes CS:0000 to CS:0017.
Identically, the sequence used to terminate and exit to DOS can be replaced by the
.EXIT directive, which has exactly the same effect.
Pre Lab Work:
1. Study the attached hand out, and review the material related to
segmentation and addressing modes.
2. Write programs 7-1 and 7-2
3. Write the program given in assignment.
4. Fill in the tables associated with the different programs.
5. Bring your work to the lab.
Lab Work:
1- Fill in table 2, associated with program 2, in which you specify only the
addressing mode, for both source and destination, for each instruction.
Lab Assignment:
Write a program that prompts the user to enter a string, in capital letters, of a
maximum length of 20 characters. Read the string in capital letters and convert it to
small letters. Then display the new string.
Note:
To convert a capital letter to a small one, use the following instruction:
;Read character
MOV AL, character_read
ADD AL, 20H
; Display character in AL register
Use the following to loop through the string you just entered.
LOOP Again
; This program displays a string terminated by a $ sign using INT 21H function 09H.
.STACK 200
.DATA
MESSAGE DB ‘This is the message to be displayed: ’, ‘$’
MESSAGE2 DB ‘The message you just entered : ;’ , ‘$’
BUF DB 10 ; Number of characters to be read
DB 10 DUP(?); Reserve 10 bytes for string
.CODE
MOV AX,@DATA
MOV DS,AX
LEA DX,MESSAGE
MOV AH,09H
INT 21H
MOV AH, 0AH
MOV DX, OFFSET BUF
INT 21H
LEA DX,MESSAGE2
MOV AH,09H
INT 21H
MOV AX,4C00H
INT 21H
END
TITLE “PROGRAM 2 EXPERIMENT 7”
; This program displays a message and reads a new message from the keyboard
.MODEL SMALL
.STACK 200
.DATA
CRLF DB 0DH,0AH,'$'
PROMPT DB 'Enter a name of max. length 30 char.: ',0DH,0AH,'$'
STRING1 DB 'Mr. ','$'
STRING2 DB ' studies 8086 programming. ','$'
; Allocate 32 bytes for BUFFER, and put the value 31 in the second byte.
BUFFER DB 31,32 DUP(?)
.CODE
.STARTUP ;This directive initializes the DS and CS segments.
LEA DX,PROMPT ;display prompt
MOV AH,09H
INT 21H
MOV AH,09H
MOV BH,00H
MOV BL,BUFFER[1] ;move in BL buffer length
MOV BUFFER[BX+2],'$' ;put a $ sign at the end of buf
LEA DX,BUFFER[2] ;load actual length of buffer
INT 21H
Section:
Student ID:
Section:
Student ID:
Addressing Modes
Instructions
Source Destination
LEA DX,PROMPT
MOV AH,09H
INT 21H
MOV AH,0AH
LEA DX, BUFFER
INT 21H
LEA DX, CRLF
MOV AH,09H
INT 21H
LEA DX,STRING1
MOV AH,09H
INT 21H
MOV AH,09H
MOV BH,00H
MOV BL,BUFFER[1]
MOV BUFFER[BX+2],'$'
LEA DX,BUFFER[2]
INT 21H
LEA DX,STRING2
MOV AH,09H
INT 21H
LEA DX, CRLF
MOV AH,09H
INT 21H
MOV AH, 02H
MOV DL,BUFFER[1]
ADD DL, 30H
INT 21H
MOV AX,4C00H
INT 21H