0% found this document useful (0 votes)
57 views18 pages

Faculty of Engineering, Science & Technology (Fest) : ELT-233A, Micro-Processor (Lab)

The document discusses various input and output instructions in assembly language that interface with the operating system via interrupts. [1] It describes functions like INT 21H function 01H for single character input with echo, function 07H for input without echo, and function 02H for single character output. [2] It also covers function 09H for string output and function 4CH to return program control to DOS. [3] Key concepts explained are using the AH register to specify functions and invoking interrupts to interface with the operating system for input/output.

Uploaded by

saadat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views18 pages

Faculty of Engineering, Science & Technology (Fest) : ELT-233A, Micro-Processor (Lab)

The document discusses various input and output instructions in assembly language that interface with the operating system via interrupts. [1] It describes functions like INT 21H function 01H for single character input with echo, function 07H for input without echo, and function 02H for single character output. [2] It also covers function 09H for string output and function 4CH to return program control to DOS. [3] Key concepts explained are using the AH register to specify functions and invoking interrupts to interface with the operating system for input/output.

Uploaded by

saadat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

ZIAUDDIN UNIVERSITY FACULTY OF ENGINEERING SCIENCE

TECHNOLOGY AND MANAGEMENT SEMESTER IV

FACULTY OF ENGINEERING, SCIENCE & TECHNOLOGY (FEST)


ELT-233A, Micro-Processor (Lab)
Table of contents
S.NO Date EXPERIMENTS Sign Remarks
.

1
13-4-21 Introduction to Assembly and Assembler

3
13-4-21 Input and Output instructions

5
14-4-21 Multiplication & Division
VLSI FEST Indus University

MICROPROCESSOR AND MICROCONTROLLERS


Lab # 01
Introduction To Assembly and Assemble

OBJECTIVE:
Developing basic understanding about Assembly and Assembler (emu8086)

INTRODUCTION:

Programming Languages
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 Languages


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:

1. High Level Languages


A programming language that enables a programmer to write programs that are more or less independent
of a particular type of computer and are designed to give a better program efficiency. Such languages are
considered high-level because they are closer to human languages.

2. Low Level Languages


These are designed to have both: a relatively good programming efficiency and relatively good machine
efficiency.

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 In general,
they are classified as
1. Data registers
2. Address registers
3. Segment register
4. Offset registers
5. Status register

Some General Purpose Registers:

AX (Accumulator Register)
VLSI FEST Indus University

· 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)

· It is used to store the data also it serves as an address register.

CX (Count 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)
· It is used in multiplication and division operations.
· It is used in IO operation like DL in character output and DX in string output functions.

Register Size:
· We have three different sizes of registers:
· 8-bit register: AH, AL, BH, BL, CH, CL, DH, DL
· 16-bit registers: AX, BX, CX, DX, SP, BP, SI, DI, SS, DS, CS, ES, FS, GS, IP, FLAGS
· 32-bit registers: EAX, EXB, ECX, EDX, ESI, EDI, ESP, EBP, EIP, and EFLAGS.

Basic MOV Instruction


· 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, Source

Examples:
· MOV AH, BL; 8-bits register to register
· MOV BX, AX; 16-bits register to register
· MOV byte1, BL; 8-bit register to memory.
· MOV AX, word1 ;16-bit memory to register

Code to Display String

TITLE LAB01
.MODEL SMALL
.STACK 100H
.DATA
MESSAGE1 DB 0AH, 0DH, "INDUS UNIVERSITY$"
VLSI FEST Indus University

.CODE
MAIN:
MOV AX, @DATA
MOV DS, AX
MOV DX, OFFSET MESSAGE1
MOV AH, 09H
INT 21H

MOV AH, 4CH


INT 21H
END MAIN

Procedure
· Open a notepad editor and create a new file with any name but with the extension “.asm”,eg
lab1.asm. save it to bin folder of tasm.
· Now copy and paste the following code into that file and save again
· Goto command prompt and type cd c:\tasm\bin
· Now type “tasm filename.asm” and press enter
· Now type “tlink filename.obj” and press enter
· Now type “filename.exe” and hit enter
·
· Example :

Lab Tasks

1. Write a program to display your complete name on the screen

CODE:
section .data
msg db "Saadat Irfan", 0ah
VLSI FEST Indus University

section .text
global _start

_start:
mov rax, 1
mov rdi, 1
mov rsi, msg
mov rdx, 13
syscall
mov rax, 60
mov rdi, 0
syscall
2. Write a program to display you complete enrolment number on screen

