CE302 MICROPROCESSORS Levent EREN Izmir University of Economics.

Slides:



Advertisements
Similar presentations
Jump Condition.
Advertisements

CDP ECE Spring 2000 ECE 291 Spring 2000 Lecture 4: The 80x86 Instruction Set Architecture Registers-Instructions Constantine D. Polychronopoulos.
Micro-Computer Applications: Jumping and Loop Dr. Eng. Amr T. Abdel-Hamid ELECT 707 Fall 2011.
Department of Computer Science and Software Engineering
ACOE2511 Assembly Language Arithmetic and Logic Instructions.
The CPU Revision Typical machine code instructions Using op-codes and operands Symbolic addressing. Conditional and unconditional branches.
LAB Flow Control Instructions
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
1 Homework Reading –PAL, pp Machine Projects –MP2 due at start of Class 12 Labs –Continue labs with your assigned section.
Gursharan Singh Tatla Block Diagram of Intel 8086 Gursharan Singh Tatla 19-Apr-17.
Unit-1 PREPARED BY: PROF. HARISH I RATHOD COMPUTER ENGINEERING DEPARTMENT GUJARAT POWER ENGINEERING & RESEARCH INSTITUTE Advance Processor.
ECE291 Lecture 4 Jumping in head first. ECE 291 Lecture 4Page 2 of 42 Lecture outline Multiplication and Division Program control instructions Unconditional.
An Introduction to 8086 Microprocessor.
Microprocessor Programming II
3.7 String Instructions Specifying the Operands’ Size and Address and the String Direction STRING = a data collection in memory. String ELEMENTS can be:
Lecture 3 Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.
Low Level Programming Lecturer: Duncan Smeed Low Level Program Control Structures.
Types of Registers (8086 Microprocessor Based)
Chapter 4 - Implementing Standard Program Structures in 8086 Assembly Language from Microprocessors and Interfacing by Douglas Hall.
Lecture 5 Multiplication, Division and Branches Dr. Dimitrios S. Nikolopoulos CSL/UIUC.
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 4 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
(Flow Control Instructions)
Executing and Linking an assembly program. Lesson plan Review Program logic and control Practice exercise Assembling, Linking and Executing Programs Practice.
Computer Architecture and Organization
1 ICS 51 Introductory Computer Organization Fall 2009.
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 5 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
Microprocessor Programming II To discuss more complicated programming techniques Flag control instructions Compare and jump Subroutines Loop and string.
Intel 8086 (8088) Microprocessor Structure
LEA instruction The LEA instruction can be used to get the offset address of a variable Example ORG 100h MOV AL, VAR1 ; check value of VAR1 by moving it.
October 1, 2003Serguei A. Mokhov, 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003.
3.4 Addressing modes Specify the operand to be used. To generate an address, a segment register is used also. Immediate addressing: the operand is a number.
2/20/2016CAP 2211 Flow Control Instructions. 2/20/2016CAP 2212 Transfer of Control Flow control instructions are used to control the flow of a program.
Microprocessor & Assembly Language Arithmetic and logical Instructions.
Jumps, Loops and Branching. Unconditional Jumps Transfer the control flow of the program to a specified instruction, other than the next instruction in.
Internal Programming Architecture or Model
Selection and Iteration Chapter 8 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Intel 8086 MICROPROCESSOR ARCHITECTURE
Part of the Assembler Language Programmers Toolbox
Assembly Language Programming of 8085
Microprocessor T. Y. B. Sc..
Homework Reading Labs PAL, pp
Introduction to 8086 Microprocessor
8086 Microprocessor.
Instruksi Set Prosesor 8088
Microprocessor and Assembly Language
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Machine control instruction
INSTRUCTION SET.
More on logical instruction and
Assembly Language Programming Part 2
Intel 8088 (8086) Microprocessor Structure
Microprocessor and Assembly Language
Flags Register & Jump Instruction
Intel 8088 (8086) Microprocessor Structure
Lecture 1 Instruction set of 8086 Лектор: Люличева И.А. 1.
Program Logic and Control
Program Logic and Control
Homework Reading Machine Projects Labs PAL, pp
Flow Control Instructions
CNET 315 Microprocessor & Assembly Language
EECE.3170 Microprocessor Systems Design I
Assembly Language for Intel 8086 Jump Condition
Chapter 7 –Program Logic and Control
The JUMP GROUP Unconditional Jump (JMP).
Chapter 8: Instruction Set 8086 CPU Architecture
Chapter 7 –Program Logic and Control
Part I Data Representation and 8086 Microprocessors
Presentation transcript:

