SlideShare a Scribd company logo
1 of 12
What isAssembly 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;
 It is most suitable for writing interrupt service routines and other memory resident
programs.
An assembly program can be divided into three sections:
 The data section
 The bss section
 The text section
The data Section
The data section is used for declaring initialized data or constants. This data does not change
at runtime. It can declare various constant values, file names or buffer size etc. in this section.
The syntax for declaring data section is:
section .data
The bss Section
The bss section is used for declaring variables. The syntax for declaring bss section is:
section .bss
The textsection
The text section is used for keeping the actual code. This section must begin with the
declaration global main, which tells the kernel where the program execution begins.
The syntax for declaring text section is:
section .text
global main
main:
8085 program to add two 8 bit numbers
Problem – Write an assembly language program to add two 8 bit numbers stored at address
2050 and address 2051 in 8085 microprocessor. The starting address of the program is taken
as 2000
Example –
Algorithm
 Load the first number from memory location 2050 to accumualtor.
 Move the content of accumulator to register H.
 Load the second number from memory location 2051 to accumaltor.
 Then add the content of register H and accumulator using “ADD” instruction and
storing result at 3050
 The carry generated is recovered using “ADC” command and is stored at memory
location 3051
Program –
MEMORY ADDRESS MNEMONICS COMMENT
2000 LDA 2050 A<-[2050]
2003 MOV H, A H<-A
2004 LDA 2051 A<-[2051]
2007 ADD H A<-A+H
2006 MOV L, A L←A
2007 MVI A 00 A←00
2009 ADC A A←A+A+carry
200A MOV H, A H←A
200B SHLD 3050 H→3051, L→3050
200E HLT
Explanation
 LDA 2050 moves the contents of 2050 memory location to the accumulator.
 MOV H, A copies contents of Accumulator to register H to A
 LDA 2051 moves the contents of 2051 memory location to the accumulator.
 ADD H adds contents of A (Accumulator) and H register (F9). The result is stored in
A itself. For all arithmetic instructions A is by default an operand and A stores the
result as well
 MOV L, A copies contents of A (34) to L
 MVI A 00 moves immediate data (i.e., 00) to A
 ADC A adds contents of A(00), contents of register specified (i.e A) and carry (1). As
ADC is also an arithmetic operation, A is by default an operand and A stores the
result as well
 MOV H, A copies contents of A (01) to H
 SHLD 3050 moves the contents of L register (34) in 3050 memory location and
contents of H register (01) in 3051 memory location
 HLT stops executing the program and halts any further execution
The 8086 microprocessor supports 8 types of instructions −
 Data Transfer Instructions
 Arithmetic Instructions
 Bit Manipulation Instructions
 String Instructions
 Program Execution Transfer Instructions (Branch & Loop Instructions)
 Processor Control Instructions
 Iteration Control Instructions
 Interrupt Instructions
Let us now discuss these instruction sets in detail.
Data Transfer Instructions
These instructions are used to transfer the data from the source operand to the destination
operand. Following are the list of instructions under this group −
Instruction to transfer a word
 MOV − Used to copy the byte or word from the provided source to the provided
destination.
 PPUSH − Used to put a word at the top of the stack.
 POP − Used to get a word from the top of the stack to the provided location.
 PUSHA − Used to put all the registers into the stack.
 POPA − Used to get words from the stack to all registers.
 XCHG − Used to exchange the data from two locations.
 XLAT − Used to translate a byte in AL using a table in the memory.
Instructions for input and output port transfer
 IN − Used to read a byte or word from the provided port to the accumulator.
 OUT − Used to send out a byte or word from the accumulator to the provided port.
Instructions to transfer the address
 LEA − Used to load the address of operand into the provided register.
 LDS − Used to load DS register and other provided register from the memory
 LES − Used to load ES register and other provided register from the memory.
Instructions to transfer flag registers
 LAHF − Used to load AH with the low byte of the flag register.
 SAHF − Used to store AH register to low byte of the flag register.
 PUSHF − Used to copy the flag register at the top of the stack.
 POPF − Used to copy a word at the top of the stack to the flag register.
Arithmetic Instructions
These instructions are used to perform arithmetic operations like addition, subtraction,
multiplication, division, etc.
Following is the list of instructions under this group −
Instructions to perform addition
 ADD − Used to add the provided byte to byte/word to word.
 ADC − Used to add with carry.
 INC − Used to increment the provided byte/word by 1.
 AAA − Used to adjust ASCII after addition.
 DAA − Used to adjust the decimal after the addition/subtraction operation.
Instructions to perform subtraction
 SUB − Used to subtract the byte from byte/word from word.
 SBB − Used to perform subtraction with borrow.
 DEC − Used to decrement the provided byte/word by 1.
 NPG − Used to negate each bit of the provided byte/word and add 1/2’s complement.
 CMP − Used to compare 2 provided byte/word.
 AAS − Used to adjust ASCII codes after subtraction.
 DAS − Used to adjust decimal after subtraction.
Instruction to perform multiplication
 MUL − Used to multiply unsigned byte by byte/word by word.
 IMUL − Used to multiply signed byte by byte/word by word.
 AAM − Used to adjust ASCII codes after multiplication.
Instructions to perform division
 DIV − Used to divide the unsigned word by byte or unsigned double word by word.
 IDIV − Used to divide the signed word by byte or signed double word by word.
 AAD − Used to adjust ASCII codes after division.
 CBW − Used to fill the upper byte of the word with the copies of sign bit of the
lower byte.
 CWD − Used to fill the upper word of the double word with the sign bit of the lower