CODE:
section .data
msg db "4-15/2019/010", 0ah

section .text
global _start

_start:
mov rax, 1
mov rdi, 1
mov rsi, msg
mov rdx, 13
syscall
mov rax, 60
mov rdi, 0
syscall
3. Test your code after removing the $ sign from the string

A) As per the observation after removing $ symbol from the code there was no significant change
noticed in output.

Lab #03
VLSI FEST Indus University

Input and Output Instruction


Objective
 Understand the working of INT 21H instruction
 Understand program having basic Input and Output Instruction

Theory
The processor cannot access the peripheral devices (like keyboard or monitor) directly. Microprocessor use BIOS
routines or DOS routines to access peripherals. The BIOS (Basic Input/Output System) routines are store in ROM
and directly run the I/O ports where DOS routine use BIOS routine to perform operation that’s why has less
complex than BIOS routine.
The BIOS and DOS both use INT (Interrupt) instruction, the interrupt is actually done by number
which determine nature of interrupt. The format of interrupt instruction is:
INT interrupt number
e.g. INT 21H ; Invoke DOS routine
INT 16H ; Invoke BIOS routine

Some
INT
Function Number Routine 21H

01H Take input with echo


02H Display character
07H Take input without echo
09H Display string
4CH Control back to DOS

0BH Check standard input status

2AH Get system Date


Get system Time
2CH
Function

When INT 21H execute the DOS first see the function number in AH register, so all the function number must be
placed in AH register to execute.
VLSI FEST Indus University

Function 01H (Single character input with echo)

After instruction executes, the AL register get the ASCII Code of the character and if non-character key (control
key) is press then than AL register get 00H. The 01H function also displays the character on screen.

MOV AH, 01H ; Move input key function to AH register

INT 21H ; Invoke DOS interrupt

Function 07H (Single character input without echo)

This function works as same as the function of 01H but it not display the press character on screen.

Function 02H (Single character output)

This function displays the signal character whose ASCII Code value is present in DL register.

MOV DL,’A’ ; Move the ASCII code of A ( A = 41H) in DL register

MOV AH, 02H ; Move the single character output function into AH register

INT 21H ; Invoke DOS interrupt

Function 09H (Display string)

The function display the string which is terminated by $ sign present in Data segment register. Data Segment
address is store in DS register and DX register store the offset address of the string to display.

.DATA

MESSAGE DB 0AH, 0DH,”INDUS UNIVERSITY$”

.CODE

MOV AX,@DATA ; Get address of DATA segment

MOV DS, AX ; Move address of DATA segment into DS register

MOV DX, OFFSET MESSAGE ;Get offset address of MESSAGE

MOV AH, 09H ;Move display string function into AH register

INT 21H ; Invoke DOS interrupt


VLSI FEST Indus University

Function 4CH (DOS exit function)

When the program terminate (end) the control must return back to the DOS. This is done by 4CH function.

MOV AH, 4CH ; Move return to DOS function into AH register

INT 21H ; Invoke DOS interrupt

Function 0BH (Check for Character available function)

This function is used to check any available character of keyboard. This function return two values in AL register, if
it’s 00H then no character available and if it’s FFH then a character available.

MOV AH, 0BH ; Check for any Character available

INT 21H ; Invoke DOS interrupt

Function 2AH (Get system Date function)

This function returns the Date of the system. The return values are store in varies registers that are CX (year (1980-
2099)), DH (month (00-11)), DL (day (0-30)) and AL (day of the week (00 for Sunday))

MOV AH, 2CH ; Get current time of the system

INT 21H ; Invoke DOS interrupt

Function 2CH (Get system Time function)

This function return the time of the system. The return values store in varies registers that are CH (hour (0-23)), CL
(minutes (0-59)), DH (second (0-59)) and DL (1/100 second (0-99))

MOV AH, 2CH ; Get current time of the system

INT 21H ; Invoke DOS interrupt

Hour store in CH register, Minutes store in CL register, Second store in DH register and milli-second store in DL
register.

Tasks:
1- Write a program to take 4 character input from user and display user input on screen

A)
mov ax, @data
mov ds, ax

mov dx, offset a


mov ah, 09h
int 21h

mov ah, 01h


VLSI FEST Indus University

int 21h

MOV BH, AL
mov ah, 01h
int 21h

MOV CH, AL
mov Ch, 01h
int 21h

MOV DH, AL
mov DH, 01h
int 21h

MOV BL, AL

mov dx, offset b


mov ah, 09h
int 21h

