[PDF] [PDF] 8086 Programming

23 oct 2012 · instructions are decoded by processor during execution cycle opcode – same as last example: 111111 000 w = 0 For each instruction – whether in textbook or in processor's programming manual - the permitted operands 



Previous PDF Next PDF





[PDF] 8086 assembler tutorial for beginners (part 1) what is assembly

flags register - determines the current state of the microprocessor IP register you can copy paste the above program to emu8086 code editor, and press



[PDF] UNIT-2 8086 ASSEMBLY LANGUAGE PROGRAMMING

MICROPROCESSORS AND MICROCONTROLLERS Page 1 UNIT-II The 8086 instructions are categorized into the following main types (i) Other MOV instructions examples are given below with the corresponding addressing modes



[PDF] Microprocessor and Programming - Shri Datta Meghe Polytechnic

Instruction Set of 8086 Microprocessor Apply instructions in Assembly Language Program for Describe microprocessor evolution with suitable example?



[PDF] Examples Programs Using 8086 Microprocessor Instructions

24 avr 2019 · April 27th, 2019 - Assembly Language Programming 8086 Tutorial Pdf Masm 8086 Tutorial Pdf download free X86 Assembly Wikibooks open 



[PDF] Assembly Language Tutorial - Tutorialspoint

The registers are processor components that hold data and address To execute a program the system copies it from the external device into the internal memory



[PDF] Tutorial Emu86

2) 8086 assembler tutorial for beginners (part 1) this tutorial is intended the set of bytes, this set is called machine code, processor understands the machine 



[PDF] 8086 Programming

23 oct 2012 · instructions are decoded by processor during execution cycle opcode – same as last example: 111111 000 w = 0 For each instruction – whether in textbook or in processor's programming manual - the permitted operands 



[PDF] Assembly Language Programming 8086 Examples - teachmeeduvn

5 mai 2018 · Understanding 8085 8086 Microprocessors Programming Examples For 8086 Online Programming 8086 Tutorial Pdf Assembly



[PDF] 8086 Microprocessor Tutorial Pdf - niaschilbioblas

From Ashkelon Nuclear Research Centre: 8086 assembler and microprocessor emulator Study computer architecture and assembly language programming

[PDF] microprocessor 8086 programs with explanation pdf

[PDF] microprocessor 8086 programs with flowchart

[PDF] microprocessor 8086 textbook pdf free download

[PDF] microprocessor and assembly language lecture notes

[PDF] microprocessor and assembly language notes pdf

[PDF] microprocessor and microcontroller lab manual

[PDF] microprocessor and microcontroller lab manual for ece free download

[PDF] microprocessor architecture pdf

[PDF] microprocessor assembly language programming notes

[PDF] microprocessor book pdf

[PDF] microprocessor book pdf for engineering

[PDF] microprocessor by u.s. shah pdf

[PDF] microprocessor lab

[PDF] microprocessor lab manual r=h:edu

[PDF] microprocessor lab manual sppu

8086 Programming

Compiled by: Chandra Thapa

October 23, 2012

UNIT I

Concept (not important for exam and not in syllabus)

Instruction Encoding

How to encode instructions as binary values?

Instructions consist of:

i operation (opcode) e.g. MOV i operands (number depends on operation) i operands specified using addressing modes i addressing mode may include addressing information i e.g. registers, constant values Encoding of instruction must include opcode, operands & addressing information.

Encoding:

i represent entire instruction as a binary value i number of bytes needed depends on how much information must be encoded i instructions are encoded by assembler: i .OBJ file ! (link, then loaded by loader) i instructions are decoded by processor during execution cycle

We will consider a subset of interesting cases

Instructions with No Operands

(easy) i encode operation only in a single byte i examples: RET

C3 H NOP 90 H

i Are consistent - never change

Instructions with One Operand

i operand is a register (reg8/16) or a memory operand (mem8/16) i always 2 bytes for opcode and addressing info i may have up to 2 more bytes of immediate data i opcode bits: some in both bytes! 10 bits total i w = width of operand

0 = 8-bit

1 = 16-bit

i mod & r/m encode addressing info opcode w

7 1 0

mod opcode r/m

7 6 5 4 3 2 1 0

MOD / R/M TABLE

mod

00 01 10 11

r/m w = 0 w = 1

