+ All Categories
Home > Documents > 8086 Software

8086 Software

Date post: 18-Jul-2016
Category:
Upload: christopher-baker
View: 29 times
Download: 2 times
Share this document with a friend
Description:
8086 software part description
130
HISTORY OF P Prepared by SHIHABUDEEN H
Transcript
Page 1: 8086 Software

HISTORY OF P Prepared by

SHIHABUDEEN H

Page 2: 8086 Software
Page 3: 8086 Software
Page 4: 8086 Software
Page 5: 8086 Software
Page 6: 8086 Software

8086 P Prepared by

SHIHABUDEEN H

Page 7: 8086 Software

1.Architecture

2.Programming

3.Interfacing

MICROPROCESSORS-8086

Page 8: 8086 Software

For good study of microprocessors two types of models are used :

Programmer’s model :- this model shows features , such as internal registers, address ,data & control buses ; that we need to program the device.The hardware model:- this model shows the pin diagram and the signals to/from this pins to understand how a microcomputer system is built around.

Page 9: 8086 Software

MICROCOMPUTERA microcomputer system is one which uses a microprocessor as its cpuIn addition the microcomputer also has a memory unit, input/output devices and system buses. The system buses are of three types:

1.Address bus 2.Data bus 3.Control bus

Physically buses are group of wires

Page 10: 8086 Software

8086 Bus organisatiomThe 8086 has 1.20 address lines 2.16 data lines 3.4-10 control lines. Address bus• To address 1,048,,576 (220 ) memory

locations/ports.• Sends out the address of memory

location that’s is to be written to or read from

• Sends out the address of ports that’s is to be written to or read from

Page 11: 8086 Software

Data bus• To manipulate and/or operate on

16-bits(2-bytes) of data at a time. • Read /write data from/to memory

and port through data bus• Data is three states 0,1,Z

Control bus• To generate necessary control signals for proper working of address bus and data bus

Page 12: 8086 Software
Page 13: 8086 Software

Features of 8086 8086 has 16-bit ALU; this means 16-bit

numbers are directly processed by 8086. Which carries out addition, subtraction, AND, OR, XOR, increment, decrement, complement, or shift binary numbers.

it has 16-bit data bus, so it can read data or write data to memory or i/o ports either 16 bits or 8 bits at a time.

it has 20 address lines, so it can address up to 220 i.E. 1048576 = 1mbytes of memory (words i.E. 16 bit numbers are stored in consecutive memory locations). Due to the 1mbytes memory size multiprogramming is made feasible as well as several multiprogramming features have been incorporated in 8086 design.

Page 14: 8086 Software

Features Continued … 8086 includes few features, which enhance