mov dl, BH
mov ah, 02h
int 21h
mov dl, BL
mov ah, 02h
int 21h

mov dx, offset c


mov ah, 09h
int 21h

ret

mov DL, 13
mov ah, 02h
int 21h
mov DL, 10
mov ah, 02h
int 21h
ret
VLSI FEST Indus University

2- Write a password program, in which take input from user and display **** instead. (4 Character
password)

A) password:
mov ah, 07h
int 21h
cmp al,0dh
mov b[si],al
inc si
mov dl, '*'
mov ah,2
int 21h
jmp password

3- Write case conversion program, in which user enters small case character and program
converts it to upper case.

A) READ MACRO MSG


MOV AH,0AH
LEA DX,MSG
INT 21H
ENDM

PRINT MACRO MSG


MOV AH,09H
LEA DX,MSG
INT 21H
ENDM

DATA SEGMENT
CR EQU 0DH
LF EQU 0AH
MSG1 DB \"ENTER THE STRING IN LOWERCASE:$\"
MSG2 DB CR,LF,\"THE UPPERCASE STRING IS :$\"

BUFF DB 255
DB 0
DB 255 DUP (\'$\')
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
PRINT MSG1
READ BUFF
MOV SI,OFFSET BUFF+2
MOV CL,BYTEPTR[SI-1]
MOV CH,00H
VLSI FEST Indus University

LP1: MOV AH,[SI]


MOV AL,61H
JB LP1
CMP AL,7BH
JNB LP1
SUB AL,20H
MOV [SI],AL

LP2:
INC SI
LOOP SP1
PRINT MSG2
PRINT MSG2
PRINT BUFF+2
MOV AH,4CH
INT 21H
CODE ENDS
END START

4- Write a program to display system date


A) .MODEL SMALL

.STACK 64

.DATA
EN_DATE DB \'ENTER DATE (dd-mm-yyyy): $\'
MSGDAY DB \'DAY : $\'
MSGMONTH DB \'MONTH : $\'
NL DB 0DH,0AH,\'$\'
DAY DB \' \',\'$\'
MONTH DB \' \',\'$\'
.CODE

MAIN PROC
MOV AX,@DATA
MOV DS,AX

LEA DX,EN_DATE
MOV AH,09H
INT 21H
LEA SI,DAY
READ_DAY:
MOV AH,01H
INT 21H
CMP AL,2DH
JE F_READ_DAY

MOV [SI],AL

INC SI
JMP READ_DAY

F_READ_DAY:
INC SI
MOV AL,\'$\'
MOV [SI],AL
VLSI FEST Indus University

LEA SI,MONTH

READ_MONTH:
MOV AH,01H
INT 21H

CMP AL,2DH
JE F_READ_MONTH

MOV [SI],AL

INC SI
JMP READ_MONTH
F_READ_MONTH:
INC SI
MOV AL,\'$\'
MOV [SI],AL
MOV CL,04H
READ_YEAR:
MOV AH,01H
INT 21H
LOOP READ_YEAR
DISP:
LEA DX,NL
MOV AH,09H
INT 21H

LEA DX,MSGDAY
INT 21H

LEA DX,NL
INT 21H

LEA DX,DAY
INT 21H

LEA DX,NL
INT 21H

LEA DX,MSGMONTH
INT 21H

LEA DX,NL
INT 21H

LEA DX,MONTH
INT 21H

MOV AH,4CH
INT 21H

MAIN ENDP
END MAIN
VLSI FEST Indus University

EXPERIMENT 05
Multiplication and Division Instructions
Objective
 Understand Multiplication and Division instructions
 Working of ASCII adjust instruction

Theory

Multiplication Instruction
There are two instructions for multiplication, MUL (Multiplication) and IMUL (Integer Multiplication)
Instruction.
Instruction format are:
MUL Source ; Unsigned multiplication
IMUL Source ; Integer multiplication for Signed number
The source may be a register or memory but not a constant. Also the source value and the multiplying
value should be of same magnitude.

Byte Form Multiplication


In the byte form of multiplication one number should present in source and other in AL register.
The result may be of 16-bit (1 word) which is stored in AX register.

Word Form Multiplication


In the word form of multiplication one number is present in source and other is in AX register. The
result may be of 32-bit (Double word) so most significant 16-bit goes in DX and least significant 16-bit
goes to AX register.

AAM (ASCII Adjust for Multiplication) Instruction