000 [BX + SI] [BX + SI + d] [BX + SI + n] AL AX

001 [BX + DI] [BX + DI + d] [BX + DI + n] CL CX

010 [BP + SI] [BP + SI + d] [BP + SI + n] DL DX

011 [BP + DI] [BP + DI + d] [BP + DI + n] BL BX

100 [SI] [SI + d] [SI + n] AH SP

101 [DI] [DI + d] [DI + n] CH BP

110 direct ad [BP + d] [BP + n] DH SI

111 [BX] [BX + d] [BX + n] BH DI

d is 8-bit signed value n is 16-bit unsigned value register direct address mod = 01 is not used by the assembler!

Example:

INC DH

opcode : 1st byte: 1111111 2nd byte: 000 w = 0 (8-bit operand) operand = DH register: mod = 11 r/m = 110 opcode w

1st byte: 1111111 0 = FE H

mod opcode r/m

2nd byte: 11 000 110 = C6 H

What does following encoding represent?

11111111 11000111 = FF C7 H

opcode = INC 1st byte: 1111111 2nd byte: 000 w = 1 16-bit operand mod = 11 register operand r/m = 111 DI register encoding for

INC DI !!!

Another Example:

INC BYTE PTR [SI - 4]

i indexed addressing to an 8-bit memory operand i will need extra byte(s) to encode the immediate value (4 = FFFC H) from table! opcode - same as last example: 111111 000 w = 0 8-bit destination (memory) operand r/m = 100 (from table) mod could be 01 or 10 depends on constant can use whichever mod value works can shorten encodings! the assembler will use mod = 10

16-bit constant (FFFCH) encoded into instruction

little endian resulting instruction encoding: byte 1 byte 2 byte 3 byte 4

1111111 0 10 000 100 11111100 11111111

FE 84 FC FF H

Could also encode same instruction:

mod = 01 constant encoded as signed 8-bit value therefore instruction encoding includes only one byte for the encoding of - 4 resulting instruction encoding: byte 1 byte 2 byte 3

1111111 0 01 000 100 11111100

FE 44 FC

H N.B. the 8-bit value (- 4 = FC H) is sign extended to 16-bits (FFFC H) before adding SI value why?

Another Example:

INC BYTE PTR [SI + 128]

i indexed addressing to an 8-bit memory operand i everything the same as last example, except: can "t encode +128 as 8-bit signed value! need 16-bits to encode 128 then must have mod = 10 !! instruction encoding would include two extra bytes encoding 128 = 00 80 H resulting instruction encoding: byte 1 byte 2 byte 3 byte 4

1111111 0 10 000 100

FE 84 00 80 H

Instructions with Two Operands (2 Forms)

i at most, can have only one memory operand i can have 0 or 1 memory operands, but not 2 i limits max. instruction size to 6 bytes little endian mod ! value of most signif. bit of byte is copied to all bits in extension byte i e.g. MOV WORD PTR [BX+ 500], 0F0F0H i 2 bytes opcode + addressing info i 2 bytes destination addressing constant 500 i 2 bytes source constant F0F0 H FORM 1: Two Operands And Source Uses Immediate Mode i destination either register or memory i encode dest using mod & r/m - as before w (as before) = size of operand (8- or 16-bit) if w = 1 (16-bit) then s is significant s  indicates size of immediate value

0  all 16-bits encoded in instruction

assembler always used s = 0 = 1  8-bits encoded - sign extend to 16-bits!

Example:

SUB My_Var, 31H

i My_Var is a word (DW) stored at address 0200H opcode bits: 1st byte: 100000 2nd byte: 101 w = 1 (16-bit memory operand) s = 1 - can encode 31H in one byte sign extend to 0031H opcode s w

7 2 1 0

mod opcode r/m

7 6 5 4 3 2 1 0

mod = 00 r/m = 110 resulting encoding: opcode

100000 1 1 00 101 110 2-bytes dest 1-byte

address imm s w mod r/m

83 2E 02 00 31

FORM 2: Two Operands And Source Does Not Use Immediate Mode i at least one of destination or source is register! i encode register operand i encode other using mod & r/m - as before d = destination

0 source is encoded in REG

1 destination is encoded in REG

opcode d w

7 2 1 0

mod REG r/m

7 6 5 4 3 2 1 0

destination: direct addressing stored little endian assembler uses s = 0 & 16-bit immediate value