multiprocessing capability (it can be used with math coprocessors like 8087, I/O processor 8089 etc.

Operates on +5v supply and single phase (single line) clock frequency.(Clock is generated by separate peripheral chip 8284).

8086 comes with different versions. 8086 runs at 5 MHz, 8086-2 runs at 8 MHz, 8086-1 runs at 10 MHz.

It comes in 40-pin configuration with HMOS technology having around 20,000 transistors in its circuitry.

Page 15: 8086 Software

Features Continued … It has multiplexed address and data

bus like 8085 due to which the pin count is reduced considerably

Higher Throughput (Speed)(This is achieved

by a concept called pipelining)But the concept of 8086’s principles and structures is very useful for understanding other advanced Intel microprocessors

Page 16: 8086 Software

Pin Diagram of 8086

HARDWARE

Page 17: 8086 Software

INTERNAL ARCHITECTURE8086 CPU is divided into two parts1.Bus Interface Unit

1.Sends out addresses2.Fetch instructions3.Read data from ports and memory4.Write data to ports and memory

5.All transfer of data and address needed for EU2.Execution Unit

1.Controls BIU2.From where to fetch instructions and data3.Decodes instructions4.Excecute instructions

Page 18: 8086 Software

Bus Interface Unit(BIU)1.Queue While an EU is decoding an instruction or

executing an instruction which does not require use of the buses, Fetches up to six instruction bytes of following instructions

When EU is ready for its next instruction, it simply reads the queue in the BIU.

This is much faster than sending out the address to the memory and waiting for the memory to send back the next instruction byte

First in First out register( FIFO)

Page 19: 8086 Software

Machine cycle Each time CPU executes an instruction it takes some steps,

called machine cycle.A machine cycle can be broken down into smaller cycles such as instruction cycle and execution cycle.

Fetching: Before the CPU can execute an instruction, the control unit must retrieve (or fetch) a command or data from the computer’s memory.

Decoding: Before a command can be executed, the control unit must break down (or decode) the command into instructions.

Executing: Part of the execution cycle. When the command is executed, the CPU carries out the instructions in order by converting them into microcode.

Storing: The CPU maybe required to store the results of an instruction in memory.

Page 20: 8086 Software

Pipelining Fetching the next instruction while the current

instruction executes is called pipelining. The control unit begins a new machine cycle,

that is it begins executing a new instruction before the current cycle is completed.

Executions are performed in stages, when the first instruction completes the fetching stage, it moves to the decode stage, and a new instruction is fetched.

Using this technology, new microprocessors can execute up to six instructions simultaneously

Page 21: 8086 Software
Page 22: 8086 Software

Memory Segmentation2. Segmentation 20 bit address(220 = 1048576 bytes ) Four segment registers Holds upper 16 bit of starting address At a time 8086 works with one segment 4 segment are any where in the 1Mb

memory

Page 23: 8086 Software

Segment registers

Extra segment register Code segment register Stack segment register Data segment register

Page 24: 8086 Software

Advantages of segmentation

Facilitate the use of separate memory areas for the program, its data and the stack.

Permit a program and/or its data to be put into different areas of memory each time the program is executed.

Multitasking becomes easy. Speed of execution increase Overlapping is possible

Page 25: 8086 Software

Physical Address Calculation

Segment registers stored the upper 16 bit of the

segment which the BIU is currently fetching instructions BIU insert lower 4 bits which is always

zeros segment base = upper 16 bit address

if segment base = 2000 Actual address is 20000H

HARDWIRED ZERO

Page 26: 8086 Software

Instruction Pointer(IP)

Holds the 16 bit address of the next instruction within the current segment This value is known as Offset Used to locate the 20 bit address sent out by the BIU If the CS register contain 348AH Base Address = 348A0H IP = 1234H CS 3 4 8 A 0 Implied Zero +IP 1 2 3 4 -----------------------

3 5 A3 4 H Physical address = CS:IP

Page 27: 8086 Software

Storing

Extra segment :- store dataData segment :- store dataCode segment:- store codeStack segment:- store Address and data

Page 28: 8086 Software

Stack Stack segment: store address and data while

subprogram executes Stack segment register holds upper 16 bits of

stack segment Stack pointer used to hold the 16 bit offset from

the segment base to where data is recently stored on the stack

Recent memory location is known as top of stack Physical address is also calculated by adding segment base with content of stack pointer

Physical address= SS: SP Last In First Out register(LIFO)

Page 29: 8086 Software

Execution Unit

Control Circuitry :- directs internal operations Instruction Decoder:-decodes fetched instructions from memory to series of actions Arithmetic Logic Unit(ALU):- Addition, Subtraction, multiplication division and logical operations(XOR,OR,AND,…..) Flag register General Purpose Registers

Page 30: 8086 Software

Flag Register

Indicates the status of a microprocessor Some Conditions produced and some controls 16 bit register Nine active flags 6 Condition flags and 3 control flags Condition:- Set or reset on basis of arithmetic and logical operation Control :-Deliberately set or reset with specific instruction by the programmer

Page 31: 8086 Software

Continued…

Condition FlagsCarry FlagAuxiliary carry FlagZero Flag Overflow Flag Sign Flag Parity FlagControl Flags Direction FlagTrap Flag Interrupt Flag

U U U U OF DF IF TF SF ZF U AF U PF U CF

Page 32: 8086 Software

Condition Flags

C (carry) holds the carry after addition or borrow after subtraction. also indicates error conditions

P (parity) is the count of ones in a number expressed as even or odd. Logic 0 for odd parity; logic 1 for even parity. if a number contains three binary one bits, it has odd parity; If a number contains no one bits, it has even parity

Page 33: 8086 Software

Continued…… A (auxiliary carry) holds the carry (half-carry)

after addition or the borrow after subtraction between bit positions 3 and 4 of the result.

Z (zero) shows that the result of an arithmetic or logic operation is zero.

S (sign) flag holds the arithmetic sign of the result after an arithmetic or logic instruction executes.

O (overflow) occurs when signed numbers are added or subtracted. an overflow indicates the result has exceeded the capacity of the machine

Page 34: 8086 Software

Control flags I (interrupt) controls operation of the INTR

(interrupt request) input pin. D (direction) selects increment or

decrement mode for the DI and/or SI registers.

T (trap) The trap flag enables trapping through an on-chip debugging feature.

Page 35: 8086 Software

Registers

Page 36: 8086 Software
Page 37: 8086 Software

General Registers All general registers of the 8086 microprocessor can

be used for arithmetic and logic operations. All the registers are 16 bit wide. The general registers are:

AX (Accumulator): This is accumulator register. It gets used in arithmetic, logic and data transfer instructions. In manipulation and division, one of the numbers involved must be in AX or AL.

BX (Base Register): This is base register. BX register is an address register. It usually contain a data pointer used for based, based indexed or register indirect addressing.

Page 38: 8086 Software

Continued…. CX (Count register): This is Count

register. This serves as a loop counter. Program loop constructions are facilitated by it. Count register can also be used as a counter in string manipulation and shift/rotate instruction.

DX (Data Register): This is data register.

Data register can be used as a port number in I/O operations. It is also used in multiplication and division.

SP (Stack Pointer): This is stack pointer register pointing to program stack. It is used in conjunction with SS for accessing the stack segment.

Page 39: 8086 Software

Continued….

BP (Base Pointer): This is base pointer register pointing to data in stack segment. Unlike SP, we can use BP to access data in the other segments. Used to store the offset values

SI (Source Index): This is source index register

which is used to point to memory locations in the data segment addressed by DS. By incrementing the contents of SI one can easily access consecutive memory locations.

DI (Destination Index): This is destination index register performs the same function as SI. There is a class of instructions called string operations, that use DI to access the memory locations addressed by ES.

Page 40: 8086 Software

ProgrammingThree level of programming1. Machine language Binary numbers 0,1 It is impossible to memorize2. Assembly language Four letter mnemonics are used to represent

instruction Easy to memorize Assembler is used to convert assembly languages to

binary words A format is there for representing an operation3. High level language :-compiler are used to convert higher

level languages to machine codes

Page 41: 8086 Software

Instruction Set

A wide variety of instructions are there in 8086

Depending upon the function instructions are divided into many types

Decoding of instruction is done at the EU There is some format in representing an

instruction (changes with instructions) Label field Opcode field Operand field Comment field Next: MOV Ax,ABC2H ;move the value to Ax

Page 42: 8086 Software

INSTRUCTION SET OF 8086

Classified into 7 categories:1] Data Transfer 2] Arithmetic 3] Logical 4] Control 5]Processor Control Instructions6] String Manipulation7] Interrupt Control

