You are on page 1of 44

Lecture 01: Introduction

National University of
Computer & Emerging Sciences

Lab 01
Introduction
Mr. Zia Ur Rehman

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

About me
• BS(SE) –Comsat University(2014-2018)

• MS(CS) – UET Taxila(2018-)

• Instructor –FAST-NU(2019-)

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

About me
Office: 307
Office hours – to be decided
Email: zia.urrehman@nu.edu.pk

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Some Rules

– Raise your hand before asking any question


and then WAIT for the permission
– Never ever miss a class
– Never ever “sleep” in the class
– Never use mobile phones in the class
– In group assignments, everyone will be evaluated
individually.
– You won’t be allowed to come inside the lab after
10 minutes

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Some Rules

– Submit your work on Slate.


– (Email submissions won’t be accepted)

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Dishonesty, Plagiarism

All parties involved in any kind of cheating in


any exam (Quizzes, Assignments &
Projects) will get negative marks.

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Tentative Evaluation Breakdown


Assignments 10
Quizzes 10
Project 20
Lab tasks 30

Final Exam 30

Total 100

Note: The evaluation Breakdown plus course outline for all sections will be same
Grading will be combined so don’t rely on your class position look for the batch position

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Agenda for today


- Introduction and Outline discussion
- Assembler (Masm)
- Intel 8086 Microprocessor
Registers
- Writing & Compiling Assembly code

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

PROGRAM
TRANSLATION
SEQUENCE

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Program Translation Sequence

High level language (C, C++)

Assembly Language

Machine Language

Hardware

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Program Translation Sequence

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Program Translation

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Assembler
 Assembler, A program that converts source-code programs from
assembly language to machine language. It generates
 Object file: A machine language translation of the program.
 Linker: Copies sub-routines from link library into object file &
produces executable program.
 Debugger: Provides a way for programmer to trace execution of a
program and examine the contents of memory.

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

The Microsoft Macro Assembler (MASM) is


an x86 assembler that uses the Intel syntax for MS-
DOS and Microsoft Windows.

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

What is DosBox

 Emulator
 Free software
 Debugging
 Run on every Environment
 Can grip on syntax
 Easy to use

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Installing DOSBOX and 8086


Download “8086 Folder” from classroom
Extract contents of 8086.rar in Google
classroom

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Interface

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Drive mounting
DOSBox does not automatically make any
drive (or a part of it) accessible to the
emulation.
You have to make your directories available as
drives in DOSBox by using the "mount"
command.

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Drive mounting
mount c c:\8086

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

How File create


C:
 edit filename.asm

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

FileName .asm

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

DOSBOX commands for code


compilation:
masm test.asm (this will create an object
file)

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Cont…
link test.obj (this will create an
executable)

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Cont…
Test.exe (to run executable)

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Intel 8086 (Registers)


8086 has total of Fourteen Registers accessible
to programmer.
Each register is 16 bits long i.e. it can contain
16-bit binary number at max.

 General Purpose/Data Registers (AX, BX, CX,
DX).
Index/Pointer registers (SP, BP, SI, DI).
Segment Registers (SS, DS, SS, ES).
Control Registers (Flags, Instruction Pointer).

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Inside 8086 (Data Registers)


 8086 CPU has four 16-bit data registers 
◦ 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).
 These registers can be used in arithmetic or logic operations
and as temporary storage.
 The main purpose of a register is to keep a number (variable).

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Inside 8086 (Registers)


 The size of the above registers is 16 bit, it's something
like: 0011000000111001b (in binary form), or 12345 in decimal (human)
form.
 4 general purpose registers (AX, BX, CX, DX) are made of two separate
8 bit registers
◦ For example if AX= 0011000000111001b, then AH=00110000b and
AL=00111001b.
 Registers are located inside the CPU, they are much faster than memory.
accessing a memory location requires the use of a system bus, so it takes
much longer.
 Accessing data in a register usually takes no time. therefore, you should
try to keep variables in the registers for manipulation.

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Inside 8086 (Data Registers)


Each data register has a special purpose
too.
Register Special Purpose
AX Multiply/divide
BX Index Registers for MOVE

CX Count Register for String


Operations
DX Port address for IN and OUT

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Instruction
Assembler converts the instruction in to machine
code.
◦ Machine code is a sequence of bits can be read by the
processor.
Tells CPU what to do.
Each instruction has
◦ Mnemonic (Required)
 Symbolic Code for Instructions or Commands to perform
a particular function
 mov, inc, add, sub, mul
◦ Operand (Optional/Depend on Instruction)
 On which operation is to be performed.

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Type of Operands
Immediate
◦ A constant Integer of 8 or 16 bit.
Register
◦ Name of register.
Memory
◦ References to Memory Location.

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Data Transfer Instructions


Mnemonic Function
MOV Move byte or word to register or memory

IN, OUT Input byte or word from port, output word to


port
LEA Load effective address
LDS, LES Load pointer using data segment, extra
segment
PUSH, POP Push word onto stack, pop word off stack

XCHG Exchange byte or word


XLAT Translate byte using look-up table

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Arithmetic Instructions
INC operand1
◦ operand = operand + 1
Example
◦ MOV AL, 228 ;
◦ INC AL ; AL = 229
DEC operand1
◦ operand = operand - 1
Example
◦ MOV AL, 255 ;
◦ DEC AL ; AL = 254

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Examples
Val=result; MOV AX,result
MOV Val,AX

Result= x+y; MOV AX,x


ADD AX,y
MOV Result,AX

 Most high-level language


instructions need more than
one assembly instruction

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Sample Code

int main () .model small


{ .stack
.data
int a=5; .code
mov al,5
cout<<a; add al,48
mov dl,al
return 0; mov ah,02h
int 21h
}
mov ah,4ch
int 21h
end

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Example 2

int Y;
int X = (Y + 4) * 3;

mov ax,Y move Y to the AX register


add ax,4 add 4 to the AX register
mov bx,3 move 3 to the BX register
mul bx multiply AX by BX
mov X,ax
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 01: Introduction

Why Assembly Language

 Better understanding of hardware and software interaction.


 Optimization of processing time.
 Representation of data in memory
 Embedded Programming
 How a program access external devices
 How processor access and execute instruction
 It helps in device driver
 Less memory and execution time

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Learning Outcomes

 Learning Programming methodology to be able to create system level


software tools and application programs.

 interrelationship between hardware and software

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Quiz

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Q1:Convert C program to Assembly Language?

Hint use only 16 bit registers (4 points)


( 4 )points

Q2: if AX= 0011000000111001b and


Quiz 1
BX=0011001100110011b

Nand AX,BX Find the Output? (3 points)


Q3: intmov
X = dh,56
((Y * 4) / 3);
mov dx,48
inc dx
Value of
dl=? dh=? dx=? (3 points)
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 01: Introduction

Things to do Before Next Lab

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Before coming to next lab, Make sure


you are done with..
Masm 615 must be installed and configured by
using either of methods discussed.
Must have tested a code on your installed assembler.
Understanding of Assembly language and
Assembler.
Understanding of Masm615 Data/Special purpose
registers and Instructions which are discussed today.

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 01: Introduction

Thank You :)

FAST, National University of Computer and Emerging Sciences, Islamabad

You might also like