31 00 (little endian)

Example: SUB My_Var , SI

opcode:

0010 10

suppose My_Var is @ address 0020H d = 0 - source is a register - encoded in REG w = 1 - 16-bit operand mod = 00 destination is memory - direct mode r/m = 110

REG = 110

(SI) encoding:

001010 0 1 00 110 110 addrs const

29 36 20 00

NOTE : different first-byte opcode bits for SUB when source is immediate (100000) vs. when source is not immediate (001010) The opcode bits for FORM 1 vs. FORM 2 instructions are different!

MOV [BX], 200

MOV [BX] , AX

i what if both source and destination are registers? i should REG encode source or destination?

Example: SUB BX, CX

d w mod register encoding as in mod = 11 column in table different opcode bits! r/m

Case 1: Source (CX) is encoded in REG

opcode: 0010 10 d = 0 - source is encoded in REG w = 1 - 16-bit operand mod = 11 destination is register r/m = 011 BX register is destination register

REG = 001

CX register is source register

encoding:

001010 0 1 11 001 011

29 CB

Case 2:

Destination (BX) is encoded in REG

opcode: 0010 10 d = 1 - destination is encoded in REG w = 1 - 16-bit operand mod = 11 source is register r/m = 001 CX register (source)

REG = 011

BX register (destination)

encoding:

001010 0 1 11 011 001

29 D9

d w mod r/m i cases 1 & 2: two encodings for same instruction!

Some Special-Case Encodings:

i single-operand instructions & operand is 16-bit register - can encode in one byte i instructions involving the accumulator:

AL or AX

i shorter encoded forms - often one byte

WHY? What use are these special cases?

Instruction Encoding (human perspective)

1. given instruction - how to encode ? 2. given binary - how to decode ?

Given instruction - how to encode ?

i decide on form & number of bytes i find opcode bits from table i decide on remaining bits y individual bit values y look up mod & r/m values if needed y look up register encoding if needed i fill opcode byte(s) i add immediate operand data byte(s) y words  little endian y dest precedes source

Given binary - how to decode ?

i use first 6 bits of first byte to decide on form & number of bytes i use opcode bits to find operation from table i identify operands from remaining bits y individual bits

Why might this be important? EXAM !!!!

y look up mod & r/m values if present y look up register encoding if present i add immediate operand data byte(s) if present y words  little endian y dest precedes source

Could you hand-assemble a simple program now?

YES! recall previous control flow

encoding discussions

What about an operation / opcode look-up table?

i many forms - some give: y opcode bits only y entire first instruction byte - including operand info encoded in first byte! i list of info for each instruction will be posted! y opcode bits y forms

UNIT II

Overview of the 80x86

80x86 register model,

segmented memory model instruction execution.

8086 Register Set

16-Bit General Purpose Registers

H can access all 16-bits at once

H can access just high (H) byte, or low (L) byte

AX BX CX DX

16-Bit

Segment Addressing Registers

CS Code Segment

DS Data Segment

SS Stack Segment

ES Extra Segment

16-Bit

Offset Addressing Registers

SP Stack Pointer

BP Base Pointer

SI Source Index

DI Destination Index

AH AL

BH BL

CH CL

DH DL 8-bit 8-bit

16-bit

only the General

Purpose registers allow

access as

8-bit High/Low sub-

registers

16-Bit Control/Status Registers

IP Instruction Pointer (execution control)

FLAGS Status Flags - one bit/flag

H 16-bit reg, but only 9 bits have meaning

H text: page 27

H ignore unused bits

H usually interested in individual flags

H not 16-bit value

Quick Overview of 80x86 Flag

Flag Name Description

C Carry

A Auxiliary Carry

O Overflow

S Sign

Z Zero

D Direction

I Interrupt

T Trap

H Flags are set and cleared as “side-effects" of an instruction Part of learning an instruction is learning what flags is writes H There are instructions that “read" a flag and indicate whether or not that flag is set or cleared.

Other Registers in Programmer"s Model

H support the execution of instructions

H cannot be accessed directly by programmers

H may be larger than 16-bits:

temporary reg "s (scratchpad values)

IR Instruction Register

Segmented Memory Model:

Processor Design Problem

: How can 16-bit registers and values be used to specify 20-bit addresses?quotesdbs_dbs17.pdfusesText_23