Page 43: 8086 Software

Data Transfer InstructionsNote : Data Transfer Instructions do not affect any flags1] MOV dest, srcNote that source and destination cannot be memory location. Also source and destination must be same type.2] PUSH Src: Copies word on stack.3] POP dest: Copies word from stack into dest. Reg.4] IN acc, port : Copies 8 or 16 bit data from port to accumulator.a) Fixed Port

b) Variable Port 5] OUT port, acc

Page 44: 8086 Software

Data Transfer Instructions Cont…

6] LES Reg, Mem: Load register and extra segment register with words from memory.

7] LDS Reg,Mem: Load register and data segment register with words from memory.

8] LEA Reg,Src: load Effective address.(Offset is loaded in specified register)

9] LAHF: Copy lower byte of flag register into AH register.

10] SAHF: Copy AH register to lower byte of flag

Page 45: 8086 Software

Data Transfer Instructions Cont …

11] XCHG dest, src: Exchange contents of source and destination.

12] XLAT: Translate a byte in AL.This instruction replaces the byte in AL with byte pointed by BX.To point desired byte in look up table instruction adds contains of BX with AL ( BX+ AL). Goes to this location and loads into AL.

Page 46: 8086 Software

Arithmetic Instructions1]ADD dest,src 2] ADC dest,src: Add with carry3] AAA : ASCII adjust after addition.

We can add two ASCII numbers directly and use AAA after addition so as to get result directly in BCD. (Works with AL only)

4] DAA : Decimal adjust accumulator. ( Works with AL only)

Page 47: 8086 Software

Arithmetic Instructions Cont…

5] SUB dest, src6] SBB dest, src: Subtract with borrow.7] AAS: ASCII adjust for subtraction

( same as AAA and works with AL only)8] DAS : Decimal adjust after Subtraction.

( works with AL only)9] MUL src10 ] IMUL src: Multiplication of signed byte.

Page 48: 8086 Software

Arithmetic Instructions Cont…

11] AAM: BCD adjust after multiply.(works with AL only)

12]DIV src If any one attempts to divide by 0 , then ?

13] IDIV: Division of signed numbers14]AAD: BCD to Binary convert before Division.15] DEC dest

Page 49: 8086 Software

Arithmetic Instructions Cont…

16] INC dest17] CWD: Convert signed word to signed double word.18] CBW : Convert signed byte to signed word.

(CBW and CWD works only with AL, AX and DX)

19] NEG dest: Forms 2’s complement.

Page 50: 8086 Software

Logical Instructions1] AND dest, src2] NOT dest: Invert each bit in destination3] OR dest, src4] XOR dest, src5] RCL dest, count : Rotate left through Carry

Rotate as many times as directly specified in the instruction. For more no.of rotations, count can be specified in CL register.

6] RCR dest, count : Rotate right through carry7] ROL dest, count : Rotate left ( into carry as well as into LSB)8] ROR dest, Count : Rotate right ( into carry as well as into MSB)

Page 51: 8086 Software

Logical Instructions Cont…

9] SAL/ SHL dest, count : Shift left and append 0s on right.10] SAR dest, count : Shift right retain a copy of the S-bit and shift all bits to right.11]SHR dest, count : Shift right append 0s on left12] TEST dest, src: AND logically, updates flags but source and dest are unchanged.

Page 52: 8086 Software

Logical Instructions Cont…

13] CMP dest, srcCF, ZF and SF are used Ex. CMP CX,BX

CF ZF SFCX = BX 0 1 0CX > BX 0 0 0CX < BX 1 0 1

Page 53: 8086 Software

CONTROL TRANSFER INSTRUCTIONS

1]CALL : Call a procedureTwo types of calls:

i) Near Call ( Intra segment)ii) Far Call ( Intersegment)

2] RET : Return execution from procedure3] JMP : Unconditional Jump to specified destination. Two types near and Far

Page 54: 8086 Software

CONTROL TRANSFER INSTRUCTIONS Cont…

4] JA / JNBE: Jump if above / Jump if not below

