/
Assembly Language for Intel 8086 Assembly Language for Intel 8086

Assembly Language for Intel 8086 - PowerPoint Presentation

lindy-dunigan
lindy-dunigan . @lindy-dunigan
Follow
457 views
Uploaded On 2016-05-18

Assembly Language for Intel 8086 - PPT Presentation

Jump Condition Ch 6 Assembly Language Programming by Charls Marut Some materials are from Dr Sazzad NSU Topic Control Flow Structure Conditional Jump Unconditional Jump Control Flow Structures ID: 325407

jumps jump unsigned label jump jumps label unsigned signed equal jmp instruction jnz code top conditional ascii destination cmp

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Assembly Language for Intel 8086" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

Assembly Language for Intel 8086Jump Condition

Ch

6, Assembly Language Programming – by

Charls

Marut

Some materials are from Dr.

Sazzad

, NSUSlide2

TopicControl Flow StructureConditional Jump

Unconditional Jump

Control Flow Structures

Branches with Compound ConditionsSlide3

An Example of JumpDisplay the entire IBM character set

.MODEL SMALL

.CODE

.STARTUP

MOV

AH, 2 ; display char function MOV CX, 256 ; no. of chars to display MOV DL, 0 ; DL has ASCII code for null charPRINT_LOOP: INT 21H ; display a char INC DL ; increment ASCII code DEC CX ; decrement counter JNZ PRINT_LOOP: ; keep going if CX not 0 .EXIT END

Calls system routine/functions

Section 6-1 of Assembly Language Programming Book

The function number

Statement label

Labels r needed in cases where one instruction refers to another.Slide4

Conditional JumpsJNZ Syntax: Jxxx destination_label

True or False

[no gray area – like our minds!]

JNZ

is an example of conditional jump instruction

Checks the Z flag. If Z = 0 then jump to the location

Three categories of conditional jumpsSigned jumps, for signed interpretationUnsigned jumps, for unsigned interpretationSingle-flag jumps, operates on settings of individual flagsSlide5

How to decide? Implement?CPU looks at the FLAGS registerIf jump conditions r TRUE – the CPU adjusts the IP [instruction pointer 3.2.5] to point to the

destination_label

,

so that the instruction at this label will be done next.

If FALSE – no change in IPSlide6

1. Signed Conditional Jumps

Opcodes

Description

Condition for

jumps

JG/JNLE

Jump if Greater thanJump if Not Less than or Equal toZF = 0 and SF = OFJGE/JNLJump if Greater than or Equal toJump if Not Less thanSF = OFJL/JNGEJump if Less thanJump if Not Greater than or Equal toSF <> OFJLE/JNGJump if less than or equal

Jump if not greater thanZF = 1 or SF <> OFSlide7

2. Unsigned Conditional Jumps

Symbol

Description

Condition for

jumps

JA/JNBE

Jump if aboveJump if not below or equalCF = 0 and ZF = 0JAE/JNBJump if above or equalJump if not belowCF = 0JB/JNAEJump if belowJump if not above or equalCF = 1JBE/JNAJump if below or equalJump if not aboveCF = 1 or ZF = 1Slide8

3. Single-Flag Jumps

Symbol

Description

Condition for

jumps

JE/JZ

Jump if equalJump if equal to zeroZF = 1JNE/JNZJump if not equalJump if not zeroZF = 0JCJump if carryCF = 1JNCJump if no carryCF = 0JOJump if overflowOF = 1JNO

Jump if no overflowOF = 0

JSJump if sign negative

SF = 1JNS

Jump if nonnegative sign

SF = 0JP/JPE

Jump if parity evenPF = 1

JNP/JPO

Jump if parity odd

PF

= 0Slide9

Range of a Conditional JumpThe destination label must precede the Jump

instruction by no more than 126 bytes

Or, follow by no more than 127 bytes

LABEL

:

; statement

; statement JNZ LABEL126 bytesJZ LABEL ; statements ; statementsLABEL: ; statement ; statement

127 bytes

refSlide10

CMP InstructionThe jump condition is often provided by the CMP (

compare

) instruction

CMP

destination, source

 dest[contents] – source[contents]It is like SUB, except that destination is not changedDestination may not be a constantThe result is not stored but the flags are affectedCMP AX, BXJG BELOW ;JG – jump if >CMP AX, 10JG BELOWIf AX = 7FFFh, and BX = 0001h, the result is 7FFFh - 0001h = 7FFEh. ZF = SF = OF = 0, JG is satisfied, so control transfers to label BELOWSlide11

Signed vs. Unsigned JumpsEach signed jump corresponds to an analogous unsigned jump e.g., signed JG (if

>

) corresponds to unsigned JA (

if above

)

Use depends on the interpretation

The jumps operate on different flagsSymbolDescriptionCondition for jumpsJG/JNLEJump if greater thanJump if not less than or equal toZF = 0 and SF = OFJA/JNBEJump if aboveJump if not below or equalCF = 0 and ZF = 0Wrong jumps  wrong results! [same as life]Slide12

Signed vs. Unsigned Jumps cont.

For

signed

interpretation, let us take

AX = 7FFFh, BX = 8000h and we execute

Even though 7FFFh > 8000h in a signed sense, the program does not jump to BELOW_LABEL

 why?Because 7FFFh < 8000h in an unsigned senseJA, which is the unsigned jumpCMP AX, BXJA BELOW_LABELSlide13

With standard ASCII character set [character code 0-31 for control chars; 32-127 for printable characters] – either signed/unsigned jumps may be used.Why?Because the

sign bit

of a

byte

containing a character code is always

 zero [0].

BUT, unsigned jumps should be used when comparing extended ASCII characters [code 80h ~ FFh] Signed vs. Unsigned Jumps cont.working with CHARSlide14

Extended ASCII codes (character code 128-255)There are several different variations of the 8-bit ASCII table. E.g., ISO 8859-1, also called ISO Latin-1. Codes 129-159 contain the Microsoft® Windows Latin-1 extended characters.

http://www.ascii-code.com/Slide15

The JMP InstructionJMP (jump) instruction causes an

unconditional

jump

Syntax is:

JMP

can be used to get around the range restriction [126/127 byte]Flags – no changeJMP destination/target_labelTOP:; body of the loop, say 2 instructionsDEC CX ; decrement counterJNZ TOP ; keep looping if CX > 0MOV AX, BXTOP:; the loop body contains so many instructions ; that label TOP is out of range for JNZ. Solution is- DEC CX JNZ BOTTOM JMP EXITBOTTOM: JMP TOPEXIT: MOV AX, BX

Section 6-3: Assembly Language Programming

refSlide16

TOP:; the loop body contains so many instructions

; that label TOP is out of range for JNZ.

Solution is-

DEC CX

JNZ

BOTTOM

JMP EXITBOTTOM: JMP TOPEXIT: MOV AX, BXWhen CX=0 - It will not Jump to BOTTOM It will go to next instr. JMP EXIT JMP TOP  is unconditional – just Jump!