CE302 MICROPROCESSORS Levent EREN Izmir University of Economics

CE302 Outline Unconditional jump Conditional branching Construction of loops

CE302 Unconditional Jump JMP Short jump 2-byte instruction that allows jumps or branches to memory locations within +127 and -128 bytes from the memory location following the jump JMPSHORT Label Near jump 3-byte instruction that allows jumps or branches within +/- 32Kb from the instruction in the current code segment JMPLabel Far jump 5-byte instruction that allows a jump to any memory location with in the entire memory space JMPLabel For 80386, 80486, the near jump is within +/-2G if the machine operates in the protected mode and +/-32K bytes if operates in the real mode OPCODE DISP OPCODE DISP low DISP high OPCODE IP low IP high CS low CS high

CE302 Conditional Branching Logic and arithmetic instructions set flags Flags provide state information from previous instruction(s) Using flags we can perform conditional jumping, i.e., transfer program execution to some different place within the program if condition was true –jump back or forward in your code to the location specified –instruction pointer (IP) gets updated (to point to the instruction to which execution will jump) if condition was false –continue execution at the following instruction –IP gets incremented as usual

CE302 Conditional Branching (cont.) Conditional jumps are always short jumps in the –the range of the jump is +127 bytes and -128 bytes from the location following the conditional jump In 80386, conditional jumps are either short or near jumps Conditional jumps test: sign (S), zero (Z), carry (C), parity (P), and overflow (O) Note: an FFh is above the 00h in the set of unsigned numbers an FFh (-1) is less than 00h for signed numbers when you compare unsigned FFh is above 00h, but signed FFh is less than 00h

CE302 Numerical Comparison CMP(comparison) compares A to B –a subtraction that only changes the flag bits –useful for checking the entire contents of a register or a memory location against another value –usually followed by a conditional jump instruction CMPAL, 10h ;compare with 10h (contents of AL does not change) JAESUBER ;if 10h or above then jump to memory location SUBER SUB (subtraction) calculates difference A - B –saves results to A and set flags

CE302 Numerical Comparison Condition Code Settings CMPOprnd1, Oprnd2 Unsigned OperandsSigned operands Z: equality/inequality C: Oprnd1 < Oprnd2 (C=1) C: no meaning Oprnd1 >= Oprnd2 (C=0) S: no meaning S and O taken together O: no meaningIf ((S=0) and (O=1)) or ((S=1) and (O=0)) then Oprnd1 < Oprnd2 If ((S=0) and (O=0)) or ((S=1) and (O=1)) then Oprnd1 >= Oprnd2

CE302 Comparing Signed Integers Consider CMP AX,BX computed by the CPU –The Sign bit (S) will be set if the result of AX-BX has a 1 at the most significant bit of the result (i.e., 15th bit for 16-bit op) –The Overflow flag (O) will be set if the result of AX-BX produced a number that was out of range ( for 16-bit numbers) to be represented by an integer. Difference in JS (jump on sign) and JL (jump less than) –The conditional jump JS looks at the sign bit (S) of the last compare (or subtraction). If S = = 1 then jump. –The conditional jump JL looks (S XOR O) of the last compare (or subtraction) REGARDLESS of the value AX-BX, i.e., even if AX-BX causes overflow, the JL will be correctly executed

CE302 Comparing Signed Integers (cont.) JL is true if the condition: S xor O is met JL is true for two conditions: S=1, O=0: –(AX-BX) was negative and (AX-BX) did not overflow –Example (8-bit): (-5) - (2) = (-7) Result (-7) has the sign bit set Thus (-5) is less than (2).

CE302 Comparing Signed Integers (cont.) S=0, O=1: –Overflow!, Sign bit of the result is wrong! –Consider the following case: AX is a large negative number (-) BX is a positive number (+). The subtraction of (-) and (+) is the same as the addition of (-) and (-) The result causes negative overflow, and thus cannot be represented as a signed integer correctly (O=1). The result of AX-BX appears positive (S=0). –Example (8-bit): (-128) - (1) = (+127) –Result (+127) overflowed. Answer should have been (-129). –Result appears positive, but overflow occurred –Thus (-128) is less than (1), i.e., the condition is TRUE for executing JL