The terms above and below are used when we refer to the magnitude of Unsigned number .Used normally after CMP.

5] JAE / JNB / JNC6] JB / JC / JNAE7] JBE / JNA8] JE/ JZ

Page 55: 8086 Software

CONTROL TRANSFER INSTRUCTIONS Cont…

9] JCXZ: Jump if CX is Zero.10] JG / JNLE: Jump if Greater /Jump if NOT less than or equal.

The term greater than or less than is used in connection with two signed numbers.

11] JGE / JNL:12] JL / JNGE :13] JLE / JNG :14]JNE / JNZ :

Page 56: 8086 Software

CONTROL TRANSFER INSTRUCTIONS Cont…

15] JNO : Jump if no overflow16] JNS : Jump if no sign17] JS18] JO19] JNP / JPO 20] JP / JPE

In all above conditional instructions the destination of jump is in the range of -128 to + 127 bytes from the address after jump.

Page 57: 8086 Software

CONTROL TRANSFER INSTRUCTIONS Cont…

21] LOOP: Loop to the specified label if CX is not equal to Zero.

The count is loaded in CX reg. Every time LOOP is executed, CX is automatically decremented - used in delay programs

22] LOOPE/ LOOPZ: Loop while CX is not equal to zero and ZF = 1.

23] LOOPNE / LOOPNZ: Loop while CX not equal to zero and ZF = 0.

In all above LOOP instructions the destination of jump is in the range of -128 to + 127 bytes from the address after LOOP.

Page 58: 8086 Software

PROCESSOR CONTROL 1] CLC: Clear Carry flag.2] STC :Set carry Flag3] CMC :Complement Carry Flag4] CLD: Clear Direction Flag.5] STD: Set Direction Flag6] CLI :Clear Interrupt Flag.7] STI : Set Interrupt Flag.8] HLT: Halt Processing.

Page 59: 8086 Software

PROCESSOR CONTROL Cont…

9] NOP : No Operation10] ESC: Escape

Executed by Co-processors and actions are performed according to 6 bit coding in the instruction.

11] LOCK : Assert bus lock SignalThis is a prefix instruction.

12] WAIT :Wait for test or Interrupt Signal.Assert wait states.

Page 60: 8086 Software

STRING CONTROL

1] MOVS/ MOVSB/ MOVSWDest string name,src string nameThis instn moves data byte or word from location in DS to location in ES.

2] REP / REPE / REPZ / REPNE / REPNZRepeat string instructions until specified conditions exist.This is prefix a instruction.

Page 61: 8086 Software

STRING CONTROL Contd… 3] CMPS / CMPSB / CMPSW

Compare string bytes or string words.

4] SCAS / SCASB / SCASWScan a string byte or string word.Compares byte in AL or word in AX. String address is to be loaded in DI.

5] STOS / STOSB / STOSWStore byte or word in a string.Copies a byte or word in AL or AX to memory location pointed by DI.

6] LODS / LODSB /LODSW Load a byte or word in AL or AX

Copies byte or word from memory location pointed by SI into AL or AX register.

Page 62: 8086 Software

Interrupt Control

1]INT type

2] INTO Interrupt on overflow

3] IRET Interrupt return

Page 63: 8086 Software

Addressing Modes

1. Way of locating data or operands2. There are two types of instructions3. Sequential control flow and control transfer

instruction Control will be transmitted to next instruction

after the execution Control is transmitted to some predefined

address 4. Addressing modes are sequential control flow instruction

Page 64: 8086 Software

Addressing Modes A] Data Category B] Branch Category

A] Data Category1) Immediate Addressing

2) Direct Addressing ( Segment Override prefix) 3) Register Addressing

4) Register Indirect Addressing

Page 65: 8086 Software

Addressing Modes Cont…

5) Register Relative addressing6) Base Index addressing7) Relative Base Index addressing

B] Branch Category :(control transfer)1) Intra segment Direct2) Intra segment Indirect3) Inter segment Direct4) Inter segment Indirect

Page 66: 8086 Software

Immediate Addressing

Suppose that in a program you need to put the number 437BH in the CX register.

The MOV CX, 437BH instruction can be used to do this.

When it executes this instruction will put the immediate hexadecimal number 437BH in the 16-Bit CX register.

This is referred to as immediate addressing mode.

Page 67: 8086 Software

Register Addressing

Register addressing mode means that the register is the source of an operand for an instruction.

Example: The instruction MOV CX,AX. The destination location is specified

before the comma and the source is specified after the comma.

Note that the content of AX are just copied to CX, not moved.

Page 68: 8086 Software

Direct Addressing

For the simplest memory addressing mode, the effective address is just a 16-Bit number written directly in the instruction.

Example: MOV BL, [437AH]. The square brackets around the 437AH are shorthand

for the content of the memory location. When executed the content of that memory location

will be copied in the BL register. The BIU calculates the 20-Bit physical address by

adding the effective address 437AH to the segment base address.

The effective address 10H*DS+437AH This is called direct addressing mode.

Page 69: 8086 Software

Register Indirect Addressing

The address of memory location is not visible in the instruction compared to direct addressing mode

