Morgan Kaufmann Publishers Computer Organization and Assembly Language

Slides:



Advertisements
Similar presentations
Jump Condition.
Advertisements

Flow of Control Instruction/Control structure Looping structure Looping structure Branching structure Branching structure For assembly language program.
ACOE2511 Assembly Language Arithmetic and Logic Instructions.
Computer Organization & Assembly Language
LAB Flow Control Instructions
Assembly Language for Intel-Based Computers
Flow Control Instructions
9-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
Topics Control Flow Structure – Conditional Jump – Unconditional Jump Control Flow Structures – IF-THEN – IF-THEN-ELSE – CASE Branches with Compound Conditions.
An Introduction to 8086 Microprocessor.
Lecture 3 Presented By Dr. Shazzad Hosain Asst. Prof. EECS, NSU.
Types of Registers (8086 Microprocessor Based)
ICS312 Set 9 Logic & Shift Instructions. Logic & Shift Instructions Logic and Shift Instructions can be used to change the bit values in an operand. The.
Lecture 4 ( Assembly Language).
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Arithmetic Flags and Instructions
(Flow Control Instructions)
Executing and Linking an assembly program. Lesson plan Review Program logic and control Practice exercise Assembling, Linking and Executing Programs Practice.
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.
1 IKI10230 Pengantar Organisasi Komputer Kuliah no. 06: Control Structures Sumber: 1. Paul Carter, PC Assembly Language 2. Hamacher. Computer Organization,
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.
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.
Microprocessor MA Rahim Khan Computer Engineering and Networks Department.
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.
Jumps, Loops and Branching. Unconditional Jumps Transfer the control flow of the program to a specified instruction, other than the next instruction in.
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
Selection and Iteration Chapter 8 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Chapter 12 Processor Structure and Function. Central Processing Unit CPU architecture, Register organization, Instruction formats and addressing modes(Intel.
Data Transfers, Addressing, and Arithmetic
Homework Reading Labs PAL, pp
8086 Microprocessor.
Instruksi Set Prosesor 8088
Microprocessor and Assembly Language
Lecture 4 Control Flow Structures (LOOPS)
EE3541 Introduction to Microprocessors
Microprocessor and Assembly Language
Basic Microprocessor Architecture
Assembly IA-32.
INSTRUCTION SET.
More on logical instruction and
Assembly Language Programming Part 2
ECE 353 Introduction to Microprocessor Systems
Microprocessor and Assembly Language
CÁC LỆNH HỢP NGỮ.
Introduction to Assembly Language
Lecture 4 ( Assembly Language).
Flags Register & Jump Instruction
Lecture 1 Instruction set of 8086 Лектор: Люличева И.А. 1.
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
CS 301 Fall 2002 Computer Organization
Shift & Rotate Instructions)
Program Logic and Control
University of Gujrat Department of Computer Science
Program Logic and Control
Symbolic Instruction and Addressing
Shift & Rotate Instructions)
Flow Control Instructions
Morgan Kaufmann Publishers Computer Organization and Assembly Language
EECE.3170 Microprocessor Systems Design I
High-level language structures
Chapter 6 –Symbolic Instruction and Addressing
Assembly Language for Intel 8086 Jump Condition
Jump & Loop instructions
Chapter 7 –Program Logic and Control
Chapter 8: Instruction Set 8086 CPU Architecture
Chapter 7 –Program Logic and Control
Computer Architecture and Assembly Language
Part VI Looping Structures
Presentation transcript:

Morgan Kaufmann Publishers Computer Organization and Assembly Language September 12, 2018 CS 206 D Computer Organization and Assembly Language Chapter 1 — Computer Abstractions and Technology

Chapter 7 –Program Logic and Control Lecture 5 and Lecture 6 Chapter 7 –Program Logic and Control

Chapter Outline Short, near and far address JMP Instruction The CMP Instruction Conditional Jump instruction The Loop instruction While Loop REPEAT Loop