The AAM instruction converts the result of two BCD digit multiplications into unpacked BCD format.
This instruction convert the result into BCD whose value is lower then 100 D or 64H, this is because the
result is store in AX register in the unpacked form that are AL and AH so largest value is 99 D which
store as AH = 09 and AL = 09 . The operation for the instruction is the result which is store in AL
register is divided by 10D and the quotient store in AL register and while remainder store in AH
register.

E.g. MUL Instruction


MOV AL, 05H ; Move value in AL which is source
MOV BL, 07H ; Move value in BL which is source
VLSI FEST Indus University

MUL BL ; AX = 05H x 07H = 23H


AAM ; AX = 0305H (5 x 7 = 35)
E.g. IMUL Instruction
MOV AL,-01D ; AL = FFH
MOV BL,-01D ; BL = FFH
IMUL BL ; AX = FF H x FF H = 0001H
VLSI FEST Indus University

Division Instruction
Like wise multiplication instruction there are two division instruction which are DIV (Division) and IDIV
(Integer Division) Instruction.
Instruction format are:
DIV Divisor ; Unsigned Division
IDIV Divisor ; Integer Division for Signed number
The source may be a register or memory but not a constant as in multiplication instruction. If dividend
is of 16-bit then divisor is of 8-bit also if dividend is of 32-bit then divisor is of 16-bit. For signed
division, the remainder has the same sign as the sign of dividend.

Byte Form Division


In the byte form of division the 16-bit dividend is placed in AX register and the divisor is in 8-bit
register. After division the 8-bit quotient is in AL register while 8-bit remainder in AH register.

Word Form Division


In the word form of division the 32-bit dividend is DX (higher bits of word) and AX (lower bits of
word) registers and divisor is in 16-bit register. After division the 16-bit quotient is in AX register
while 16-bit remainder in DX registers.

E.g. DIV Instruction


MOV AX, 0009H ; AX = 0009H
MOV BL, 02H ; BL = 02H
DIV BL ; AX = AX / BL (AX = 0104H where 04 in AL is quotient and 01 in AH
is remainder)
E.g. IDIV Instruction
MOV AX, -0009D ; AX = -0009D
MOV BL, 07H ; BL = 07H
IDIV BL ; AX = AX / BL (AX = FEFFH where FF in AL is quotient and FE in
AH is remainder)

AAD (ASCII adjust for division) Instruction


The AAD instruction converts the unpacked BCD into binary and store in AL or converts unpacked
BCD into packed BCD and store in AL. From the AX register the AH register is multiply by 10 D or
0AH then add it to AL register it also clear the AH register.

MOV AX, 0302H ; DIVIDEND (32 in unpacked form)


AAD ; AX = 0020H
MOV BL, 4 ; DIVISOR
DIV BL ; AX = 0008H (32 / 4 = 8)
VLSI FEST Indus University
VLSI FEST Indus University

Multiplication and Division Instruction table


Function Instruction syntax Operation Registers used in Registers used to
type Operation store result
Source may be register The 16-bits (1 word)
Multiplication MUL Source Byte byte or memory byte result store in
for unsigned and second byte in AX register
Format
number AL register
Source may be word The result is of 32-bits
IMUL Source register or memory (double word). The most
for signed word and second word significant 16-bits store
Word
number in AX register in DX register while the
Format least significant 16-bits
[1] store in AX register
The 8-bits Divisor The 8-bits (1 byte)
Division DIV Divisor Byte store in register byte or quotient store in AL and
for unsigned Format memory byte and 16-
8-bits remainder store in
number bits dividend store in
AX register AH register
IDIV Divisor The 16-bit Divisor The 16-bit (1 word)
for signed Word store in register word Quotient store in AX and
number Format or memory word and
16-bits remainder store in
[2] 32-bit dividend store in
DX:AX registers DX register
Note: For IMUL and IDIV if the sign bit for number is set then its 2`s complement will taken for calculation. And
also if the sign for both the numbers are same then after calculation the result will store directly and if the sign are
different then the 2`s complement of result will store.

Exercise
1) Write a program to generate the following sequence
(1, 2, 4, 8, 16)

A) .model small
.stack 100H
.data
.code

call proc

mov cx,5

mov dx,0
L1:
mov bx,2
add dx,bx
mov ah,02h
loop L1
int 21
endp
VLSI FEST Indus University

2) Write a program to generate the following sequence


(16, 8, 4, 2, 1)

.model small
.stack 100H
.data
.code

call proc

mov cx,0

mov dx,5
L1:
mov bx,2
add dx,bx
mov ah,02h
loop L1
int 21
endp

You might also like