Example: The instruction MOV CX,[AX]. The square brackets around the AX are shorthand

for the content of the memory location. When executed the content of that memory

location which is pointed by AX will be copied in the CX register.

The effective address 10H*DS+[AX] This is called register indirect addressing mode

Page 70: 8086 Software

Register Relative addressing

Relative to some displacement Example MOV AX, 50H[BX] While executing the data is available at

an effective address formed by adding an 8 bit or 16 bit displacement with the content of any of the registers(BX)

The effective address 10H*DS+50H+[BX]

Page 71: 8086 Software

Indexed Addressing mode Similar to register indirect addressing mode Example MOV AX,[SI] The square brackets around the SI are

shorthand for the content of the memory location.

When executed the content of that memory location which is pointed by SI will be copied in the AX register.

The effective address 10H*DS+[SI] This is called indexed addressing mode

Page 72: 8086 Software

Based Indexed addressing Mixing of indexed and register indirect It is modification to indexed addressing

mode Example MOV AX,[BX][SI] Content at the effective address is copied

to AX register Effective address is calculated by adding

the content of base register (BX or BP) to the content of index register(SI or DI)

The effective address 10H*DS+[BX]+[SI]

Page 73: 8086 Software

Relative Base Index addressing Most complex addressing mode Example MOV AX,50H[BX][SI] Content at the effective address is copied

to AX register Effective address is calculated by adding

8 or 16 bit displacement to sum of the content of base register (BX or BP) to the content of index register(SI or DI)

The effective address 10H*DS+50H+[BX]+[SI]

Page 74: 8086 Software

1) Intra segment Direct

The control is to be transferred is in the same segment

The address to which control is to be transferred is appear directly in the instruction

The given displacement is added to the current content of IP

Page 75: 8086 Software

2) Intra segment Indirect

The control is to be transferred is in the same segment

The address to which the control is to be transferred is not appear directly in the instruction

The displacement is found in some register or in some memory location

Page 76: 8086 Software

3) Inter segment Direct

The control is to be transferred is in a different segment

The address to which control is to be transferred is appear directly in the instruction (CS:IP or DS : IP)

The given displacement is Calculated by using (CS:IP or DS : IP)

Page 77: 8086 Software

4) Inter segment Indirect The control is to be transferred is in a

different segment The address to which control is to be

transferred is not appear directly in the instruction

The branch address is the content of memory location containing four bytes IP (LSB), IP (MSB) ,CS (LSB), CS (MSB) sequentially

The starting address is represented using some addressing mode except immediate addressing mode

Page 78: 8086 Software

Programming using debug DEBUG.com is a DOS utility that facilitate

the debugging and trouble shooting features of assembly language programs

C:\users\user pc Cd.. C:\users> Cd.. C:\> C:\>debug

Page 79: 8086 Software

Debug commands -? :- displays all the commands -R :- displays all registers and flags -R reg :- old content : new content :- display specified register contents and modify with the entered new contents eg: R ax -D seg : offset 1 offset 2 :- display memory contents in segment from offset 1to offset 2 eg: D 3000 3005 -D :- display 128 memory location of RAM starting from the current display pointer

Page 80: 8086 Software

-E :-enter hex data at current display pointer -E seg : offset 1 :- Enter hex data at seg: offset 1 by byte. The memory pointer is incremented by

space key, data entry is to be completed by enter key

eg: E 3000 -F seg: offset 1 offset 2 BYTE :- fill the memory locations starting from seg: offset 1 to offset 2 by the byte ‘BYTE’ eg: F 3000 3005 0A -F seg: offset 1 offset 2 BYTE 1 BYTE 2 BYTE 3 :- fill the memory locations starting from seg: offset 1 to offset 2 by the byte BYTE 1 BYTE 2 BYTE 3 eg: F 3000 3002 0A 23 0B

Page 81: 8086 Software

-A :- assemble from the current CS:IP -A seg: offset eg: A 3000 :- Assemble the entered instruction from seg : offset address -U :- un assemble from the current CS:IP -U seg: offset eg: U 3000 :- Un assemble the entered instruction from seg : offset address -G :- Execute from the current CS:IP -G= seg: offset1 offset 2 eg: G= 3000

3005 :- Execute the instructions from offset 1 to offset 2 in the current CS

Page 82: 8086 Software

-S seg: offset1 offset 2 BYTE/BYTES :- search a BYTE or BYTES separated by ‘ ’ in the memory block seg: offset 1 to offset 2 & display all the offset at which the byte is found (eg: S 3000 3005 0A/000A ) -Q :- qui the debug & return to DOS -T seg: offset :- trace the program execution by

single stepping starting from the address seg:offset -M seg: offset 1 offset 2 NB :- move ‘NB’ bytes

from offset one to offset 2 (eg: M 3000 3005 0A) -C seg: offset 1 offset 2 NB :- compare ‘NB’ Bytes

in offset 1 with offset 2 & display the offsets at which the comparison is true(eg: C 3000 3005 0A)

Page 83: 8086 Software

Write a program to add two 16 bit numbers

Write a program to transfer a block of data (8 bit)

mov ax,0006 mov bx,0007 add ax,bx mov [3000],ax hlt

