CS 235 Computer Organization & Assembly Language

Slides:



Advertisements
Similar presentations
Integer Arithmetic: Multiply, Divide, and Bitwise Operations
Advertisements

Lecture 5: MIPS Instruction Set
ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS
COE 202: Digital Logic Design Signed Numbers
COMP3221 lec06-numbers-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 6: Number Systems - II
By Tien Phung CS 147 Dr. Sin-Min Lee. High-level Languages Assembly Languages Machine Languages.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C Chapter 3 – Digital Logic and Binary Numbers These are lecture notes to accompany.
1 Arithmetic and Logical Operations - Part II. Unsigned Numbers Addition in unsigned numbers is the same regardless of the base. Given a pair of bit sequences.
The 8051 Microcontroller and Embedded Systems
Ch. 7 Logic, Shift and Rotate instr.
Khaled A. Al-Utaibi  Introduction  Arithmetic Instructions  Basic Logical Instructions  Shift Instructions  Rotate Instructions.
Operations on Bits Arithmetic Operations Logic Operations
Natawut NupairojAssembly Language1 Arithmetic Operations.
ITEC 352 Lecture 14 ISA(6). Review Questions? Beginning / End Memory locations Variable / Memory syntax PSR Loops / Branches.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
ECE 447: Lecture 12 Logic, Arithmetic, Data Test and Control Instructions of MC68HC11.
Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C Chapter 4 –Binary Arithmetic These are lecture notes to accompany the book SPARC.
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
EET 4250 Instruction Representation & Formats Acknowledgements: Some slides and lecture notes for this course adapted from Prof. Mary Jane Penn.
Chapter 2 — Instructions: Language of the Computer — 1 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 9 Binary Representation and Logical Operations.
ECE/CS 552: Arithmetic I Instructor:Mikko H Lipasti Fall 2010 University of Wisconsin-Madison Lecture notes partially based on set created by Mark Hill.
1 CS 151 : Digital Design Chapter 4: Arithmetic Functions and Circuits 4-3 : Binary Subtraction.
Integer Operations Computer Organization and Assembly Language: Module 5.
Microprocessor & Assembly Language
MIPS Arithmetic and Logic Instructions
CS Computer Organization Numbers and Instructions Dr. Stephen P. Carl.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Yaohang Li.
ITEC 352 Lecture 16 ISA(7). Review Exam / Questions? Conditional codes, how important are they? How important are comments in assembly? What are the benefits.
Lecture 4: Digital Systems & Binary Numbers (4)
David Kauchak CS 52 – Spring 2017
CHAPTER 9 COMPUTER ARITHMETIC - ALU
Negative Binary Numbers
Status Register Status = system byte (supervisor only) + user byte = system status + condition code register usually, it is not important to know.
COMPUTER ARCHITECTURE & OPERATIONS I
ECE 3430 – Intro to Microcomputer Systems
The University of Adelaide, School of Computer Science
Negative Binary Numbers
ICS312 SET 7 Flags.
Decision Making.
Chapter 3 – Digital Logic and Binary Numbers
A Level Computing Component 2
The FLAGS Register An x bit means an unidentified value 9/12/2018
ECE/CS 552: Arithmetic and Logic
MPIS Instructions Functionalities of instructions Instruction format
MISP Assembly.
Data Representation in Computer Systems
CSC 3210 Computer Organization and Programming
Computer Architecture & Operations I
The University of Adelaide, School of Computer Science
University of Gujrat Department of Computer Science
Write a program to calculate x**y, given x and y.
Shift & Rotate Instructions)
Flow of Control -- Conditional branch instructions
CPS120: Introduction to Computer Science
Arithmetic and Logic Chapter 5
March 2006 Saeid Nooshabadi
ECE 331 – Digital System Design
MIPS Assembly.
Flow of Control -- Conditional branch instructions
ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS
MIPS Arithmetic and Logic Instructions
MIPS Arithmetic and Logic Instructions
Shift and Rotate Instructions.
Bit Manipulations CS212.
Part I Data Representation and 8086 Microprocessors
An Introduction to the ARM CORTEX M0+ Instructions
Two’s Complement & Binary Arithmetic
Presentation transcript:

CS 235 Computer Organization & Assembly Language Branching & Shifting CS 235 Computer Organization & Assembly Language

Two’s Complement Branching Conditions When the numbers are signed (two’s complement), the branching conditions introduced earlier are appropriate. bl branch < 0 (N xor V) = 1 ble branch <= 0 Z or (N xor V)=1 be branch == 0 Z = 1 bne branch != 0 Z = 0 bge branch >= 0 (N xor V) = 0 bg branch > 0 Z or (N xor V)=0

How are Conditions Set? Signed numbers Z is set when all bits of the result are 0 N is set when the msb is 1 V is set 1) when the register is not long enough to hold the result 2) on subtraction, d = m – s, when the sign of d is the same as the sign of s and the sign of m is different from s For example, most_negative – any_positive_number (-8) – (2) = 10, not representable in 4 bits

Conditions with Unsigned Arithmetic No N flag!!! Condition codes set differently On addition, a carry out of the msb indicates overflow and the carry bit C is set On subtraction. We imagine an extra bit to the left of the number. By forming the two’s complement of the subtrahend, and adding, we would expect a carry out of the most significant bit to be added to the imaginary bit to indicate a positive result. So the C bit is set if there is no carry out of the msb. Result: the test for unsigned overflow is a test of the carry bit C.

4 Bit Examples 1) 12 1100 09 1001 21 10101 On addition, the carry bit set indicates overflow.

4 Bit Examples 2) 12 1100 - 09 0111 = (10000 –1 - 1001) +1 03 10011 and the carry indicates a correct result

4 Bit Examples 3) 09 1001 - 12 0100 = (10000 –1 - 1100) +1 21 01101 The carry bit is not set, so the result is incorrect

Unsigned Branching Conditions When the numbers are unsigned, the branching conditions are different. blu branch < 0 C = 1 bleu branch <= 0 Z or C =1 be branch == 0 Z = 1 bne branch != 0 Z = 0 bgeu branch >= 0 C = 0 bgu branch > 0 Z and C =0

Condition Code Tests based directly upon condition codes bneg branch on negative N = 1 bpos branch on positive N = 0 bz branch on zero Z = 1 bnz branch on not zero Z = 0 bvs branch overflow set V = 1 bvc branch no overflow V = 0 bcs branch carry set C = 1 bcc branch carry clear C = 0

Shifting Three shifts Shift right logical srl rs1, rs2_or_im, rdest Shift right arithmetic sra rs1, rs2_or_im, rdest Shift left logical sll rs1, rs2_or_im, rdest The rs1 is shifted the numbers of bits in the second operand and the result is stored in the destination

Shift is a Multiply by 2 A fast multiply Used instead of .mul Consider %o0 * 11 1110 = 10112 = 8 + 2 + 1 sll %o0, 3, %o1 ! 8*x sll %o0, 1, %o2 ! 2*x add %o0, %o1, %o3 ! x + 8*x add %o2, %o3, %o3 ! 8*x + 2*x + x ! = 11*x

SPARC Boolean Opcodes Recall Boolean Operations (02:38) andcc regs1, reg_or_imm, regdest andncc regs1, reg_or_imm, regdest xorcc regs1, reg_or_imm, regdest orcc regs1, reg_or_imm, regdest xnorcc regs1, reg_or_imm, regdest orncc regs1, reg_or_imm, regdest