word.
Bit Manipulation Instructions
These instructions are used to perform operations where data bits are involved, i.e.
operations like logical, shift, etc.
Following is the list of instructions under this group −
Instructions to perform logical operation
 NOT − Used to invert each bit of a byte or word.
 AND − Used for adding each bit in a byte/word with the corresponding bit in another
byte/word.
 OR − Used to multiply each bit in a byte/word with the corresponding bit in another
byte/word.
 XOR − Used to perform Exclusive-OR operation over each bit in a byte/word with
the corresponding bit in another byte/word.
 TEST − Used to add operands to update flags, without affecting operands.
Instructions to perform shift operations
 SHL/SAL − Used to shift bits of a byte/word towards left and put zero(S) in LSBs.
 SHR − Used to shift bits of a byte/word towards the right and put zero(S) in MSBs.
 SAR − Used to shift bits of a byte/word towards the right and copy the old MSB into
the new MSB.
Instructions to perform rotate operations
 ROL − Used to rotate bits of byte/word towards the left, i.e. MSB to LSB and to
Carry Flag [CF].
 ROR − Used to rotate bits of byte/word towards the right, i.e. LSB to MSB and to
Carry Flag [CF].
 RCR − Used to rotate bits of byte/word towards the right, i.e. LSB to CF and CF to
MSB.
 RCL − Used to rotate bits of byte/word towards the left, i.e. MSB to CF and CF to
LSB.
String Instructions
String is a group of bytes/words and their memory is always allocated in a sequential order.
Following is the list of instructions under this group
 REP − Used to repeat the given instruction till CX ≠ 0.
 REPE/REPZ − Used to repeat the given instruction until CX = 0 or zero flag ZF = 1.
 REPNE/REPNZ − Used to repeat the given instruction until CX = 0 or zero flag ZF
= 1.
 MOVS/MOVSB/MOVSW − Used to move the byte/word from one string to
another.
 COMS/COMPSB/COMPSW − Used to compare two string bytes/words.
 INS/INSB/INSW − Used as an input string/byte/word from the I/O port to the
provided memory location.
 OUTS/OUTSB/OUTSW − Used as an output string/byte/word from the provided
memory location to the I/O port.
 SCAS/SCASB/SCASW − Used to scan a string and compare its byte with a byte in
AL or string word with a word in AX.
 LODS/LODSB/LODSW − Used to store the string byte into AL or string word into
AX.
PROGRAM STRUCTURE
Program Execution Transfer Instructions (Branch and Loop Instructions)
These instructions are used to transfer/branch the instructions during an execution. It
includes the following instructions −
Instructions to transfer the instruction during an execution without any condition −
 CALL − Used to call a procedure and save their return address to the stack.
 RET − Used to return from the procedure to the main program.
 JMP − Used to jump to the provided address to proceed to the next instruction.
Instructions to transfer the instruction during an execution with some conditions −
 JA/JNBE − Used to jump if above/not below/equal instruction satisfies.
 JAE/JNB − Used to jump if above/not below instruction satisfies.
 JBE/JNA − Used to jump if below/equal/ not above instruction satisfies.
 JC − Used to jump if carry flag CF = 1
 JE/JZ − Used to jump if equal/zero flag ZF = 1
 JG/JNLE − Used to jump if greater/not less than/equal instruction satisfies.
 JGE/JNL − Used to jump if greater than/equal/not less than instruction satisfies.
 JL/JNGE − Used to jump if less than/not greater than/equal instruction satisfies.
 JLE/JNG − Used to jump if less than/equal/if not greater than instruction satisfies.
 JNC − Used to jump if no carry flag (CF = 0)
 JNE/JNZ − Used to jump if not equal/zero flag ZF = 0
 JNO − Used to jump if no overflow flag OF = 0
 JNP/JPO − Used to jump if not parity/parity odd PF = 0
 JNS − Used to jump if not sign SF = 0
 JO − Used to jump if overflow flag OF = 1
 JP/JPE − Used to jump if parity/parity even PF = 1
 JS − Used to jump if sign flag SF = 1
Processor Control Instructions
These instructions are used to control the processor action by setting/resetting the flag
values.
Following are the instructions under this group −
 STC − Used to set carry flag CF to 1
 CLC − Used to clear/reset carry flag CF to 0
 CMC − Used to put complement at the state of carry flag CF.
 STD − Used to set the direction flag DF to 1
 CLD − Used to clear/reset the direction flag DF to 0
 STI − Used to set the interrupt enable flag to 1, i.e., enable INTR input.
 CLI − Used to clear the interrupt enable flag to 0, i.e., disable INTR input.
Iteration Control Instructions
These instructions are used to execute the given instructions for number of times. Following
is the list of instructions under this group −
 LOOP − Used to loop a group of instructions until the condition satisfies, i.e., CX =
0
 LOOPE/LOOPZ − Used to loop a group of instructions till it satisfies ZF = 1 & CX
= 0
 LOOPNE/LOOPNZ − Used to loop a group of instructions till it satisfies ZF = 0 &
CX = 0
 JCXZ − Used to jump to the provided address if CX = 0
Interrupt Instructions
These instructions are used to call the interrupt during program execution.
 INT − Used to interrupt the program during execution and calling service specified.
 INTO − Used to interrupt the program during execution if OF = 1
 IRET − Used to return from interrupt service to the main program