mov si,2000 mov di,3000 mov cx,000aL1:mov al,[si] mov [di],al inc si inc di dec cx jnz L1 hlt

Page 84: 8086 Software

Write a debug program to find the factorial of a given no:

mov si,4000 mov cx,[si] mov ax,0000 inc si inc si mov ax,[si] cmp ax,0000 jz L1

cmp ax,0001 jz L1L3: dec cx jz L2 mul cx jmp L3 L1: mov ax,0001 L2: mov [3000],ax hlt

Page 85: 8086 Software

Write a program to find the largest among a set of 10 nos

Write a program to find the square root of a given no.

mov si,2000 mov cx ,000a mov ax,[si]L1: inc si inc si dec cx jz end cmp ax,[si] jnc L1 mov ax, [si] jmp L1END: mov si,3000 mov [si],ax hlt

mov si,2000 mov al,[si]mov bl,01 mov cl,00 L1: sub al,bljc L2inc cl inc bl inc bl jmp L1 L2: mov si,3000 mov [si],clhlt

Page 86: 8086 Software

Write a program to generate fibanocci seriesmov si,4000

mov cx,[2000]mov ax,0000mov [si],axdec cxjz ENDmov bx,0001inc siinc simov [si],bxdec cx

jz END L1: inc si

inc siadd ax,bxmov [si],axmov ax,bxmov bx,[si]dec cxjnz L1

END:hlt

Page 87: 8086 Software

Development tools Programs which can be run to perform

some functions on the user program Some manuals are there to help the

programmer

Page 88: 8086 Software

Editor Program which allows the user to create file

containing assembly language statements eg:- PC write ,word store The editor comes with assemblers As you type the program ,the editor stores the

ASCII codes of the letters and no's in successive RAM locations

Editor let you to insert new line &move everything down

After typing you can save the program as a source file with an extension .ASM

eg:- sum.asm

Page 89: 8086 Software

Assembler Program used to translate assembly

language mnemonics to corresponding binary words

It reads the source file On first pass, determines the

displacement of data items & offset of labels etc.

On Second pass it produce the binary codes and inserts the displacement and offset etc calculated in the first pass

Page 90: 8086 Software

It generates two files Object file with extension .OBJ contain

binary codes the second file called list file with

extension .LST contain instruction along with binary codes & offset for each instruction

Assembler list the typing or syntax error in the source program

Page 91: 8086 Software

Linker

Program used to join several object files into one large object file for writing large program

We can divide the large program into smaller modules

Each module can be individually written, tested, debugged.

When all modules works, their object modules can be linked together to form large program

Page 92: 8086 Software

On IBM PC we must run link program on our .OBJ file(even it contains only one module)

It produces a link file which contains the binary codes for all modules

It also produces a link map file which contains the address information about the linked files

Link files have an extension .EXE

Page 93: 8086 Software

Locator

Program used to assign the specific address of where the segments of object code are to be loaded into memory

A locator program called EXE2BIN comes with DOS converts .EXE file to a .BIN file which has physical address

Page 94: 8086 Software

Debugger If the program does not need an external

hardware ,you can use a debugger to run and debug your program .

It allows to load the object code to system memory ,execute and debug it

You can change the contents of registers and memory locations

Page 95: 8086 Software

The program allows the uses to stop the execution after each instruction

It allows you to insert break points in the program

It allows you to find the problems in the source program

A basic debugger is there with DOS

Page 96: 8086 Software

Emulator Mixture of hardware and software Used to test & debug the software and

hard ware of an external system A multi wire cable connects the host

system to the system being developed Through this connection the software of

the emulator allows the user to download the object code program into the system being test & run it

Page 97: 8086 Software

It allows us to load ,run ,examine, change the contents of memory and register and insert break point

Emulator takes the snap shot of the contents of register & activity on address and data bus and state of flags as instruction executes

This trace data is stored in a large RAM A print out of trace data can be taken to

see the result of program execution

Page 98: 8086 Software

Programming using Assembler

Assemble is used to convert the mnemonics of instruction along with the data into their equivalent object code modules

These object modules are then converted to executable by using linker and loader programs

Hence mnemonics are directly used in the program

Page 99: 8086 Software

Assembly language programming using MASM

(Microsoft assembler) MASM needs the source program as its

input &provides an object file(.OBJ). The LINK accepts the object file provides

an EXE file. To write the ,use a text editor and save it

with an extension “.ASM” . The MASM must be installed in your PC

Page 100: 8086 Software

Steps C:\users\user pc Cd.. C:\users> Cd.. C:\> D: D:\> cd masm D:\masm

Page 101: 8086 Software

Steps…….. Step 1: Edit Step 2: Enter or type the program Step 3: Save as “filename.asm” Step 4: Quit editor Step 5: Assembling process D:\masm> D:\masm> masm filename.asm .LINK file created

Page 102: 8086 Software

Steps…….. Step 6: Linking process D:\masm> LINK filename.obj .EXE file created Step 7: Execution process D:\masm> filename Step 8: Final output. This will open the output window

Page 103: 8086 Software

Some predefined alphabetical strings called ”directive”