Short, Near and Far addresses 1- A short address, limited to a distance of -128 to 127 bytes 2- A near address, limited to a distance of -32,768 to 32,767 bytes 3- A far address, which may be within the same segment at a distance over 32K or in other segment FAR NEAR SHORT YES JMP NO JXXX(conditional jump) LOOP NlA CALL

Unconditional Jumps - The JMP Instruction The JMP (jump) instruction causes an unconditional transfer of control (unconditional jump). Syntax: JMP destination Example: JMP L10 …….. L10: INC CX SHORT/NEAR/FAR address JMP Backward and Forward jumps L10: ……. JMP L10; Backward ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; JMP L10; Forward

The CMP Instruction The jump condition is often provided by the CMP (compare) instruction Syntax: CMP destination, source Compares by computing destination contents minus source contents. The result is not stored, but the Flags are affected. Destination may not be a constant. CMP is just like SUB, except that destination is not changed.

Flags Carry flag Overflow Parity flag Direction Interrupt enable Auxiliary flag Zero Overflow Direction Interrupt enable Trap Sign 6 are status/ conditional flags 3 are control flag

Flag Register Conditional flags: They are set according to some results of arithmetic operation. You do not need to alter the value yourself. Control flags: Used to control some operations of the MPU. These flags are to be set by you in order to achieve some specific purposes. Flag O D I T S Z A P C Bit no. 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 CF (carry) Contains carry from leftmost bit following arithmetic, also contains last bit from a shift or rotate operation. Example: (11110000)+(10100001) =10010001 SF =1 ,CF=1 ,ZF=0 ,OF=0 ,PF=0

Flag Register OF (overflow) The overflow flag is set to1 if the result of an arithmetic operation is too big for the microprocessor’s maximum word size, otherwise it is reset to 0 DF (direction) Indicates left or right for moving or comparing string data. IF (interrupt) Indicates whether external interrupts are being processed or ignored. TF (trap) Permits operation of the processor in single step mode.

Flag Register SF (sign) Contains the resulting sign of an arithmetic operation (1=negative; 0=positive) ZF (zero) Indicates when the result of arithmetic or a comparison is zero. (1= zero; 0= nonzero) AF (auxiliary carry) Contains carry out of bit 3 into bit 4 for specialized arithmetic. PF (parity) is set to 1 to indicate whether the result of the last operation contains either an even number of 1’s (even parity) or an odd number of 1’s (odd parity) depending on the microprocessor..

Conditional Jumps Syntax Jxxx destination_label Example JNZ PRINT_LOOP If the condition for the jump is true, the next instruction to be executed is the instruction at destinaltion_label (PRINT_LOOP), which may precede or follow the jump instruction itself. If the condition is false, the instruction immediately following the jump is done next. For JNZ, the condition is that the result of the previous operation is not zero.

Conditional Jumps Signed Jumps: used for signed interpretations. Symbol Description Condition for Jumps JG/JNLE jump if grater than ZF = 0 & SF = OF jump if not less than or equal JGE/JNL jump if grater than or equal SF = OF jump if not less than JL/JNGE jump if less than SF <> OF jump if not greater than or equal JLE/JNG jump if less than or equal ZF = 1 or SF <> OF jump if not grater than

Conditional Jumps Unsigned Jumps: used for unsigned interpretations. Symbol Description Condition for Jumps JA/JNBE jump if above CF = 0 & ZF = 0 jump if not below or equal JAE/JNB jump if above or equal CF = 0 jump if not below JB/JNAE jump if below CF = 1 jump if not above or equal JBE/JNA jump if below or equal CF = 1 or ZF = 1 jump if not above

Conditional Jumps Single Flag Jumps: operates on settings of individual flags. Symbol Description Condition for Jumps JE/JZ jump if equal/ jump if equal to 0 ZF = 1 JNE/JNZ jump if not equal/ jump if not 0 ZF = 0 JC jump if carry CF = 1 JNC jump if no carry CF = 0 JO jump if overflow OF = 1 JNO jump if no overflow OF = 0 JS jump if sign negative SF = 1 JNS jump if nonnegative sign SF = 0 JP/JPE jump if parity even PF = 1 JNP/JPO jump if parity odd PF = 0

