0% found this document useful (0 votes)
80 views

Unit 2

The document discusses microprocessors and assembly language programming. It defines assembly language and its advantages. It also lists the tools used for assembly language programming and the typical steps to develop an assembly language program.

Uploaded by

xboyxman1000
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views

Unit 2

The document discusses microprocessors and assembly language programming. It defines assembly language and its advantages. It also lists the tools used for assembly language programming and the typical steps to develop an assembly language program.

Uploaded by

xboyxman1000
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Microprocessors

By
Mr. Parag R. Sali
Lecturer
Department of Computer Technology
SNJB’s Shri. Hiralal Hastimal ( Jain Brothers)
Polytechnic, Chandwad
Program Name: Computer Engineering Group
Program Code : CO/CM/IF/CW
Semester : Forth
Course Title : Microprocessors
Course Code : 22415

The Art of Assembly Language Programming


What is Assembly Language?
Each personal computer has a microprocessor that manages the computer's
arithmetical, logical and control activities.
Each family of processors has its own set of instructions for handling various
operations like getting input from keyboard, displaying information on screen
and performing various other jobs. These set of instructions are called 'machine
language instruction'.
Processor understands only machine language instructions which are strings of
1s and 0s. However machine language is too obscure and complex for using in
software development. So the low level assembly language is designed for a
specific family of processors that represents various instructions in symbolic code
and a more understandable form.
Advantages of Assembly Language
An understanding of assembly language provides knowledge of:
Interface of programs with OS, processor and BIOS;
Representation of data in memory and other external devices;
How processor accesses and executes instruction;
How instructions accesses and process data;
How a program access external devices.

Other advantages of using assembly language are:


It requires less memory and execution time;
It allows hardware-specific complex jobs in an easier way;
It is suitable for time-critical jobs;
List assembly language programming tools.

1. Editors
2. Assembler
3. Linker
4. Debugger.
assembly language program development steps.

1. Defining the problem: The first step in writing program is to think very carefully
about the problem that the program must solve.
2. Algorithm: The formula or sequence of operations to be performed by the
program can be specified as a step in general English is called algorithm.
3. Flowchart: The flowchart is a graphically representation of the program
operation or task.
4. Initialization checklist: Initialization task is to make the checklist of entire
variables, constants, all the registers, flags and programmable ports
5. Choosing instructions: Choose those instructions that make program smaller in
size and more importantly efficient in execution.
6. Converting algorithms to assembly language program: Every step in the
algorithm is converted into program statement using correct and efficient
instructions or group of instructions.
There are many good assembler programs, like:
Microsoft Assembler (MASM)
Borland Turbo Assembler (TASM)
The GNU assembler (GAS)

We will use the NASM assembler, as it is:


Free. You can download it from various web sources.
Well documented and you will get lots of information on net.
Could be used on both Linux and Windows
Program Development
• Problem: must convert ideas (human thoughts) into an executing
program (binary image in memory)
• The Program Development Process uses a set of tools to provide a people-
friendly way to write programs and then convert them to the binary image.

1. Programming Language
– Syntax: set of symbols + grammar rules for constructing statements using
symbols
– Semantics: what is meant by statements 􀃆 ultimately, what happens upon
execution
– Assembly Language : A readable language that maps one-to-one to the
machine instructions, to what operations are supported by the CPU.
Program Development..cont
2. Assembler : A Program that converts the assembly language to object
format
• Object Code is the program in machine format (ie. binary)
• May contain unresolved references (ie. file contains some or all of complete
program)
3. Linker : A program that combines object files to create an single
“executable” file
– Major functional difference is that all references are resolved. (ie. Program
contains all parts needed to run)
4. Loader : A program that loads executable files into memory, and may initialize
some registers (e.g. IP ) and starts it going.
5. Debugger : A program that loads but controls the execution of the program.
To start/stop execution, to view and modify state variables
 Algorithm

An algorithm is a set of instructions designed to perform a specific task. This can be


a simple process, such as multiplying two numbers, or a complex operation, such as playing a
compressed video file. .. In computer programming, algorithms are often created as functions.
Q. Write a program to add two integer numbers

Step 1 : Start
Step 2 : Declare the variable Num1,Num2 ; Sum
Step 3 : Read value for Num1,Num2
Step 4 : Add two numbers & assign the result to Sum
Sum = Num1 + Num2
Step 5 : Display the value of Sum
Step 6 : Stop
Q. Write a program to calculate area of circle

Step 1 : Start
Step 2 : Declare the variable r, area, Pi = 3.14
Step 3 : Read value for r
Step 4 : Calculate area of circle
area = Pi * r * r
Step 5 : Display the value of area
Step 6 : Stop
 Flowchart