CE302 Comparing Signed Integers CMP AX, BX AXBX AXBX AXBX AX – BX = 2 – (-4) = = 6 =0110 So s = 0, no overflow (o = 0) Therefore AX >= BX AX – BX = 6 – (-3) = = 9 = 1001 So s = 1, overflow (o = 1) Therefore AX >= BX AX – BX = 2 – 4 = -2 = 1110 So s = 1, no overflow (o = 0) Therefore AX < BX

CE302 Conditional Branching (cont.) Terminology used to differentiate between jump instructions that use the carry flag and the overflow flag –Above/Belowunsigned compare –Greater/Lesssigned (+/-) compare Names of jump instructions J => Jump N => Not A/B G/L=> Above/Below Greater/Less E=>Equal

CE302 Summary of Conditional Jump Instructions CommandDescriptionCondition JA=JNBEJump if above C=0 & Z=0 Jump if not below or equal JBE=JNAJump if below or equalC=1 | Z=1 JAE=JNB=JNC Jump if above or equal C=0 Jump if not below Jump if no carry JB=JNAE=JC Jump if below C=1 Jump if carry JE=JZ Jump if equal Z=1 Jump if Zero JNE=JNZ Jump if not equalZ=0 Jump if not zero JSJump Sign (MSB=1) S=1

CE302 Summary of Conditional Jump Instructions CommandDescriptionCondition JNSJump Not Sign (MSB=0) S=0 JO Jump if overflow set O=1 JNOJump if no overflow O=0 JG=JNLE Jump if greater Jump if not less or equal S=O & Z=0 JGE=JNLJump if greater or equal S=O Jump if not less JL=JNGEJump if less S^O Jump if not greater or equal JLE=JNG Jump if less or equal S^O | Z=1 Jump if not greater JCXZJump if register CX=zero CX=0

CE302 Mapping High Level Branches into Linear Code CMP AX, BX JA true_label …. …. JMP done_label …. true_label: …. done_label:

CE302 Mapping High Level Branches into Linear Code (cont.)

CE302 Mapping High Level Branches into Linear Code (cont.) LOOP instruction –combination of a decrement CX and a conditional jump –LOOP decrements CX (ECX if in 32-bit mode) and if CX  0 it jumps to the address indicated by the label –if CX becomes a 0, the next sequential instruction executes ADDSPROC NEAR MOVCX, 100; load count MOVSI, OFFSET BLOCK1 MOVDI, OFFSET BLOCK2 Again: LODSW;get Block1 data; AX = [SI]; SI = SI + 2 ADDAX, ES:[DI];add Block2 data STOSW;store in Block2; [DI] = AX; DI = DI + 2 LOOPAgain;repeat 100 times RET ADDSENDP

CE302 Examples ;if (J <= K) then ;L := L + 1 ;elseL := L - 1 ; J, K, L are signed words MOVAX, J CMPAX, K JNELDoElse INCL JMPifDone DoElse: DECL ifDone: ;while (J >= K) do begin ;J := J - 1; ;K := K + 1; ;L := J * K; ;end; WhlLoop: MOVAX, J CMPAX, K JNGEQuitLoop DECJ INCK MOVAX, J IMULAX, K MOVL, AX JMPWhlLoop QuitLoop:

CE302 Example (LOOPNE) The LOOPNE instruction is useful for controlling loops that stop on some condition or when the loop exceeds some number of iterations Consider String1 that contains a sequence of characters that end with the byte containing zero we want to convert those characters to upper case and copy them to String2 ….. String1BYTE“This string contains lower case characters”, 0 String2BYTE128 dup (0) ……..

CE302 Example (LOOPNE) LEASI, String1 ;the same as use of OFFSET LEADI, String2 MOVCX, 127;Max 127 chars to String2 StrLoop: LODSB;get char from String1; AL =[SI]; SI = SI + 1 CMPAL, ‘a’;see if lower case JBNotLower ;chars are unsigned CMPAL, ‘z’ JANotLower ANDAL, 5Fh;convert lower -> upper case; ;bit 6 must be 0 NotLower: STOSB; [DI] = AL; DI = DI + 1 CMPAL, 0;see if zero terminator LOOPNEStrLoop;quit if AL or CX = 0