MACROS:
A Macro is a group of instructions with a name. When a macro is invoked, the
associated set of instructions is inserted in place in to the source, replacing the macro name.
This“macro expansion” is done by a Macro Preprocessor and it happens before assembly.
Thus the actual Assembler sees the “expanded” source Writing a macro is another way of
ensuring modular programming in assembly language.A macro is a sequence of instructions,
assigned by a name and could be used anywhere in the program.
In NASM, macros are defined with %macro and %endmacro directives. The macro begins
with the %macro directive and ends with the %endmacro directive.
The Syntax for macro definition −
%macro macro_name number_of_params
<macro body>
%endmacro
Where, number_of_params specifies the number parameters, macro_name specifies the name
of the macro.The macro is invoked by using the macro name along with the necessary
parameters. When you need to use some sequence of instructions many times in a program,
you can put those instructions in a macro and use it instead of writing the instructions all the
time. For example, a very common need for programs is to write a string of characters in the
screen. For displaying a string of characters, you need the following sequence of instructions
mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
In the above example of displaying a character string, the registers EAX, EBX, ECX and
EDX have been used by the INT 80H function call. So, each time you need to display on
screen, you need to save these registers on the stack, invoke INT 80H and then restore the
original value of the registers from the stack. So, it could be useful to write two macros for
saving and restoring data.
observed that, some instructions like IMUL, IDIV, INT, etc., need some of the information to
be stored in some particular registers and even return values in some specific register(s). If
the program was already using those registers for keeping important data, then the existing
data from these registers should be saved in the stack and restored after the instruction is
executed.
ASSEMBLER DIRECTIVES
SEGMENT
The SEGMENT directive is used to indicate the start of a logical segment. Preceding the
SEGMENT directive is the name you want to give the segment. For example, the statement
CODE SEGMENTindicates to the assembler the start of a logical segment called CODE. The
SEGMENT and ENDS directive are used to “bracket” a logical segment containing code of
data.
Additional terms are often added to a SEGMENT directive statement to indicate some
special way in which we want the assembler to treat the segment. The statement CODE
SEGMENT WORD tells the assembler that we want the content of this segment located on
the next available word (even address)when segments ate combined and given absolute
addresses. Without this WORD addition, the segment will be located on the next available
paragraph (16-byte) address, which might waste as much as 15 bytes of memory. The
statement CODE SEGMENT PUBLIC tells the assembler that the segment may be put
together with other segments named CODE from other assembly modules when the modules
are linked together.
ENDS (END SEGMENT)
This directive is used with the name of a segment to indicate the end of that logical segment.
CODE SEGMENT Start of logical segment containing code instruction statements
CODE ENDS End of segment named CODE
END (END PROCEDURE)
The END directive is put after the last statement of a program to tell the assembler that this is
the end of the program module. The assembler will ignore any statements after an END
directive, so you should make sure to use only one END directive at the very end of your
program module. A carriage return is required after the END directive.
ASSUME
The ASSUME directive is used tell the assembler the name of the logical segment it should
use for a specified segment. The statement ASSUME CS: CODE, for example, tells the
assembler that the instructions for a program are in a logical segment named CODE. The
statement ASSUME DS: DATA tells the assembler that for any program instruction, which
refers to the data segment, it should use the logical segment called DATA.
DB (DEFINE BYTE)
The DB directive is used to declare a byte type variable, or a set aside one or more storage
locations of type byte in memory. PRICES DB 49H, 98H, 29H Declare array of 3 bytes
named PRICE and initialize them with specified values. NAMES DB “THOMAS” Declare
array of 6 bytes and initialize with ASCII codes for the letters in THOMAS.
TEMP DB 100 DUP (?) Set aside 100 bytes of storage in memory and give it the name
TEMP. But leave the 100 bytes un-initialized.
PRESSURE DB 20H DUP (0) Set aside 20H bytes of storage in memory, give it the name
PRESSURE and put 0 in all 20H locations.
DD (DEFINE DOUBLE WORD)
The DD directive is used to declare a variable of type double word or to reserve memory
locations, which can be accessed as type double word. The statement ARRAY DD
25629261H, for example, will define a double word named ARRAY and initialize the double
word with the specified value when the program is loaded into memory to be run. The low
word, 9261H, will be put in memory at a lower address than the high word.
DQ (DEFINE QUADWORD)
The DQ directive is used to tell the assembler to declare a variable 4 words in length or to
reserve 4 words of storage in memory. The statement BIG_NUMBER DQ
243598740192A92BH, for example, will declare a variable named BIG_NUMBER and
initialize the 4 words set aside with the specified number when the program is loaded into
memory to be run.
DT (DEFINE TEN BYTES)
The DT directive is used to tell the assembler to declare a variable, which is 10 bytes in
length or to reserve 10 bytes of storage in memory. The statement PACKED_BCD DT
11223344556677889900 will declare an array named PACKED_BCD, which is 10 bytes in
length. It will initialize the 10 bytes with the values 11, 22, 33, 44, 55, 66, 77, 88, 99, and 00
when the program is loaded into memory to be run.
The statement RESULT DT 20H DUP (0) will declare an array of 20H blocks of 10
bytes each and initialize all 320 bytes to 00 when the program is loaded into memory to be
run.
DW (DEFINE WORD)
The DW directive is used to tell the assembler to define a variable of type word or to reserve
storage locations of type word in memory. The statement MULTIPLIER DW 437AH, for
example, declares a variable of type word named MULTIPLIER, and initialized with the
value 437AH when the program is loaded into memory to be run.
WORDS DW 1234H, 3456H Declare an array of 2 words and initialize them with the
specified values.
STORAGE DW 100 DUP (0) Reserve an array of 100 words of memory and initialize all 100
words with 0000. Array is named as STORAGE.
STORAGE DW 100 DUP (?) Reserve 100 word of storage in memory and give it the name
STORAGE, but leave the words un-initialized.
EQU (EQUATE)
EQU is used to give a name to some value or symbol. Each time the assembler finds the
given name in the program, it replaces the name with the value or symbol you equated with
that name. Suppose, for example, you write the statement FACTOR EQU 03H at the start of
your program, and later in the program you write the instruction statement ADD AL,
FACTOR. When the assembler codes this instruction statement, it will code it as if you had
written the instruction ADD AL, 03H.
CONTROL EQU 11000110 B Replacement
MOV AL, CONTROL Assignment
DECIMAL_ADJUST EQU DAA Create clearer mnemonic for DAA
ADD AL, BL Add BCD numbers
DECIMAL_ADJUST Keep result in BCD format.