Used to give hints to the assembler while doing assembling process

Another type of hints which helps to assign a particular constant with a label or initialize particular memory locations or labels with constants is called “operator”

Assembler directives and operators

Page 104: 8086 Software

ASSEMBLER DIRECTIVES

1] ASSUME Used to tell assembler the name of logical segment. eg: ASSUME CS: Code, DS:DATA

2] END 3] DB :- Define byte. Used to reserve byte/bytes in memory. User can also initialize these bytes with ASCII codes of characters specified as string eg: Ranks DB 01H,02H 03H,04H mes DB ‘good morning’

Page 105: 8086 Software

ASSEMBLER DIRECTIVES Cont… 4] DW:-Define word. Reserves no of memory words eg: words DW 1234 H,5678H wdata DW 5 dup(6666H)5] DD Define Double Word6] DQ Define Quad Word7] DT Define Ten Bytes

Page 106: 8086 Software

ASSEMBLER DIRECTIVES Cont…

8] PROC Procedure 9] ENDP :- End of procedure10] ENDS:- End of segment11] EQU Assign a value or a symbol 12] EVEN: Align on even memory address.13] OFFSET 14] PTR Pointer :- specify data type

eg:PROC procedure name

Procedure name ENDP

eg: DATA SEGMENT

DATA ENDS

eg: EVEN PROC ROOT

ROOT ENDP

eg: CREATE EQU ADD LABEL EQU 0003eg: MOV SI ,OFFSET LISTeg: MOV AL,BYTEPTR[SI]

Page 107: 8086 Software

ASSEMBLER DIRECTIVES Cont…

15]ORG :-starts the memory allotment for the segment from declared address

16]LABEL Ex: AGAIN LABEL FAR

17] PUBLIC Links modules together

18] EXTRNTells the assembler that the names or labels following this directive is in some other assembly module as PUBLIC

eg: ORG 2000eg: mod1 segment public Factorial mod1 ends mod2 segment extern factorial mod2 ends

Page 108: 8086 Software

ASSEMBLER DIRECTIVES Cont…

19] GROUP:-Grouping of logical segments. eg: program group CODE,DATA Assume CS:program ,DS: program20] NAME

To give specific name to module.21] INCLUDE

Include source code from file.22] SEGMENT23] SHORT

Operator that tells assembler about short displacement.

24] TYPE :-Type of variable whether byte or word. for byte data type=1 for word=2 for double word =425] GLOBAL,LOCAL

eg: JMP SHORT LABELeg: Mov ax, type string

Page 109: 8086 Software

DOS Function calls under INT 21H

DOS acts as a user interface with computer hardware resources( memory, CRT display Hard disc, Floppy disc etc. )

Handled with the help of the instruction INT 21H in DOS Under this INTERRUPT ,the specific resources

are selected depending on the value in AH Order is following :- MOV AH,XXH INT 21 H

Page 110: 8086 Software

Different INT 21H functions If AH = 09H

Displays the string pointed by DS:DX If AH = 01H The keyboard entry is accepted & its value is store

in AL register If AH = 4CH This will bring the computer to DOS prompt If AH = 0AH Reads the string from keyboard and stores to the

location pointed by DS: DX. Function will terminate when enter key is pressed

If AH = 02H It will send a character in DL to CRT display

Page 111: 8086 Software

String Group of numbers or characters 12321122H ASDFGHJKL asdfghjkl

Page 112: 8086 Software

Procedures A set of repeated instructions in program A CALL instruction is used to call procedure This will send the processor to the starting address

of procedure while execution Stack segment is used store the current execution

details for further execution A RET instruction return execution control to the

next instruction in main line While using procedure the machine codes

corresponding to the repeated instruction is put in memory only one

Disadvantage is the time required for call and return process

Page 113: 8086 Software

Macros When repeated instruction are too short

we can use a MACRO MACRO is a group of instruction with a

name normally given at the starting of a program

Each time we call macro, the assembler will insert the group of instruction in the place of call

Assembler generates the machine code each time

Page 114: 8086 Software

So program take up more memory than procedure

But it saves the overhead time involved in calling and returning the procedure

Syntax Macro name MACRO

parameters

ENDM

Page 115: 8086 Software

Steps to write an assembly language program

After studying the problem, decide the logical segment required

Almost all program require DATA & CODE segments

The labels DATA & CODE is reserved by MASM as the names of code and data segments

All the data are declared in DATA segment DATA ENDS marks the end of data segment CODE segment contains the instruction

Page 116: 8086 Software

The label START is starting point of execution sequence

The ASSUME directive informs the assembler that the label CODE is used for code segment & DATA for data segment

CS automatically loads with address corresponding to the label CODE at the time of execution

But DS is to be loaded by the programmer

Page 117: 8086 Software

So the first two lines performs this task MOV AX,DATA MOV DS, AX The function of INT 21 H with 4CH in Ah is

used as last instruction which returns the computer to DOS prompt

The statement CODE ENDS marks the end of code segment

END START denotes the end of procedure stated with label START

Page 118: 8086 Software

General format of assembly language program

DATA SEGMENT