IF-THEN-ELSE Example: Suppose AL and BL contain extended ASCII characters. Display the one that comes first in the character sequence. Solution: Pseudocode: IF AL <= BL THEN display the character in AL ELSE display the character in BL END_IF CMP AL, BL ; AL <= BL? JNBE ELSE_ ; no, display char in BL ; AL <= BL MOV DL, AL ; move char to be displayed JMP DISPLAY ; go to display ELSE_: ; BL < AL MOV DL, BL DISPLAY: MOV AH, 2 ; prepare to display INT 21h ; display it

Branches with compound Conditions Sometimes the branching condition in an IF or CASE takes the form: condition_1 AND condition_2 or condition_1 OR condition_2 An AND condition is true if and only if all conditions are true. Example: Read a character, and if it’s an uppercase letter, display it. Pseudocode: Read a character (into AL) IF ('A' <= character) and (character <= 'Z') THEN display character END_IF AND condition OR condition

AND Condition It can be coded as follows: ; read a character ; if ('A' <= char) and (char <='Z') ; then display char MOV AH,1 ; prepare to read INT 21h ; char in AL CMP AL, 'A' ; char >= 'A'? JNGE END_IF ; no, exit CMP AL, 'Z' ; char <= 'Z'? JNLE END_IF ; no, exit MOV DL, AL ; get char MOV AH, 2 ; prepare to display INT 21h ; display char END_IF:

OR Condition An OR condition is true if at least one of the conditions is true. Example: Read a character. If it’s 'y' or 'Y', display it; otherwise, terminate the program. Solution: Pseudocode: Read a character (into AL) IF (character = 'y') or (character = 'Y') THEN display character ELSE terminate the program END_IF continue

OR Condition It can be coded as follows: ; read a character ; if (char = 'y') or (char = 'Y') MOV AH,1 ; prepare to read INT 21h ; char in AL CMP AL, 'y' ; char = 'y'? JE THEN ; yes, go to display it CMP AL, 'Y' ; char = 'Y'? JMP ELSE_ ; no, terminate THEN: MOV DL, AL ; get char MOV AH, 2 ; prepare to display INT 21h ; display char JMP END_IF ; and exit ELSE_: MOV AH, 4Ch INT 21h ; DOS exit END_IF:

Loop Instruction Syntax: The LOOP instruction can be used to implement a For loop. Syntax: The counter for the loop is the register CX, which is initialized to loop_count. Execution of the LOOP instruction causes CX to be decremented automatically. If (CX < > 0) control transfers to destination_label else the next instruction after LOOP is done. ; initialize CX to loop_count TOP: ; body of the loop LOOP TOP SHORT address LOOP

FOR Loop Example: Write some code to display a row of 80 stars. Solution: Pseudocode: FOR 80 times DO display '*' END_IF ; what if CX =0? MOV CX, 80 MOV AH, 2 MOV DL, '*' JCXZ SKIP ;jump if CX=0 TOP: INT 21h LOOP TOP SKIP: It can be coded as follows: MOV CX, 80 MOV AH, 2 MOV DL, '*' TOP: INT 21h LOOP TOP

WHILE Loop This loop depends on a condition. Pseudocode: WHILE condition DO statements END_WHILE initialize count to 0 read a character WHILE character <> carriage_return DO count = count + 1 read character Example: Write some code to count the number of characters in an input line. WHILE_: END_WHILE: MOV DX, 0 ; DX counts characters MOV AH, 1 ; prepare to read INT 21h ; character in AL CMP AL, 0Dh ; CR? JE END_WHILE ; yes, exit ; not CR, increment count INC DX INT 21h ; read a character JMP WHILE_ ; loop back

REPEAT Loop This loop depends on a condition. Pseudocode: REPEAT Statements UNTIL conditions Example: write code to read characters until a blank is read Read character UNTIL character is blank MOV AH,1 REAPEAT: INT 21H CMP AL,’ ‘ JNE REAPEAT