A flowchart is simply a graphical representation of steps. It shows steps in sequential


order and is widely used in presenting the flow of algorithms, workflow or processes. Typically,
a flowchart shows the steps as boxes of various kinds, and their order by connecting them with
arrows.
Notations
of
Flowchart
Start

Declare Variable Num1, Num2 and Sum

Read Num1 & Num2

Add Num1, Num2 and assign value to sum


sum = Num1 + Num2

print sum

Stop
Start

Declare Variable area, r & Pi = 3.14

Read r

calculate area
area = Pi * r * r

print area

Stop
Variables
Variable is a memory location. For a programmer it is much easier to have some
value be kept in a variable named "var1" then at the address 5A73:235B,
especially when you have 10 or more variables. Our compiler supports two types
of variables: BYTE and WORD.
Syntax for a variable declaration:
name DB value
name DW value
DB - stays for Define Byte. DW - stays for Define Word.
name - can be any letter or digit combination, though it should start with a letter.
It's possible to declare unnamed variables by not specifying the name (this
variable will have an address but no name).
value - can be any numeric value in any supported numbering system
(hexadecimal, binary, or decimal), or "?" symbol for variables that are not
initialized.
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.
these types of operands are supported:
MOV REG, memory
MOV memory, REG
MOV REG, REG
MOV memory, immediate
MOV REG, immediate

REG: AX, BX, CX, DX, AH, AL, BL, BH, CH, CL, DH, DL, DI, SI, BP, SP.

memory: [BX], [BX+SI+7], variable, etc...

immediate: 5, -24, 3Fh, 10001101b, etc...


here is a short program that demonstrates the use of MOV instruction:
ORG 100h ; this directive required for a simple 1 segment .com program.
MOV AX, 0B800h ; set AX to hexadecimal value of B800h.
MOV DS, AX ; copy value of AX to DS.
MOV CL, 'A' ; set CL to ASCII code of 'A', it is 41h.
MOV CH, 1101_1111b ; set CH to binary value.
MOV BX, 15Eh ; set BX to 15Eh.
RET ; returns to operating system.
data segment
a db 09h
b db 02h
c dw ?
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov al,a
mov bl,b
add al,bl
Mov c,ax
mov ah,09h
int 21h
code ends
ASSEMBLER DIRECTIVES
• Assembler directives are the commands to the assembler that direct the
assembly process.
• They indicate how an operand is treated by the assembler and how
assembler handles the program.
• They also direct the assembler how program and data should arrange in
the memory.
• ALP’s are composed of two type of statements.
(i) The instructions which are translated to machine codes by assembler.
(ii) The directives that direct the assembler during assembly process, for
which no machine code is generated.
1. ASSUME: Assume logical segment name.
The ASSUME directive is used to inform the assembler the names of the logical
segments to be assumed for different segments used in the program .In the ALP
each segment is given name.
Syntax: ASSUME segreg:segname,…segreg:segname
Ex: ASSUME CS:CODE
ASSUME CS:CODE,DS:DATA,SS:STACK
2. DB: Define Byte
The DB directive is used to reserve byte or bytes of memory locations in the
available memory.
Syntax: Name of variable DB initialization value.
Ex: MARKS DB 35H,30H,35H,40H
NAME DB “VARDHAMAN”

3. DW: Define Word


The DW directive serves the same purpose as the DB directive, but it now
makes the assembler reserve the number of
memory words(16-bit) instead of bytes.
Syntax: variable name DW initialization values.
Ex: WORDS DW 1234H,4567H,2367H
4. DD: Define Double:
The directive DD is used to define a double word (4bytes) variable.
Syntax: variablename DD 12345678H
Ex: Data1 DD 12345678H

5. DQ: Define Quad Word


This directive is used to direct the assembler to reserve 4 words (8 bytes) of
memory for the specified variable and may initialize it with the specified values.
Syntax: Name of variable DQ initialize values.
Ex: Data1 DQ 123456789ABCDEF2H

6. DT: Define Ten Bytes


The DT directive directs the assembler to define the specified variable requiring
10 bytes for its storage and initialize the 10-bytes with the specified values.
Syntax: Name of variable DT initialize values.
Ex: Data1 DT 123456789ABCDEF34567H
7. END: End of Program
The END directive marks the end of an ALP. The statement after the directive
END will be ignored by the assembler.
8. ENDP: End of Procedure
The ENDP directive is used to indicate the end of procedure. In the AL
programming the subroutines are called
procedures.
Ex: Procedure Start
:
Start ENDP
9. ENDS: End of segment
The ENDS directive is used to indicate the
end of segment.
Ex: DATA SEGMENT
:
DATA ENDS

You might also like