More Related Content

What's hot

Introduction to Assembly Language Programming
Introduction to Assembly Language ProgrammingIntroduction to Assembly Language Programming
Introduction to Assembly Language ProgrammingRahul P
 
8086 assembly language
8086 assembly language8086 assembly language
8086 assembly languageMir Majid
 
Assembly language 8086 intermediate
Assembly language 8086 intermediateAssembly language 8086 intermediate
Assembly language 8086 intermediateJohn Cutajar
 
Assembly language 8086
Assembly language 8086Assembly language 8086
Assembly language 8086John Cutajar
 
Microprocessor chapter 9 - assembly language programming
Microprocessor  chapter 9 - assembly language programmingMicroprocessor  chapter 9 - assembly language programming
Microprocessor chapter 9 - assembly language programmingWondeson Emeye
 
POWER processor and features presentation
POWER processor and features presentationPOWER processor and features presentation
POWER processor and features presentationGanesan Narayanasamy
 
Microprocessor 8086 instruction description
Microprocessor 8086 instruction descriptionMicroprocessor 8086 instruction description
Microprocessor 8086 instruction descriptionDheeraj Suri
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 80869840596838
 
Advanced procedures in assembly language Full chapter ppt
Advanced procedures in assembly language Full chapter pptAdvanced procedures in assembly language Full chapter ppt
Advanced procedures in assembly language Full chapter pptMuhammad Sikandar Mustafa
 
MASM -UNIT-III
MASM -UNIT-IIIMASM -UNIT-III
MASM -UNIT-IIIDr.YNM
 
Examinable Question and answer system programming
Examinable Question and answer system programmingExaminable Question and answer system programming
Examinable Question and answer system programmingMakerere university
 
Introduction to Assembly Language
Introduction to Assembly Language Introduction to Assembly Language
Introduction to Assembly Language ApekshaShinde6
 
Assembly language programming(unit 4)
Assembly language programming(unit 4)Assembly language programming(unit 4)
Assembly language programming(unit 4)Ashim Saha
 

What's hot (20)

Assembly language part I
Assembly language part IAssembly language part I
Assembly language part I
 
Introduction to Assembly Language Programming
Introduction to Assembly Language ProgrammingIntroduction to Assembly Language Programming
Introduction to Assembly Language Programming
 
8086 assembly language
8086 assembly language8086 assembly language
8086 assembly language
 
Assembly language 8086 intermediate
Assembly language 8086 intermediateAssembly language 8086 intermediate
Assembly language 8086 intermediate
 
Assembly language 8086
Assembly language 8086Assembly language 8086
Assembly language 8086
 
Intro to assembly language
Intro to assembly languageIntro to assembly language
Intro to assembly language
 
8086 alp
8086 alp8086 alp
8086 alp
 
Microprocessor chapter 9 - assembly language programming
Microprocessor  chapter 9 - assembly language programmingMicroprocessor  chapter 9 - assembly language programming
Microprocessor chapter 9 - assembly language programming
 
POWER processor and features presentation
POWER processor and features presentationPOWER processor and features presentation
POWER processor and features presentation
 
Al2ed chapter7
Al2ed chapter7Al2ed chapter7
Al2ed chapter7
 
Microprocessor 8086 instruction description
Microprocessor 8086 instruction descriptionMicroprocessor 8086 instruction description
Microprocessor 8086 instruction description
 
12 mt06ped008
12 mt06ped008 12 mt06ped008
12 mt06ped008
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
Advanced procedures in assembly language Full chapter ppt
Advanced procedures in assembly language Full chapter pptAdvanced procedures in assembly language Full chapter ppt
Advanced procedures in assembly language Full chapter ppt
 
MASM -UNIT-III
MASM -UNIT-IIIMASM -UNIT-III
MASM -UNIT-III
 
Examinable Question and answer system programming
Examinable Question and answer system programmingExaminable Question and answer system programming
Examinable Question and answer system programming
 
Introduction to Assembly Language
Introduction to Assembly Language Introduction to Assembly Language
Introduction to Assembly Language
 
Lecture4
Lecture4Lecture4
Lecture4
 
Chapter 3 programming concepts-ii
Chapter 3  programming concepts-iiChapter 3  programming concepts-ii
Chapter 3 programming concepts-ii
 
Assembly language programming(unit 4)
Assembly language programming(unit 4)Assembly language programming(unit 4)
Assembly language programming(unit 4)
 

Similar to Microprocessor

unit1.pdf
unit1.pdfunit1.pdf
unit1.pdfSaruM1
 
Assembly language (Example with mapping from C++ to Assembly)
Assembly language (Example with mapping from C++ to Assembly)Assembly language (Example with mapping from C++ to Assembly)
Assembly language (Example with mapping from C++ to Assembly)Tish997
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086Akhila Rahul
 
Instruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorInstruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorAshita Agrawal
 
instruction-set-of-8086-mr-binu-joy3.ppt
instruction-set-of-8086-mr-binu-joy3.pptinstruction-set-of-8086-mr-binu-joy3.ppt
instruction-set-of-8086-mr-binu-joy3.pptssuser2b759d
 
