Faculty of Engineering, Science & Technology (Fest) : ELT-233A, Micro-Processor (Lab)
Faculty of Engineering, Science & Technology (Fest) : ELT-233A, Micro-Processor (Lab)
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
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.
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
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)
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.
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
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
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
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
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
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
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.
This function works as same as the function of 01H but it not display the press character on screen.
This function displays the signal character whose ASCII Code value is present in DL register.
MOV AH, 02H ; Move the single character output function into AH register
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
.CODE
When the program terminate (end) the control must return back to the DOS. This is done by 4CH 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.
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))
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))
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
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 dl, BH
mov ah, 02h
int 21h
mov dl, BL
mov ah, 02h
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.
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
LP2:
INC SI
LOOP SP1
PRINT MSG2
PRINT MSG2
PRINT BUFF+2
MOV AH,4CH
INT 21H
CODE ENDS
END START
.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.
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.
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
.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