Computer Architecture

Slides:



Advertisements
Similar presentations
Flow of Control Instruction/Control structure Looping structure Looping structure Branching structure Branching structure For assembly language program.
Advertisements

Fabián E. Bustamante, Spring 2007 Machine-Level Programming II: Control Flow Today Condition codes Control flow structures Next time Procedures.
CSC 221 Computer Organization and Assembly Language Lecture 21: Conditional and Block Structures: Assembly Programs.
The CPU Revision Typical machine code instructions Using op-codes and operands Symbolic addressing. Conditional and unconditional branches.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
Assembly Language: IA-32 Instructions
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Assembly Language for Intel-Based Computers
CS2422 Assembly Language & System Programming October 17, 2006.
Flow Control Instructions
1 Homework Reading –PAL, pp Machine Projects –MP2 due at start of Class 12 Labs –Continue labs with your assigned section.
Conditional Processing If … then … else While … do; Repeat … until.
Low Level Programming Lecturer: Duncan Smeed Low Level Program Control Structures.
Comparing and Branching ifs and loops part A. JMP instruction Consider the forever loop: for ( ; ; ) { … } How can we accomplish this in Assembler?
1 ICS 51 Introductory Computer Organization Fall 2009.
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.
1 Carnegie Mellon Assembly and Bomb Lab : Introduction to Computer Systems Recitation 4, Sept. 17, 2012.
EEL 3801 Part V Conditional Processing. This section explains how to implement conditional processing in Assembly Language for the 8086/8088 processors.
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.
תרגול 5 תכנות באסמבלי, המשך
Assembly 06. Outline cmp (review) Jump commands test mnemonic bt mnemonic Addressing 1.
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.
Comparison Instructions Test instruction –Performs an implied AND operation between each of the bits in 2 operands. Neither operand is modified. (Flags.
K.K. Leung Fall 2008Introductory Pentium Programming1 Pentium Architecture: Introductory Programming Kin K. Leung
Assembly תרגול 7 תכנות באסמבלי, המשך. Condition Codes Single bit registers  CF – carry flag  ZF – zero flag  SF – sign flag  OF – overflow flag Relevant.
Precept 7: Introduction to IA-32 Assembly Language Programming
CSC 221 Computer Organization and Assembly Language
Machine-Level Programming 2 Control Flow
Computer Architecture CST 250
Assembly Language Programming IV: shift, struct, recursion
Data Transfers, Addressing, and Arithmetic
Conditional Branch Example
Homework Reading Labs PAL, pp
Instruksi Set Prosesor 8088
Aaron Miller David Cohen Spring 2011
EE3541 Introduction to Microprocessors
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration Xeno Kovah – 2014 xkovah at gmail.
Assembly IA-32.
Assembly Language Programming Part 2
Recitation 2 – 2/4/01 Outline Machine Model
Microprocessor and Assembly Language
Machine-Level Programming II: Arithmetic & Control
Machine-Level Representation of Programs II
Computer Architecture adapted by Jason Fritts then by David Ferry
x86-64 Programming II CSE 351 Autumn 2017
Y86 Processor State Program Registers
Assembly Language: IA-32 Instructions
فصل پنجم انشعاب و حلقه.
Instructor: David Ferry
Machine-Level Programming: Control Flow
Machine-Level Programming 2 Control Flow
Lecture 30 (based on slides by R. Bodik)
Fundamentals of Computer Organisation & Architecture
Machine-Level Programming 2 Control Flow
Machine-Level Representation of Programs III
Machine-Level Programming 2 Control Flow
Homework Reading Machine Projects Labs PAL, pp
Flow Control Instructions
CNET 315 Microprocessor & Assembly Language
University of Gujrat Department of Computer Science
C021TV-I3-S1.
Machine-Level Programming II: Control Flow
X86 Assembly Review.
EECE.3170 Microprocessor Systems Design I
Carnegie Mellon Ithaca College
CS201- Lecture 8 IA32 Flow Control
Credits and Disclaimers
Computer Architecture and Assembly Language
Presentation transcript:

Computer Architecture x86 Programming Computer Architecture

* Where k is an int variable CMP Instruction CMP Instruction compares two operands Internally comparison is performed via subtraction One operand has to be a register or constant (8, 16, or 32 bits) Other operand can be a variable (memory address) or constant Sets flags as the SUB instruction Changes CF, OF, SF, PF, and ZF Operands are not modified. Instruction Result cmpb %BL, %AL FLAGS(%AL - %BL) cmpl $8, %EAX FLAGS(%EAX – 8) cmpl k, %EAX FLAGS(%eax – k) cmpl $8, k FALGS(k – 8) * Where k is an int variable

JMPcc Instruction JMPcc is a family of instruction where ‘cc’ stands for condition code Performs a jump or a branch if a condition is met Conditions are flag values set by earlier calls to CMP There are 100s of flavors of JMPcc instruction For different combination of conditions (FLAG values) For different JMP sizes 8, 16, or 32-bit offset values to be added to IP We will cover a few in class. Refer to manual for details.

JMPcc Instruction CMP a, b A compare must be performed first! Flags Used JMP Taken IF JE label1 ZF=1 a == b JNE label1 ZF=0 a != b JG label1 ZF=0, SF=CF a > b JL label1 SF!=CF a < b JLE label1 ZF=1, SF!=CF a <= b JGE label1 SF=OF a >= b

Example Usage Convert the following Java code to assembly public static main(String[] args) { int a = 10, b = 20; int c = 0; if (a > b) { c = a + b; } else { c = a – b; .text /* Every thing below goes in Code Segment */ .global _start /* Global entry point into program */ _start: /* Indicate where program starts */ movl a, %eax /* eax = a */ cmpl b, %eax /* Set Flags */ JG ifPart /* a > b */ subl b, %eax /* eax -= b */ jmp endIF /* Done with else */ ifPart: addl b, %eax /* eax += b */ endIF: movl %eax, c /* c = eax */

Example Usage (Contd.) Convert the following Java code to assembly public static main(String[] args) { int a = 10, b = 20; int c = 0; if (a > b) { c = a + b; } else { c = a – b; /* Continued from previous slide*/ /* exit*/ movl $1, %eax movl $0, %ebx int $0x80 .data /* Everything below goes in data segment */ a: .int 10 b: .int 20 c: .int 0