Arm Cortex material Arm Cortex material3222886.ppt
Arm Cortex material Arm Cortex material3222886.pptArm Cortex material Arm Cortex material3222886.ppt
Arm Cortex material Arm Cortex material3222886.pptManju Badiger
 
Assembly language.pptx
Assembly language.pptxAssembly language.pptx
Assembly language.pptxShaistaRiaz4
 
Instruction sets of 8086
Instruction sets of 8086Instruction sets of 8086
Instruction sets of 8086Mahalakshmiv11
 
Chap 3_2.ppt
Chap 3_2.pptChap 3_2.ppt
Chap 3_2.pptinian2
 
Introduction to debugging linux applications
Introduction to debugging linux applicationsIntroduction to debugging linux applications
Introduction to debugging linux applicationscommiebstrd
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Bilal Amjad
 
Compreport
CompreportCompreport
Compreportxdarlord
 
03 addr mode &amp; instructions
03 addr mode &amp; instructions03 addr mode &amp; instructions
03 addr mode &amp; instructionsShubhamBakshi14
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086Vijay Kumar
 
Instructionsetof8086 180224060745(3)
Instructionsetof8086 180224060745(3)Instructionsetof8086 180224060745(3)
Instructionsetof8086 180224060745(3)AmitPaliwal20
 

Similar to Microprocessor (20)

unit1.pdf
unit1.pdfunit1.pdf
unit1.pdf
 
Assembly language (Example with mapping from C++ to Assembly)
Assembly language (Example with mapping from C++ to Assembly)Assembly language (Example with mapping from C++ to Assembly)
Assembly language (Example with mapping from C++ to Assembly)
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
Instruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorInstruction Set of 8086 Microprocessor
Instruction Set of 8086 Microprocessor
 
Wk1to4
Wk1to4Wk1to4
Wk1to4
 
instruction-set-of-8086-mr-binu-joy3.ppt
instruction-set-of-8086-mr-binu-joy3.pptinstruction-set-of-8086-mr-binu-joy3.ppt
instruction-set-of-8086-mr-binu-joy3.ppt
 
Arm Cortex material Arm Cortex material3222886.ppt
Arm Cortex material Arm Cortex material3222886.pptArm Cortex material Arm Cortex material3222886.ppt
Arm Cortex material Arm Cortex material3222886.ppt
 
MPMC UNIT-2.pdf
MPMC UNIT-2.pdfMPMC UNIT-2.pdf
MPMC UNIT-2.pdf
 
Assembly language.pptx
Assembly language.pptxAssembly language.pptx
Assembly language.pptx
 
microprocessor
 microprocessor microprocessor
microprocessor
 
X86 operation types
X86 operation typesX86 operation types
X86 operation types
 
Instruction sets of 8086
Instruction sets of 8086Instruction sets of 8086
Instruction sets of 8086
 
Chap 3_2.ppt
Chap 3_2.pptChap 3_2.ppt
Chap 3_2.ppt
 
Introduction to debugging linux applications
Introduction to debugging linux applicationsIntroduction to debugging linux applications
Introduction to debugging linux applications
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
 
Compreport
CompreportCompreport
Compreport
 
03 addr mode &amp; instructions
03 addr mode &amp; instructions03 addr mode &amp; instructions
03 addr mode &amp; instructions
 
Lecture5
Lecture5Lecture5
Lecture5
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
Instructionsetof8086 180224060745(3)
Instructionsetof8086 180224060745(3)Instructionsetof8086 180224060745(3)
Instructionsetof8086 180224060745(3)
 

More from Bathshebaparimala

More from Bathshebaparimala (20)

C programming structures &amp; union
C programming structures &amp; unionC programming structures &amp; union
C programming structures &amp; union
 
An enhanced liver stages classification in 3 d ct and 3d-us images using glrl...
An enhanced liver stages classification in 3 d ct and 3d-us images using glrl...An enhanced liver stages classification in 3 d ct and 3d-us images using glrl...
An enhanced liver stages classification in 3 d ct and 3d-us images using glrl...
 
Assessment
AssessmentAssessment
Assessment
 
Normalization
NormalizationNormalization
Normalization
 
Protocols and its standards
Protocols and its standardsProtocols and its standards
Protocols and its standards
 
Unit v
Unit vUnit v
Unit v
 
Hint for transmission media
Hint for transmission mediaHint for transmission media
Hint for transmission media
 
Osi model detail description
Osi model  detail descriptionOsi model  detail description
Osi model detail description
 
Creating a rainbow using graphics programming in c
Creating a rainbow using graphics programming in cCreating a rainbow using graphics programming in c
Creating a rainbow using graphics programming in c
 
Network layer
Network layerNetwork layer
Network layer
 
Routing
RoutingRouting
Routing
 
Transport layer
Transport layerTransport layer
Transport layer
 
Generation of Computer Network
Generation of Computer NetworkGeneration of Computer Network
Generation of Computer Network
 
Network -Lecture Notes
Network -Lecture NotesNetwork -Lecture Notes
Network -Lecture Notes
 
Segmentation of Machine learning Algorithm
Segmentation of Machine learning AlgorithmSegmentation of Machine learning Algorithm
Segmentation of Machine learning Algorithm
 
Osireferencemodel
OsireferencemodelOsireferencemodel
Osireferencemodel
 
Transmission media
Transmission mediaTransmission media
Transmission media
 
Osi model
Osi modelOsi model
Osi model
 
Relational dbms
Relational dbmsRelational dbms
Relational dbms
 
Medical imaging
Medical imagingMedical imaging
Medical imaging
 

Recently uploaded

What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 

Recently uploaded (20)

young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 