DATA ENDSCODE SEGMENTASSUEME CS:CODE,DS:DATASTART: MOV AX, DATA MOV DS,AX

MOV AH,4CHINT 21HCODE ENDSEND START

Page 119: 8086 Software

NOTE(remember) While displaying messages . They must

be terminated using “$” The characters 0AH and 0DH are used

as the time feed &carriage feed for displaying purpose

0AH brings the cursor to next position 0DH brings the cursor to next line eg: MSG0 DB “Hello$” MSG1 DB 0DH ,0AH “Good

Morning$”

Page 120: 8086 Software

Wap to print hello Wap to print hello using macro

data segment string db “hello$”data endscode segment assume cs: code, ds: datastart: mov ax , data mov ds , ax mov dx , offset string mov ah,09h int 21h mov ah,4ch int 21hcode endsend start

print macro args mov dx, offset args mov ah,09h int 21hendmdata segmentm1 db “hello$”m2 db 0dh,0ah,”good morning$”data endscode segment assume cs: code, ds: datastart: mov ax , data mov ds , ax print m1 print m2 mov ah,4ch int 21hcode endsend start

Page 121: 8086 Software

Wap to add two no.sdata segment x db 01h y db 02h r db 02dup(?)data ends code segment assume cs: code, ds: datastart: mov ax , data mov ds , ax mov ax , x

add ax , y mov di, offset r mov [di] , ax mov ah,4ch int 21hcode endsend start

Page 122: 8086 Software

Wap to add two numbers entered through keyboard and show the result

print macro msg mov dx, offset msg mov ah,09h int 21hendmdata segment cr equ 0dh lf equ 0ah msg1 db “enter the 1st no:$”msg2 db cr,lf, ”enter 2nd no:$”msg3 db cr,lf,”sum=$” sum dw 0000h outs dw 10 dup(?)data ends

code segment assume cs: code, ds: datastart: mov ax , data mov ds , ax print msg1 call read add sum , cx print msg2 call read add sum,cx

Page 123: 8086 Software

print msg3 mov ax , sum call disp print outs mov ah,4ch int 21h

read proc mov ax,0000h mov bx,000ah mov cx,0000hL1: mov ah,01h int 21h cmp al.0dh jz L2 mov ah,00h sub al,30h push ax mov ax,cx mul bx mov cx,ax pop ax add cx,ax jmp L1 L2: ret read endp

Page 124: 8086 Software

disp proc mov bx,000ah mov cx,0000h mov di , offset outs mov dx,0024h push dx inc cx L3: mov dx,0000h div bx add dx,0030h push dx inc cx cmp ax,0000h jz L3 L4: pop [di] inc di loop L4 retdisp endpcode ends end start

Page 125: 8086 Software

Wap to find the factorial of a number

print macro msg mov dx, offset msg mov ah,09h int 21hendmdata segment cr equ 0dh lf equ 0ah msg1 db “enter the no:$” msg2 db cr,lf, ”factorial=1$” msg3 db cr,lf, ”factorial=$” outs dw 10 dup(?)data ends

code segment assume cs: code, ds: datastart: mov ax , data mov ds , ax print msg1 call read cmp cx,0000h jz L5 mov bx,0000h mov ax,0001h

Page 126: 8086 Software

L6: push cx inc bx mul bx pop cx dec cx jnz L6 print msg3 call disp

print outs jmp L7L5: print msg2L7: mov ah,4ch int 21hread procdisp proccode ends end start

Page 127: 8086 Software

Wap to check the given no is prime or not

print macro msg mov dx, offset msg mov ah,09h int 21hendmdata segment cr equ 0dh lf equ 0ah m1 db “enter the no:$” m2 db cr,lf, ”prime$” m3 db cr,lf, ”not prime$” m4 db cr,lf, ”neither prime nor composite$” data ends

code segment assume cs: code, ds: datastart: mov ax , data mov ds , ax print m1 call read cmp cx,0000h jz L5 cmp cx,0001h jz L5 mov bx , cx

Page 128: 8086 Software

L7: mov dx,0000h push cx dec bx cmp bx,0001h jz L6 pop ax mov cx,ax div bx cmp dx,0000h jnz L7

print m3 jmp L8L6: print m2 jmp L8L5: print m4L8: mov ah,4ch int 21hread procdisp proccode ends end start

Page 129: 8086 Software

Wap to reverse a stringprint macro msg mov dx, offset msg mov ah,09h int 21hendmdata segment cr equ 0dh lf equ 0ah m1 db “enter the string$” m2 db cr,lf, ”entered string$” m3 db cr,lf, ”reversed string$” outs1 dw 10 dup(?) outs2 dw 10 dup(?)data ends

code segment assume cs: code, ds: datastart: mov ax , data mov ds , ax print m1 mov si , offset outs1 mov cx, 0000hL1: mov ah,01h int 21h cmp al,0dh jz L2

Page 130: 8086 Software

mov [si],al inc si inc cx jmp L1 print m2 print outs1L2: mov di , offset outs2L3: dec si mov al,[si] mov [di],al inc di loop L3

mov al,24h mov [di],al print m3 print outs2 mov ah,4ch int 21hcode ends end start


Recommended