Coal Lab Manual
Coal Lab Manual
Student Name:
Class and Section:
Roll Number:
CGPA:
Email ID:
GENERAL INSTRUCTIONS
a. Students are required to maintain the lab manual with them till the end of the semester.
b. All readings, answers to questions and illustrations must be solved on the place provided. If more space
is required, then additional sheets may be attached. You may add screen print to the report by using the
‘Print Screen’ command on your keyboard to get a snapshot of the displayed output.
c. It is the responsibility of the student to have the manual graded before deadlines as given by the instructor.
d. Loss of manual will result in re submission of the complete manual.
e. Students are required to go through the experiment before coming to the lab session.
f. Students must bring the manual in each lab.
g. Keep the manual neat clean and presentable.
h. Plagiarism is strictly forbidden. No credit will be given if a lab session is plagiarised and no re-
submission will be entertained.
i. Marks will be deducted for late submission.
j. You need to submit the report even if you have demonstrated the exercises to the lab instructor or shown
them the lab report during the lab session.
VERSION HISTORY
Month Update By Details
July 2015 Muhammad Bilal Mushtaq Version 1.0. Initial draft prepared and experiments outlined.
Sept 2017 Nida Tasneem Version 1.1. Improvements added in the manual
Sept 2018 Nida Tasneem Version 1.2. Formatting corrected.
August 2019 Nida Tasneem 14 sessions, theoretical portion and activities are also added.
Umar Mahmud
2 10
3 10
4 10
5 10
6 10
7 10
8 10
9 10
10 10
11 10
12 10
13 10
14 10
Grand Total
OBJECTIVE
Introduction to microprocessor lab, system and kits and software. Student will get use to the software and
lab equipment, trainers and get use to the lab environment.
TIME REQUIRED : 3 hrs
PROGRAMMING LANGUAGE : NIL
SOFTWARE REQUIRED : Emulator 8086, DOS, Debug
HARDWARE REQUIRED : Core i5 in Computer Labs, MDA – Win8086
INTRODUCTION TO ASSEMBLY LANGUAGE
Assembly language is a low-level programming language.
You need to get some knowledge about computer structure in
order to understand anything. The system bus (shown in
yellow) connects the various components of a computer. The
CPU is the heart of the computer, most of computations
occurs inside the CPU. RAM is a place to where the
programs are loaded in order to be executed.
8086 MICRO-PROCESSOR
We will be studying the assembly language for the microprocessor 8086.
8086 micro-processor 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.
INSIDE A CPU
To write the assembly language programs for 8086 micro-processor, we are required to know the internal
organization at least programming model
GENERAL PURPOSE REGISTERS
8086 CPU has 8 general purpose registers, each register has its own name:
AX - the accumulator register (divided into AH / AL).
BX - the base address register (divided into BH / BL).
CX - the count register (divided into CH / CL).
DX - the data register (divided into DH / DL).
SI - source index register.
The address formed with 2 registers is called an effective address. By default, BX, SI and DI registers work
with DS segment register; BP and SP work with SS segment register.
Other general-purpose registers cannot form an effective address! Also, although BX can form an effective
address, BH and BL cannot!
SPECIAL PURPOSE REGISTERS
IP - the instruction pointer.
Flags Register - determines the current state of the processor.
IP register always works together with CS segment register and it points to currently executing instruction.
Flags Register is modified automatically by CPU after mathematical operations, this allows to determine the
type of the result, and to determine conditions to transfer control to other parts of the program. Generally,
you cannot access these registers directly.
REGISTERS CLASSIFICATIONS
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 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.
SEGMENT AND OFFSET REGISTER
RESOURCES:
https://www.youtube.com/watch?v=wLXIWKUWpSs
https://www.tutorialspoint.com/assembly_programming/assembly_introduction.htm
OBJECTIVE
In this lab, an introduction of Emu8086 will be given. Also, the Hello World Program will be explained to
make students understand how programs are written in Emu8086 using Assembly Language.
TIME REQUIRED : 3 hrs
PROGRAMMING LANGUAGE : Assembly Language
SOFTWARE REQUIRED : Emulator 8086, DOS, Debug
HARDWARE REQUIRED : Core i5 in Computer Labs, MDA – Win8086
INTRODUCTION
Emu8086 is a program that compiles the source code (assembly language) and executes it. You can watch
registers, flags and memory while your program executes. Arithmetic & Logical Unit (ALU) shows the
internal work of the central processor unit (CPU). Emulator runs programs on a Virtual PC; this completely
blocks your program from accessing real hardware, such as hard-drives and memory, 8086 machine code is
fully compatible with all next generations of Intel's microprocessors.
WHERE TO START?
Start Emu8086 by selecting its icon from the start menu, or by running Emu8086.exe.
Select "Samples" from "File" menu.
Click [Compile and Emulate] button (or press F5 hot key).
Click [Single Step] button (or press F8 hot key) and watch how the code is being executed.
Try opening other samples, all samples are heavily commented, so it's a great learning tool.
DIRECTIVES
ORG 100h is a compiler directive (it tells compiler how to handle the source code). This directive is very
important when you work with variables. It says to compiler that the executable file will be loaded at the
offset of 100h (256 bytes), so compiler should calculate the correct address for all variables when it replaces
the variable names with their offsets. Directives are never converted to any real machine code.
Why executable file is loaded at offset of 100h? Operating system keeps some data about the program in the
first 256 bytes of the CS (code segment), such as command line parameters etc. Offset is used to get the
offset address of the variable in register specified
MOV INSTRUCTION
Copies the second operand (source) to the first operand (destination).
The source operand can be an immediate value, general-purpose register or memory location.
The destination register can be a general-purpose register, or memory location.
Both operands must be the same size, which can be a byte or a word.
RESOURCES:
Download: https://download.cnet.com/Emu8086-Microprocessor-Emulator/3000-2069_4-10392690.html
https://www.youtube.com/watch?v=vlSjuq5BoG0
https://www.tutorialspoint.com/assembly_programming/assembly_introduction.htm
OBJECTIVE
In this lab students will learn registers and practice how to Input, Output and Display Characters as well as
strings.
TIME REQUIRED : 3 hrs
PROGRAMMING LANGUAGE : Assembly Language
SOFTWARE REQUIRED : Emulator 8086, DOS, Debug
HARDWARE REQUIRED : Core i5 in Computer Labs, MDA – Win8086
REGISTERS
Registers are high-speed storage locations directly inside the CPU, designed to be accessed at much higher
speed than conventional memory.
TYPES OF REGISTERS
General purpose Registers
Segment Registers
Status Flags Register
Instruction Pointer
GENERAL PURPOSE REGISTER: Can be divided into Data and Index
Data Registers: Are used for arithmetic and data movement
◾ AX (Accumulator register)
◾ BX (Base Register)
◾ CX (Counter Register)
◾ DX (Data Register)
Index Register: Contains the offsets of data and instructions.
◾ BP (Base pointer Register)
◾ SP (Stack pointer Register)
◾ SI (Source Index Register)
◾ DI (Destination Index Register)
AX (ACCUMULATOR)
Used to store the temporary result after arithmetic or logic operation.
Can be accessed as 32 bit (EAX), 16 bit (AX) or 8bit (AH or AL) register.
General Purpose Use in MOV, ADD, SUB instrs.
Special Purpose Use in MUL, DIV, etc.
General Purpose Use of AX register
16 Experiment 3 – Register, Input/Output Characters and Display Strings
ACTIVITY 3.1: ADDITION OF BINARY DIGITS
.code
main
proc
MOV AL,01001011b
MOV BL,00000011b
ADD AL,BL
MOV DL, AL
MOV AH,2H
INT 21H
MOV ax,4C00h
INT 21H
main endp
end main
Execute and write the outcome of Activity 3.1 here: -
CX (COUNT REGISTER)
Contains the count for certain instructions e,g shift count, rotate the number of bytes and a counter
with loop instruction.
Can be accessed as 32 bit (ECX), 16 bit (CX) or 8 bit (CH or CL) register 32 bit
General Purpose use in ADD, MUL, DIV, MOV
Special Purpose use in LOOP etc.
ACTIVITY 3.2
.code
main
proc
MOV CL,12
MOV BL,65
AGN:INC BL
MOV DL, BL
MOV AH,2H
INT 21H
LOOP AGN
MOV ax,4C00h
INT 21H
17 Experiment 3 – Register, Input/Output Characters and Display Strings
main endp
end main
.code
main
proc
mov dl, 'a'
mov ah,2h
INT 21H
mov ax,4C00h
INT 21H
main endp
19 Experiment 3 – Register, Input/Output Characters and Display Strings
end main
mov ax,4C00h
INT 21H
main endp
end main
STRING OUTPUT
A string is a list of characters treated as a unit.
In 8086 assembly language, single or double quotes may be used to denote a string constant.
For Defining String Variables following 3 definitions are equivalent ways of defining a string "abc":
◾ var1 db "abc" ; string constant
◾ var2 db ‘a’, ‘b’, ‘c’ ; character constants
◾ var3 db 97, 98, 99 ; ASCII codes
◾ The first version simply encloses the string in quotes. (preferred method)
◾ The second version defines a string by specifying a list of the character constants that make up
the string.
◾ The third version defines a string by specifying a list of the ASCII codes that make up the string
In order to display string using MS-DOS subprogram (number 9h), the string must be terminated
with the ‘$’ character.
In order to display a string we must know where the string begins and ends.
The beginning of string is given by obtaining its address using the offset operator.
The end of a string may be found by either knowing in advance the length of the string or by storing
a special character at the end of the string.
Write a program that input a character from user. The program will display it ten times on screen in
newline. Write program and outcome here: -
Write a program that will display uppercase letters (A-Z), using loop on new line.
RESOURCES
http://www.uobabylon.edu.iq/eprints/publication_1_26408_35.pdf
http://www1.frm.utn.edu.ar/arquitectura/t86.pdf
https://www.academia.edu/6933756/8086_Assembler_Tutorial_for_Beginners
http://people.vts.su.ac.rs/~pmiki/STOREnGO/ASM%20zbirka/emu8086.pdf
OBJECTIVES
To learn about signed and unsigned numbers
Practice how to Input, Output single and multi-digit number.
Addition and subtraction of numbers
TIME REQUIRED : 3 hrs
PROGRAMMING LANGUAGE : Assembly Language
SOFTWARE REQUIRED : Emulator 8086, DOS, Debug
HARDWARE REQUIRED : Core i5 in Computer Labs, MDA – Win8086
CHARACTER STORAGE
Computer stores binary numbers, so how character ‘A’ and ‘$’ are stored.
Computer uses character encoding scheme that translate numbers into letters.
Well-known scheme is ASCII (American Standard code for Information Interchange)
ASCII is 7 bit code with range 0 to 127.
SIGNED NUMBERS
Signed byte uses only 7 bits for its magnitude.
Highest bit is reserved for the sign, where 0 indicates positive and 1 indicates negative.
Example:
11110110 = - 10
00001010 = + 10
TWO’S COMPLEMENT NOTATION
Negative numbers use Two’s complement representation.
Removes the need for separate digital circuits to handle both addition and subtraction.
Example: A – B = A + (-B)
To find Twos complement, toggle all bits and add 1.
00000001 = + 1
11111110 (toggle all bits)
+ 1 (add 1)
11111111 = - 1
11110110 = - 10
ACTIVITY 4.1
Show the working of following instruction by taking the two’s complement
9–6 - =
146 – 9 - =
TWO’S COMPLEMENT OF HEXADECIMAL
To form the two’s complement of a hexadecimal integer, reverse all bits and add 1
Easy way to reverse the bits of a hexadecimal digit is to subtract the digit from 15.
Example:
6A3D --> 95C2 + 1 --> 95C3
ACTIVITY 4.2:
95C3
> + >
DE10 1
>
> +
1
ACTIVITY 4.3: ADDITION OF TWO SINGLE DIGITS NUMBERS
.data
Num1 db 0
Num2 db 0
msgNum1 db "Enter the 1st No: $"
msgNum2 db 10,13,"Enter the 2nd No: $"
msgAns db 10,13,"The answer is: $"
.code
;========================================
main proc
mov ax, @data
mov ds, ax
mov dx,offset msgNum1
mov ah, 09h
int 21h
;=======================================
mov ax, @data
28 Experiment 4 – Input/Output Single and Multi-digit Number
mov ds, ax
;++++++++++++++++++++++++++++++++++++++++++
;ADD Num1,Num2 is illegal
number:
number:
Write a program that reads five unsigned integers from user and display sum of those five integers on the
screen. Write program and outcome here: -
Write a program using instruction shown in table and fill in the table with the offsets of the instructions in
the code segment.
mov sum, ax
mov ax, 0
RESOURCES
http://www.uobabylon.edu.iq/eprints/publication_1_26408_35.pdf
http://www1.frm.utn.edu.ar/arquitectura/t86.pdf
https://www.academia.edu/6933756/8086_Assembler_Tutorial_for_Beginners
http://people.vts.su.ac.rs/~pmiki/STOREnGO/ASM%20zbirka/emu8086.pdf
OBJECTIVES
Defining data word and data byte variable
Identification of Flag register
Type of flag register
TIME REQUIRED : 3 hrs
PROGRAMMING LANGUAGE : Assembly Language
SOFTWARE REQUIRED : Emulator 8086, DOS, Debug
HARDWARE REQUIRED : Core i5 in Computer Labs, MDA – Win8086
IDENTIFIER
An identifier is a programmer-chosen name. It might identify a variable, a constant or a procedure. Things to
remember when creating an identifier
Length between 1 and 247 characters.
They are not case sensitive.
The first character must be a letter (A..Z, a..z), underscore (_), @ , ?, or $. Subsequent characters
may also be digits.
An identifier cannot be the same as an assembler reserved word
INSTRUCTIONS
An instruction is a statement that becomes executable when a program is assembled. Instruction contains
four basic parts
Label (Optional)
Instruction Mnemonic (required)
Operands (normally required)
Comment (optional)
[label:] mnemonic operand(s) [;comment]
DATA TYPES
Type Usage
BYTE 8-bit unsigned integer
SBYTE 8-bit signed integer
WORD 16-bit unsigned integer
SWORD 16-bit signed integer
DWORD 32-bit unsigned integer
SDWORD 32-bit signed integer
QWORD 64-bit integer
FLAG REGISTER
Determines the current state of the processor.
They are modified automatically by CPU after mathematical operations, this allows to determine the
type of the result, and to determine conditions to transfer control to other parts of the program.
Generally, you cannot access these registers directly.
TYPES OF FLAGS: There are two types of flags
Status Flags The Status flags reflect the outcomes of arithmetic and logical operations performed by
the CPU. You do not need to alter the value yourself.
◾ Carry flag (CF) is set when the result of an unsigned arithmetic operation is too large to fit into
the destination (unsigned overflow). For example, when you add bytes 255+1 (result is not in
range 0...255). When there is no overflow this flag is set to 0. This flag uses bit 0
◾ Parity flag (PF) is set if the least-significant byte in the result contains an even number of 1 bits.
Even if result is a word only 8 low bits are analyzed. This flag uses bit 2
◾ Auxiliary Carry flag (AC) is set when an arithmetic operation causes a carry from bit 3 to bit 4.
(Unsigned over flow for low nibble -4 bits) This flag uses bit 4
◾ Zero flag (ZF) is set when the result of an arithmetic or logical operation generates a result of
zero. For none zero result this flag is set to 0. This flag uses bit 6
◾ Sign flag (SF) is set when the result of an arithmetic or logical operation generates a negative
result. Actually, this flag take the value of the most significant bit. This flag uses bit 7
RESOURCES
http://www.uobabylon.edu.iq/eprints/publication_1_26408_35.pdf
http://www1.frm.utn.edu.ar/arquitectura/t86.pdf
https://www.academia.edu/6933756/8086_Assembler_Tutorial_for_Beginners
http://people.vts.su.ac.rs/~pmiki/STOREnGO/ASM%20zbirka/emu8086.pdf
OBJECTIVES
Use of Arithmetic Operators
Operation with signed and unsigned values
Solve mathematical equations
TIME REQUIRED : 3 hrs
PROGRAMMING LANGUAGE : Assembly Language
SOFTWARE REQUIRED : Emulator 8086, DOS, Debug
HARDWARE REQUIRED : Core i5 in Computer Labs, MDA – Win8086
INTEGER ADDITION AND SUBTRACTION INSTRUCTIONS (ADD, SUB)
In arithmetic instruction these types of operands are supported:
REG, memory
memory, REG
REG, REG
memory, immediate
REG, immediate
REG:AX, BX, CX, DX, AH, AL, BL, BH, CH, CL, DH, DL, DI, SI, BP, SP.
memory: variable, [BX], etc...
immediate: 5, -24, 3Fh, 10001101b, etc...
The integer at source is added to the integer at destination and the sum replaces the old value at destination.
The SF, ZF, OF, CF, PF and AF flags are set according to the value of the result of the operation.
MULTIPLICATION INSTRUCTIONS (MUL, IMUL)
There are two versions of multiplication instructions, MUL instruction is for unsigned multiplication and
IMUL instruction is for signed multiplication. These types of operands are supported by MUL and IMUL:
REG
memory
REG: AX, BX, CX, DX, AH, AL, BL, BH, CH, CL, DH, DL, DI, SI, BP, SP.
memory: variable, [BX], etc...
MUL and IMUL instructions affect CF, OF flags only:
MUL -Unsigned multiply:
When operand is a byte:
AX = AL * operand.
When operand is a word:
(DX AX) = AX * operand.
Example: Multiply AX by 10h (16 bit)
.data
Var1 dw 2000h
Var2 dw 0010h
.code
36 Experiment 6 – Arithmetic Instructions
MOV ax, Var1
MUL var2 ;DX=0002h, AX=0000h
IMUL -Signed multiply:
When operand is a byte:
AX = AL * operand.
When operand is a word:
(DX AX) = AX * operand.
Example: Multiply AX by 10h (8 bit)
.code
MOV al,1
MOV bl,-1
IMUL bl ;AX=1111111111111111b
;CF=0, OF=0
ACTIVITY 6.1 WORD MULTIPLICATION
include emu8086.inc
.data
Var1 dw 2000h
Var2 dw 0010h
.code
MOV ax,Var1
MUL Var2 ;DX=0002h,
; AX=0000h
call print_num
DEFINE_PRINT_NUM ; used by print_num proc
DEFINE_PRINT_NUM_UNS ; used by print_num proc
end
Execute and write outcome here: -
RESOURCES
http://www.uobabylon.edu.iq/eprints/publication_1_26408_35.pdf
http://www1.frm.utn.edu.ar/arquitectura/t86.pdf
https://www.academia.edu/6933756/8086_Assembler_Tutorial_for_Beginners
http://people.vts.su.ac.rs/~pmiki/STOREnGO/ASM%20zbirka/emu8086.pdf
OBJECTIVES
Learn how to use of Boolean operators
Learn which flag bits are affected by different Boolean instructions
TEST INSTRUCTION
TEST instruction performs an implied AND operation b/w each pair of matching bits in two operands and
set the flag accordingly.
TEST operand1, operand2
The difference b/w TEST and AND instruction is that TEST Does not modify the destination operand. TEST
instruction permits the same operand combinations as the AND instruction.
Flags: CF, ZF, SF, OF, PF, AF.
44 Experiment 7 – Boolean Operators
CMP INSTRUCTION
CMP (compare) instruction performs an implied subtraction of a source from destination operand i.e. Subtract
second operand from first for flags only. Neither operand is modified. CMP instruction can be b/w
CMP reg, reg
CMP reg, mem
CMP reg, imm
CMP mem, reg
CMP mem, imm
CMP instructions affect flags only and do not store a result (these instructions are used to make decisions
during program execution).
Flags: - CF, ZF, SF, OF, PF, AF.
CMP Result ZF CF
Destination < Source 0 1
Destination > Source 0 0
Destination = Source 1 0
Examples:
Destination < Source:
mov ax, 5
cmp ax, 10 ;CF = 1
Destination = Source
mov ax, 1000
mov cx, 1000
cmp cx, ax ; ZF = 1
Destination > Source
mov si, 105
cmp si, 0 ; ZF = 0 and CF = 0
RESOURCES
http://www.uobabylon.edu.iq/eprints/publication_1_26408_35.pdf
http://www1.frm.utn.edu.ar/arquitectura/t86.pdf
https://www.academia.edu/6933756/8086_Assembler_Tutorial_for_Beginners
http://people.vts.su.ac.rs/~pmiki/STOREnGO/ASM%20zbirka/emu8086.pdf
OBJECTIVES
Learn how to control the flow of program.
Learn how to transfer control conditionally and unconditionally.
Learn how to implement if statement
main ENDP
JO Jump if overflow OF = 1
JS Jump if sign SF = 1
JE Jump if equal ZF = 1
JZ Jump if zero
JP Jump if parity PF = 1
JPE Jump if parity even
cmp bx, 10
jnl elseLarge
inc smallCount
jmp endValueCheck
elseLarge:
inc largeCount
endValueCheck:
main ENDP
RESOURCES
http://www.uobabylon.edu.iq/eprints/publication_1_26408_35.pdf
http://www1.frm.utn.edu.ar/arquitectura/t86.pdf
https://www.academia.edu/6933756/8086_Assembler_Tutorial_for_Beginners
http://people.vts.su.ac.rs/~pmiki/STOREnGO/ASM%20zbirka/emu8086.pdf
OBJECTIVES
Learn how to repeat execution of a program fragment.
Learn the working of loop instruction
Learn implementation of while, until, and for loops.
main ENDP
Example:
Consider the following code
for index := 1 to 50 loop
... { loop body using index }
end for;
BX can be used to store index counting from 1 to 50, while the CX register counts down from 50 to 1.
The corresponding assembly code is as follows:
mov bx, 1 ; index := 1
mov cx, 50 ; number of iterations
forNbr: . ;
. ; use BX for index
.
inc bx ; add 1 to
index loop forNbr
; repeat
IMPLEMENTATION OF UNTIL LOOP
An until loop is a post-test loop – the condition is checked after the body of loop is executed. In general, an
until loop can be represented as follows:
repeat
... { body of loop }
until termination condition;
Termination condition is checked after the loop body is executed. If it is true, execution continues with the
statement following until loop. Otherwise, the loop body is executed again. Thus, loop body is executed at
least once. An 80x86 implementation of until loop follows:
until: . ; start of loop body
.
.
body: . ; code to check termination
condition enduntil:
Example:
consider the following code
repeat
add 2*count to sum;
add 1 to count;
until (sum > 1000);
RESOURCES
http://www.uobabylon.edu.iq/eprints/publication_1_26408_35.pdf
http://www1.frm.utn.edu.ar/arquitectura/t86.pdf
https://www.academia.edu/6933756/8086_Assembler_Tutorial_for_Beginners
http://people.vts.su.ac.rs/~pmiki/STOREnGO/ASM%20zbirka/emu8086.pdf
OBJECTIVES
Learn how to define and access arrays.
Learn how to search and modify the elements of an array.
Learn how different addressing modes are used.
org 100h
.data
array db 10h,20h,30h,40h
.code
main
proc
mov al, array
mov bl, array+1
mov cl, array+2
mov dl,array+3
main endp
end main
Execute and write outcome here: -
include emu8086.inc
.DATA
arr dw 25, 47, 15, 50, 32, 95 DUP (?)
n dw 5
.CODE
main PROC
mov ax, @data
mov ds, ax
forCount1:
add ax,[bx] ; add number to sum
add bx,2 ; get address of next array elt
loop forCount1 ; repeat n times
print 10
print 13
call print_num
0 main ENDP
RESOURCES
http://www.uobabylon.edu.iq/eprints/publication_1_26408_35.pdf
http://www1.frm.utn.edu.ar/arquitectura/t86.pdf
https://www.academia.edu/6933756/8086_Assembler_Tutorial_for_Beginners
http://people.vts.su.ac.rs/~pmiki/STOREnGO/ASM%20zbirka/emu8086.pdf
OBJECTIVES
Learn how to use the stack.
Learn how to perform different operation on stack.
TIME REQUIRED : 3 hrs
PROGRAMMING LANGUAGE : Assembly
Language
SOFTWARE REQUIRED : Emulator 8086, DOS, Debug
HARDWARE REQUIRED : Core i5 in Computer Labs, MDA – Win8086
STACK is an area of memory for keeping temporary data. The stack uses LIFO (Last in First Out)
algorithm, this means that if we push values one by one into the stack. Stack is used by CALL instruction to
keep return address for procedure, RET instruction gets this value from the stack and returns to that offset.
Quite the same thing happens when INT instruction calls an interrupt, it stores in stack flag register, code
segment and offset. IRET instruction is used to return from interrupt call.
We can also use the stack to keep any other data; there are two instructions that work with the stack:
PUSH - stores 16-bit value in the stack.
POP - gets 16-bit value from the
stack. Syntax for PUSH instruction:
PUSH REG
PUSH SREG
PUSH memory
PUSH immediate
REG: AX, BX, CX, DX, DI, SI, BP, SP.
SREG: DS, ES, SS, CS.
Memory: [BX], [BX+SI+7], 16 bits variable, etc...
Immediate: 5, -24, 3Fh, 10001101b, etc...
Syntax for POP instruction:
POP REG
POP SREG
POP memory
REG: AX, BX, CX, DX, DI, SI, BP, SP.
SREG: DS, ES, SS, (except CS).
memory: [BX], [BX+SI+7], 16 bits variable, etc...
The stack memory area is set by SS (Stack Segment) register, and SP (Stack Pointer) register. Generally,
operating system sets values of these registers on program start.
"PUSH source" instruction does the following:
Subtract 2from SP register.
68 Experiment 11 – Stack Operations
Write the value of source to the address SS:SP.
"POP destination" instruction does the following:
Write the value at the address SS:SP to destination.
Add 2to SP register.
Note: - The current address pointed by SS:SP is called the top of the stack.
ACTIVITY 11.1
org 100h
.code
main
proc
MOV AX, 1234h
PUSH AX ; store value of AX in
stack. MOV AX, 5678h ; modify the AX
value.
POP AX ; restore the original value of
AX. main endp
end main
Execute and write outcome here: -
.code
main
proc
mov ax,48H
mov dx,49H
push ax ;save ax
push dx ;save dx
mov ah,9 ;function display string
mov dx,offset message ;dx points to the string
INT 21H ;call DOS
pop dx ;restore dx
pop ax ;restore ax
mov ax,4C00h
INT 21H
main endp
end main
Execute and write outcome here: -
include emu8086.inc
.data
buffer db 100 dup(?),0
size = $ - offset buffer
.code
mov ax, @data
mov ds,ax
putc 0Dh
putc 10 ; next line.
DEFINE_GET_STRING
DEFINE_PRINT_STRING
end
Execute and write outcome here: -
Now write a code to delete the items having quantity zero and update the stack. Show code and outcome here:
RESOURCES
http://www.uobabylon.edu.iq/eprints/publication_1_26408_35.pdf
http://www1.frm.utn.edu.ar/arquitectura/t86.pdf
https://www.academia.edu/6933756/8086_Assembler_Tutorial_for_Beginners
http://people.vts.su.ac.rs/~pmiki/STOREnGO/ASM%20zbirka/emu8086.pdf
OBJECTIVES
Lear how to use BIOS Interrupts in the 8086 processor
Lear how to use DOS Interrupts in the 8086 processor
TIME REQUIRED : 3 hrs
PROGRAMMING LANGUAGE : Assembly
Language
SOFTWARE REQUIRED : Emulator 8086, DOS, Debug
HARDWARE REQUIRED : Core i5 in Computer Labs, MDA – Win8086
There are some extremely useful subroutines within BIOS and DOS that are available to the user through the
INT instruction. The INT instruction is somewhat like a FAR call. When it is invoked, it saves CS:IP and
then flags on the stack and goes to the subroutine associated with that interrupt. The INT instruction has the
following format:
INT xx ; the interrupt number xx can be 00 – FF
Since interrupts are numbered 00 to FF, this gives a total of 256interrupts in 80x86 microprocessors. From
these 256 interrupts, two are the most widely used: INT10 and INT 21. Each one can perform many
functions. You can find a list of these interrupts in emu8086 help tutorial (The List of Interrupts is given in a
file). Before the service of INT 10H or INT 21H is requested, certain registers must have specific values in
them, depending upon the function being requested. Various functions of INT 21H and INT 10H are
selected by the value put in the AH register.
Note:- Near calls & returns transfer control between procedures in the same code segment. Far calls &
returns pass control between different segments.
BIOS INTERRUPT: INT 10H subroutines are burned into the ROM BIOS of the 8086 based and
compatibles and are used to communicate with the computer user screen video. Much of the manipulation of
screen text or graphics is done through INT 10H. Among them are changing the color of characters or
background, clearing screen, and changing the locations of cursor. Below are two examples that use BIOS
interrupts.
Clearing the screen:
MOV AX, 0600H ;scroll entire screen
MOV BH, 07 ;normal attribute
MOV CX, 0000 ;start at 00,00
MOV DX, 184F ;end at 18, 4F
INT 10H ;invoke the interrupt
Setting the cursor position:
MOV AH, 02 ;set cursor option
MOV BH, 00 ;page 0
MOV DL, 25 ;column position
MOV DH, 15 ;row position
INT 10H
;clear Screen
MOV AX, 0600H ;scroll entire screen
MOV BH, 07 ;normal attribute
MOV CX, 0000 ;start at 00,00
MOV DX, 184Fh ;end at 18, 4F
INT 10H ;invoke the interrupt
;set cursor position
MOV AH, 02 ;set cursor option
MOV BH, 00 ;page 0
MOV DL, 25 ;column position
MOV DH, 15 ;row position
INT 10H
;print message
mov dx,offset hello_message
mov ah,9 ; MS-Dos Function to display string
INT 21H
mov ax,4C00h ; Halt the program and return control to OS
INT 21H
main endp
end main ; Mark the end of the source file
Execute and write outcome here: -
RESOURCES
http://www.uobabylon.edu.iq/eprints/publication_1_26408_35.pdf
http://www1.frm.utn.edu.ar/arquitectura/t86.pdf
https://www.academia.edu/6933756/8086_Assembler_Tutorial_for_Beginners
http://people.vts.su.ac.rs/~pmiki/STOREnGO/ASM%20zbirka/emu8086.pdf
OBJECTIVE: To understand static and dynamic multiplication using loops in assembly language.
TIME REQUIRED : 3 hrs
PROGRAMMING LANGUAGE : Assembly Language
SOFTWARE REQUIRED : Emulator 8086, DOS, Debug
HARDWARE REQUIRED : Core i5 in Computer Labs, MDA – Win8086
COMMAND/SYNTAX USED:
Use main Proc to start the procedure.
Use mov ah, 01h to take input from user.
Use Mov ah, 02h to display a single character.
Use the next line command and previous output hold command to make the display readable.
MOV AH, 0AH
MOV AH, 0DH
Use LEA (LOAD EFFECTIVE ADDRESS) command to display the string on screen.
LEA DX, VARIABLE
Use interrupt command to exit the previous command.
Int 21h
Use DOS exit command to exit the Programme.
Mov ah, 4ch
Int 21h
Take input from user as much as you want. When number is entered by the user it automatically goes
into AL register and machine added 30hex in the data by itself. To get the required decimal number
30h must be subtracted from AL. The input must be taken in loop.
Syntax for multiplication in loop (user defined): The destination register must be AL.
Mov cx, number
l1:
MUL source register
Dec cx
Jnz l1
The result is stored in AL. To display the result, add 30h in the result because processor only
understand hex values. To get the desired output result, one must add 30h in the result.
If the result is >=10 use the div command
The divisor will be 10 and the dividend must be in “AL
register
If the result is >=100 use the div command, then use div
command twice.
Multiplication in loop(static): In static, input is given in stack segment all other procedure is same
as above
RESOURCES
http://www.uobabylon.edu.iq/eprints/publication_1_26408_35.pdf
http://www1.frm.utn.edu.ar/arquitectura/t86.pdf
https://www.academia.edu/6933756/8086_Assembler_Tutorial_for_Beginners
http://people.vts.su.ac.rs/~pmiki/STOREnGO/ASM%20zbirka/emu8086.pdf
RESOURCES
http://www.uobabylon.edu.iq/eprints/publication_1_26408_35.pdf
http://www1.frm.utn.edu.ar/arquitectura/t86.pdf
https://www.academia.edu/6933756/8086_Assembler_Tutorial_for_Beginners
http://people.vts.su.ac.rs/~pmiki/STOREnGO/ASM%20zbirka/emu8086.pdf