Microprocessor

  • 1. What isAssembly 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;  It is most suitable for writing interrupt service routines and other memory resident programs. An assembly program can be divided into three sections:  The data section  The bss section  The text section The data Section The data section is used for declaring initialized data or constants. This data does not change at runtime. It can declare various constant values, file names or buffer size etc. in this section. The syntax for declaring data section is: section .data The bss Section The bss section is used for declaring variables. The syntax for declaring bss section is:
  • 2. section .bss The textsection The text section is used for keeping the actual code. This section must begin with the declaration global main, which tells the kernel where the program execution begins. The syntax for declaring text section is: section .text global main main: 8085 program to add two 8 bit numbers Problem – Write an assembly language program to add two 8 bit numbers stored at address 2050 and address 2051 in 8085 microprocessor. The starting address of the program is taken as 2000 Example – Algorithm  Load the first number from memory location 2050 to accumualtor.  Move the content of accumulator to register H.  Load the second number from memory location 2051 to accumaltor.  Then add the content of register H and accumulator using “ADD” instruction and storing result at 3050  The carry generated is recovered using “ADC” command and is stored at memory location 3051 Program – MEMORY ADDRESS MNEMONICS COMMENT 2000 LDA 2050 A<-[2050] 2003 MOV H, A H<-A 2004 LDA 2051 A<-[2051]
  • 3. 2007 ADD H A<-A+H 2006 MOV L, A L←A 2007 MVI A 00 A←00 2009 ADC A A←A+A+carry 200A MOV H, A H←A 200B SHLD 3050 H→3051, L→3050 200E HLT Explanation  LDA 2050 moves the contents of 2050 memory location to the accumulator.  MOV H, A copies contents of Accumulator to register H to A  LDA 2051 moves the contents of 2051 memory location to the accumulator.  ADD H adds contents of A (Accumulator) and H register (F9). The result is stored in A itself. For all arithmetic instructions A is by default an operand and A stores the result as well  MOV L, A copies contents of A (34) to L  MVI A 00 moves immediate data (i.e., 00) to A  ADC A adds contents of A(00), contents of register specified (i.e A) and carry (1). As ADC is also an arithmetic operation, A is by default an operand and A stores the result as well  MOV H, A copies contents of A (01) to H  SHLD 3050 moves the contents of L register (34) in 3050 memory location and contents of H register (01) in 3051 memory location  HLT stops executing the program and halts any further execution The 8086 microprocessor supports 8 types of instructions −
  • 4.  Data Transfer Instructions  Arithmetic Instructions  Bit Manipulation Instructions  String Instructions  Program Execution Transfer Instructions (Branch & Loop Instructions)  Processor Control Instructions  Iteration Control Instructions  Interrupt Instructions Let us now discuss these instruction sets in detail. Data Transfer Instructions These instructions are used to transfer the data from the source operand to the destination operand. Following are the list of instructions under this group − Instruction to transfer a word  MOV − Used to copy the byte or word from the provided source to the provided destination.  PPUSH − Used to put a word at the top of the stack.  POP − Used to get a word from the top of the stack to the provided location.  PUSHA − Used to put all the registers into the stack.  POPA − Used to get words from the stack to all registers.  XCHG − Used to exchange the data from two locations.  XLAT − Used to translate a byte in AL using a table in the memory. Instructions for input and output port transfer  IN − Used to read a byte or word from the provided port to the accumulator.  OUT − Used to send out a byte or word from the accumulator to the provided port. Instructions to transfer the address  LEA − Used to load the address of operand into the provided register.  LDS − Used to load DS register and other provided register from the memory  LES − Used to load ES register and other provided register from the memory. Instructions to transfer flag registers  LAHF − Used to load AH with the low byte of the flag register.  SAHF − Used to store AH register to low byte of the flag register.  PUSHF − Used to copy the flag register at the top of the stack.
  • 5.  POPF − Used to copy a word at the top of the stack to the flag register. Arithmetic Instructions These instructions are used to perform arithmetic operations like addition, subtraction, multiplication, division, etc. Following is the list of instructions under this group − Instructions to perform addition  ADD − Used to add the provided byte to byte/word to word.  ADC − Used to add with carry.  INC − Used to increment the provided byte/word by 1.  AAA − Used to adjust ASCII after addition.  DAA − Used to adjust the decimal after the addition/subtraction operation. Instructions to perform subtraction  SUB − Used to subtract the byte from byte/word from word.  SBB − Used to perform subtraction with borrow.  DEC − Used to decrement the provided byte/word by 1.  NPG − Used to negate each bit of the provided byte/word and add 1/2’s complement.  CMP − Used to compare 2 provided byte/word.  AAS − Used to adjust ASCII codes after subtraction.  DAS − Used to adjust decimal after subtraction. Instruction to perform multiplication  MUL − Used to multiply unsigned byte by byte/word by word.  IMUL − Used to multiply signed byte by byte/word by word.  AAM − Used to adjust ASCII codes after multiplication. Instructions to perform division  DIV − Used to divide the unsigned word by byte or unsigned double word by word.  IDIV − Used to divide the signed word by byte or signed double word by word.  AAD − Used to adjust ASCII codes after division.  CBW − Used to fill the upper byte of the word with the copies of sign bit of the lower byte.  CWD − Used to fill the upper word of the double word with the sign bit of the lower word.
  • 6. Bit Manipulation Instructions These instructions are used to perform operations where data bits are involved, i.e. operations like logical, shift, etc. Following is the list of instructions under this group − Instructions to perform logical operation  NOT − Used to invert each bit of a byte or word.  AND − Used for adding each bit in a byte/word with the corresponding bit in another byte/word.  OR − Used to multiply each bit in a byte/word with the corresponding bit in another byte/word.  XOR − Used to perform Exclusive-OR operation over each bit in a byte/word with the corresponding bit in another byte/word.  TEST − Used to add operands to update flags, without affecting operands. Instructions to perform shift operations  SHL/SAL − Used to shift bits of a byte/word towards left and put zero(S) in LSBs.  SHR − Used to shift bits of a byte/word towards the right and put zero(S) in MSBs.  SAR − Used to shift bits of a byte/word towards the right and copy the old MSB into the new MSB. Instructions to perform rotate operations  ROL − Used to rotate bits of byte/word towards the left, i.e. MSB to LSB and to Carry Flag [CF].  ROR − Used to rotate bits of byte/word towards the right, i.e. LSB to MSB and to Carry Flag [CF].  RCR − Used to rotate bits of byte/word towards the right, i.e. LSB to CF and CF to MSB.  RCL − Used to rotate bits of byte/word towards the left, i.e. MSB to CF and CF to LSB. String Instructions String is a group of bytes/words and their memory is always allocated in a sequential order. Following is the list of instructions under this group  REP − Used to repeat the given instruction till CX ≠ 0.  REPE/REPZ − Used to repeat the given instruction until CX = 0 or zero flag ZF = 1.  REPNE/REPNZ − Used to repeat the given instruction until CX = 0 or zero flag ZF = 1.
  • 7.  MOVS/MOVSB/MOVSW − Used to move the byte/word from one string to another.  COMS/COMPSB/COMPSW − Used to compare two string bytes/words.  INS/INSB/INSW − Used as an input string/byte/word from the I/O port to the provided memory location.  OUTS/OUTSB/OUTSW − Used as an output string/byte/word from the provided memory location to the I/O port.  SCAS/SCASB/SCASW − Used to scan a string and compare its byte with a byte in AL or string word with a word in AX.  LODS/LODSB/LODSW − Used to store the string byte into AL or string word into AX. PROGRAM STRUCTURE Program Execution Transfer Instructions (Branch and Loop Instructions) These instructions are used to transfer/branch the instructions during an execution. It includes the following instructions − Instructions to transfer the instruction during an execution without any condition −  CALL − Used to call a procedure and save their return address to the stack.  RET − Used to return from the procedure to the main program.  JMP − Used to jump to the provided address to proceed to the next instruction. Instructions to transfer the instruction during an execution with some conditions −  JA/JNBE − Used to jump if above/not below/equal instruction satisfies.  JAE/JNB − Used to jump if above/not below instruction satisfies.  JBE/JNA − Used to jump if below/equal/ not above instruction satisfies.  JC − Used to jump if carry flag CF = 1  JE/JZ − Used to jump if equal/zero flag ZF = 1  JG/JNLE − Used to jump if greater/not less than/equal instruction satisfies.  JGE/JNL − Used to jump if greater than/equal/not less than instruction satisfies.  JL/JNGE − Used to jump if less than/not greater than/equal instruction satisfies.  JLE/JNG − Used to jump if less than/equal/if not greater than instruction satisfies.  JNC − Used to jump if no carry flag (CF = 0)  JNE/JNZ − Used to jump if not equal/zero flag ZF = 0  JNO − Used to jump if no overflow flag OF = 0  JNP/JPO − Used to jump if not parity/parity odd PF = 0  JNS − Used to jump if not sign SF = 0
  • 8.  JO − Used to jump if overflow flag OF = 1  JP/JPE − Used to jump if parity/parity even PF = 1  JS − Used to jump if sign flag SF = 1 Processor Control Instructions These instructions are used to control the processor action by setting/resetting the flag values. Following are the instructions under this group −  STC − Used to set carry flag CF to 1  CLC − Used to clear/reset carry flag CF to 0  CMC − Used to put complement at the state of carry flag CF.  STD − Used to set the direction flag DF to 1  CLD − Used to clear/reset the direction flag DF to 0  STI − Used to set the interrupt enable flag to 1, i.e., enable INTR input.  CLI − Used to clear the interrupt enable flag to 0, i.e., disable INTR input. Iteration Control Instructions These instructions are used to execute the given instructions for number of times. Following is the list of instructions under this group −  LOOP − Used to loop a group of instructions until the condition satisfies, i.e., CX = 0  LOOPE/LOOPZ − Used to loop a group of instructions till it satisfies ZF = 1 & CX = 0  LOOPNE/LOOPNZ − Used to loop a group of instructions till it satisfies ZF = 0 & CX = 0  JCXZ − Used to jump to the provided address if CX = 0 Interrupt Instructions These instructions are used to call the interrupt during program execution.  INT − Used to interrupt the program during execution and calling service specified.  INTO − Used to interrupt the program during execution if OF = 1  IRET − Used to return from interrupt service to the main program MACROS: A Macro is a group of instructions with a name. When a macro is invoked, the associated set of instructions is inserted in place in to the source, replacing the macro name.
  • 9. This“macro expansion” is done by a Macro Preprocessor and it happens before assembly. Thus the actual Assembler sees the “expanded” source Writing a macro is another way of ensuring modular programming in assembly language.A macro is a sequence of instructions, assigned by a name and could be used anywhere in the program. In NASM, macros are defined with %macro and %endmacro directives. The macro begins with the %macro directive and ends with the %endmacro directive. The Syntax for macro definition − %macro macro_name number_of_params <macro body> %endmacro Where, number_of_params specifies the number parameters, macro_name specifies the name of the macro.The macro is invoked by using the macro name along with the necessary parameters. When you need to use some sequence of instructions many times in a program, you can put those instructions in a macro and use it instead of writing the instructions all the time. For example, a very common need for programs is to write a string of characters in the screen. For displaying a string of characters, you need the following sequence of instructions mov edx,len ;message length mov ecx,msg ;message to write mov ebx,1 ;file descriptor (stdout) mov eax,4 ;system call number (sys_write) int 0x80 ;call kernel In the above example of displaying a character string, the registers EAX, EBX, ECX and EDX have been used by the INT 80H function call. So, each time you need to display on screen, you need to save these registers on the stack, invoke INT 80H and then restore the original value of the registers from the stack. So, it could be useful to write two macros for saving and restoring data. observed that, some instructions like IMUL, IDIV, INT, etc., need some of the information to be stored in some particular registers and even return values in some specific register(s). If the program was already using those registers for keeping important data, then the existing data from these registers should be saved in the stack and restored after the instruction is executed. ASSEMBLER DIRECTIVES SEGMENT The SEGMENT directive is used to indicate the start of a logical segment. Preceding the SEGMENT directive is the name you want to give the segment. For example, the statement CODE SEGMENTindicates to the assembler the start of a logical segment called CODE. The
  • 10. SEGMENT and ENDS directive are used to “bracket” a logical segment containing code of data. Additional terms are often added to a SEGMENT directive statement to indicate some special way in which we want the assembler to treat the segment. The statement CODE SEGMENT WORD tells the assembler that we want the content of this segment located on the next available word (even address)when segments ate combined and given absolute addresses. Without this WORD addition, the segment will be located on the next available paragraph (16-byte) address, which might waste as much as 15 bytes of memory. The statement CODE SEGMENT PUBLIC tells the assembler that the segment may be put together with other segments named CODE from other assembly modules when the modules are linked together. ENDS (END SEGMENT) This directive is used with the name of a segment to indicate the end of that logical segment. CODE SEGMENT Start of logical segment containing code instruction statements CODE ENDS End of segment named CODE END (END PROCEDURE) The END directive is put after the last statement of a program to tell the assembler that this is the end of the program module. The assembler will ignore any statements after an END directive, so you should make sure to use only one END directive at the very end of your program module. A carriage return is required after the END directive. ASSUME The ASSUME directive is used tell the assembler the name of the logical segment it should use for a specified segment. The statement ASSUME CS: CODE, for example, tells the assembler that the instructions for a program are in a logical segment named CODE. The statement ASSUME DS: DATA tells the assembler that for any program instruction, which refers to the data segment, it should use the logical segment called DATA. DB (DEFINE BYTE) The DB directive is used to declare a byte type variable, or a set aside one or more storage locations of type byte in memory. PRICES DB 49H, 98H, 29H Declare array of 3 bytes named PRICE and initialize them with specified values. NAMES DB “THOMAS” Declare array of 6 bytes and initialize with ASCII codes for the letters in THOMAS. TEMP DB 100 DUP (?) Set aside 100 bytes of storage in memory and give it the name TEMP. But leave the 100 bytes un-initialized. PRESSURE DB 20H DUP (0) Set aside 20H bytes of storage in memory, give it the name PRESSURE and put 0 in all 20H locations. DD (DEFINE DOUBLE WORD) The DD directive is used to declare a variable of type double word or to reserve memory locations, which can be accessed as type double word. The statement ARRAY DD 25629261H, for example, will define a double word named ARRAY and initialize the double
  • 11. word with the specified value when the program is loaded into memory to be run. The low word, 9261H, will be put in memory at a lower address than the high word. DQ (DEFINE QUADWORD) The DQ directive is used to tell the assembler to declare a variable 4 words in length or to reserve 4 words of storage in memory. The statement BIG_NUMBER DQ 243598740192A92BH, for example, will declare a variable named BIG_NUMBER and initialize the 4 words set aside with the specified number when the program is loaded into memory to be run. DT (DEFINE TEN BYTES) The DT directive is used to tell the assembler to declare a variable, which is 10 bytes in length or to reserve 10 bytes of storage in memory. The statement PACKED_BCD DT 11223344556677889900 will declare an array named PACKED_BCD, which is 10 bytes in length. It will initialize the 10 bytes with the values 11, 22, 33, 44, 55, 66, 77, 88, 99, and 00 when the program is loaded into memory to be run. The statement RESULT DT 20H DUP (0) will declare an array of 20H blocks of 10 bytes each and initialize all 320 bytes to 00 when the program is loaded into memory to be run. DW (DEFINE WORD) The DW directive is used to tell the assembler to define a variable of type word or to reserve storage locations of type word in memory. The statement MULTIPLIER DW 437AH, for example, declares a variable of type word named MULTIPLIER, and initialized with the value 437AH when the program is loaded into memory to be run. WORDS DW 1234H, 3456H Declare an array of 2 words and initialize them with the specified values. STORAGE DW 100 DUP (0) Reserve an array of 100 words of memory and initialize all 100 words with 0000. Array is named as STORAGE. STORAGE DW 100 DUP (?) Reserve 100 word of storage in memory and give it the name STORAGE, but leave the words un-initialized. EQU (EQUATE) EQU is used to give a name to some value or symbol. Each time the assembler finds the given name in the program, it replaces the name with the value or symbol you equated with that name. Suppose, for example, you write the statement FACTOR EQU 03H at the start of your program, and later in the program you write the instruction statement ADD AL, FACTOR. When the assembler codes this instruction statement, it will code it as if you had written the instruction ADD AL, 03H. CONTROL EQU 11000110 B Replacement MOV AL, CONTROL Assignment
  • 12. DECIMAL_ADJUST EQU DAA Create clearer mnemonic for DAA ADD AL, BL Add BCD numbers DECIMAL_ADJUST Keep result in BCD format.