Logic Bitwise Instructions

Slides:



Advertisements
Similar presentations
Intro to CS – Honors I Representing Numbers GEORGIOS PORTOKALIDIS
Advertisements

COMP3221 lec9-logical-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 9: C/Assembler Logical and Shift - I
1 Arithmetic and Logical Operations - Part I. Boolean Operations A boolean variable can only have one of the two values, i.e, can either be 1 or 0. Given.
Computer Organization & Assembly Language
Computer Architecture CPSC 321 E. J. Kim. Overview Logical Instructions Shifts.
9-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
24/06/2015CSE1303 Part B lecture notes 1 Words, bits and pieces Lecture B05 Lecture notes section B05.
Logical & shift ops (1) Fall 2007 Lecture 05: Logical Operations.
Binary Operations Math/Logical. Binary Math Decimal Addition Example ) Add = 15 Write down 5, carry ) Add 3 +
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.
ECE 447 Fall 2009 Lecture 5: TI MSP430 Software Development in C and Assembly pt. 2.
Computer Arithmetic Nizamettin AYDIN
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.
Bits and Bytes. BITWISE OPERATORS Recall boolean logical operators in Java… boolean logical operators: &, |, ^ not: ! Show truth tables.
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
1 Logic, Shift, and Rotate Instructions Read Sections 6.2, 7.2 and 7.3 of textbook.
Arithmetic Operations
CSC321 Homework Due Due Tuesday after spring break Turn in –Design information State diagram State table K-map simplifications and expressions for flip-flop.
Logical and Bit Operations Chapter 9 S. Dandamudi.
CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS.
Arithmetic and Logic Chapter 5
ECE 447 Fall 2009 Lecture 4: TI MSP430 Architecture and Instruction Set.
Chapter 7 Bit Manipulation. 7.1 Logical Operations.
1 Sec (2.4) Arithmetic / logic instruction:. 2 Logical operations: Ex: XOR OR AND
Microprocessor & Assembly Language Arithmetic and logical Instructions.
Bit Manipulation in 'C' 'C' bit operators
Microprocessor & Assembly Language
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.
CS Computer Organization Numbers and Instructions Dr. Stephen P. Carl.
Classification of Instruction Set of 8051
COMPUTER ARCHITECTURE & OPERATIONS I
ECE 382 Lesson 7 Lesson Outline Miniquiz Instruction Execution Time
Instructor: David Ferry
Microprocessor Systems Design I
ECE 3430 – Intro to Microcomputer Systems
Bit Operations Horton pp
Chapter 3 Bit Operations
ECE 3430 – Intro to Microcomputer Systems
Data Processing Instructions
Arithmetic and Logic Chapter 5
68000 Arithmetic Instructions
The 8051 Assembly Language Arithmetic & Logic Instructions
Computer Architecture & Operations I
STACK and Stack Pointer
ECE 3430 – Intro to Microcomputer Systems
CPU: software architecture
The University of Adelaide, School of Computer Science
Topic 6: Bitwise Instructions
CS-401 Computer Architecture & Assembly Language Programming
Shift & Rotate Instructions)
Logical Operations Boy who sow wild oats better hope for crop failure.
Shift & Rotate Instructions)
Bit-wise and bit-shift operators
The University of Adelaide, School of Computer Science
Arithmetic and Logic Chapter 5
Branching instructions
Chapter 5 Arithmetic and Logic Instructions
ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS
Microprocessor and Assembly Language
Computer Organization and Assembly Language
Immediate data Immediate operands : ADD r3, r3, #1 valid ADD r3, #1,#2 invalid ADD #3, r1,r2 invalid ADD r3, r2, #&FF ( to represent hexadecimal immediate.
Shift and Rotate Instructions.
Bit Manipulations CS212.
Logical Operations Boy who sow wild oats better hope for crop failure.
Bit Operations Horton pp
Arithmetic and Logic Chapter 3
Presentation transcript:

Logic Bitwise Instructions And MSP430 logic bitwise instructions

Definitions (1) Bitwise operation: The operation takes place bit by bit, independently of other bits in the word Notation: dest  dest .op src is to be interpreted as dest(0)dest(0) .op src(0), dest(1)dest(1) .op src(1), . . . dest(n-1)dest(n-1) .op src(n-1) Where dest(j) and src(j) denote bits of destination and source. Bitwise operations allow us to manipulates bits inpendently and without affecting other bits. Typical bit operations: set (make bit=1), clear (make bit=0) and toggle or invert (invert value of bit), test (to determine if a bit is 1, or if a group of bits are not all 0)

Definitions (2) Mask: An operand, usually the source, used in bitwise operations in which only the bits to be affected in destination are 1 Example: the mask 00010100B=84h=132=24Q means that bits dest(2) and dest(4) are targeted, all others left unchanged. Set, clear, test, and toggle of bits are done using the operations or, and and xor

Properties of logic operations: 1. To clear: 2. To set: 3. And , to test: 4. To toggle or invert

Using masks to work with bits: Example Clearing bits with AND: dest<-- dest OR (NOT src) Mask 1 dest x Setting bits with OR: dest<-- dest OR src Testing bits (also AND): dest <-- dest AND src Toggling bits with XOR: dest <-- dest XOR src x' Bits 1 and 2 remain unchanged Bits 1 and 2 remain unchanged Flag Z=1 if and only if (Bit0 =0 and Bit 3=0) When only one bit is tested, Z=0 if Bit = 1 and Z=1 if Bit=0 Bits 1 and 2 remain unchanged, while bits 0 and 3 are inverted.

MSP430 Logic Functions

Effects on Flags Flags are affected by logic operations as follows, under otherwise indicated: Z=1 if destination is cleared Z=0 if at least one bit in destination is set C= Z’ (Flag C is always equal to the inverted value of Z in these operations) N = most significant bit of destination V = 0

Core bitwise Instructions (1) and src, dest realizes dest  src .and. dest xor src, dest realizes dest  src .xor. dest bit src, dest realizes src .and. dest but only affects flags Example R12= 35ABh = 0011 0101 1010 1011 R15= AB96h = 1010 1011 1001 0110 and R12,R15 0010 0001 1000 0010→R15=2182h Flags: C=1, Z=0, N=0, V=0 xor R12,R15 1001 1110 0011 1101→R15=9E3Dh Flags: C=1, Z=0, N=1, V=0 and.b R12,R15 1000 0010→R15=0082h Flags: C=1, Z=0, N=1, V=0 xor.b R12,R15 0011 1101→R15=003Dh

Core bitwise Instructions (2) – these do not affect flags - bis src, dest realizes dest  src .or. dest, : SETS BITS bic src, dest realizes dest  src’ .and. Dest : CLEARS BITS Examples R12= 35ABh = 0011 0101 1010 1011 R15= AB96h = 1010 1011 1001 0110 bis R12,R15 1011 1111 1011 1111→R15= BFBFh Flags: unchanged bic R12,R15 1000 1010 0001 0100→R15= 8A14h bis.b R12,R15 1011 1111→R15= 00BFh Flags: unchanged bic.b R12,R15 0001 0100→R15=0014h

Emulated Logic Instructions Inverting a destination Manipulating flags: inv dest = xor #FF, dest Toggles all bits

Remarks on bit instruction in MSP430 Since C=Z’, either the carry flag C or the zero flag C can be used as information about condition. In bit src, dest C=1 (Z=0) means that at least one bit among those tested is not 0. In bit #BITn, dest, where BITn is the word where all but the n-th bit are 0, C=tested bit Example R15= 0110 1100 1101 1001 then bit #BIT14,R15 yields C=1 = bit 14; bit #BIT5,R15 yields C = 0 = bit 5.

Register Control instructions. Rolling (or shifting) and rotating

GENERAL DESCRIPTIONS: Shift or roll instructions move bits to the left or right within a register or memory location Left shifts can be associated with multiplication by 2 Right shifts may be arithmetical or logical Arithmetical right shifts divide signed numbers by 2, keeping the sign bit for the result. May also be used to capture lsb or msb, while displacing other bits.

Shifts or rolls C Left shift or roll: (multiply by 2) C C Right logical shift or roll: (divide by 2 unsigned numbers) C Right arithmetic shift or roll: (divide by 2 signed numbers) S Sign bit remains

Shifts or Rolls (Example) C b3 b2 b1 b0 - C - x 1 SHIFT LEFT (A) Shift Right (Log) (B) Shift Rigt Arith: ( C ) NOTE: Carry ( C ) at left for left rolls Right C used for right rolls Arithmetic Look at shifts: Original number = 11 (unsigned), or -5 (signed) Including carry: Unsigned 22 or signed - 10 Only for unsigned: 11/2 yields 5 (in register ) and residue 1 --in C Only for signed: -5/2 yields -3 (in register ) and residue 1 (in C) -- Note: (-5) = (-3)*2 + 1, which is the division algorithm.

Rotate(s) C Rotate Left: C Rotate Right: C Rotate Left Through Carry:

Rotates (example) NOTE: Carry ( C ) at left for left rolls b3 b2 b1 b0 - C - zz 1 Rotate Left (A) R.L. through C (B) Rotate Right ( C ) Rot. Right thru C (D) NOTE: Carry ( C ) at left for left rolls Right C used for right rolls Remarks: 1. In (B) and (D), zz is the original unknown value in C 2. In (C), b3=1 because originally b0=1. This value is what was rotated.

Rolls and Rotates in MSP430

Rolling (Shifting) and Rotating Data bits Not all cases included Two core instructions: Right rolling arithmetic: rra dest Right rotation through Carry: rrc dest Two emulated instructions Left rolling arithmetic: rla dest = add dest,dest Rotate left through carry: rla dest = addc dest,dest Roll = Shift

Right arithmetic shift or roll rra: Word rra.w dest = rra dest Byte rra.b dest Arithmetic Interpretation: Divide by two ( dividend = Q*d + r, |r|<d R7 = FB0Fh = 1111101100001111 = (-1265) rra R7 1111110110000111 1 C=1 Z=0 N=1 V=0 New R7 = FD87h = > -633 -1265 = (-633)*2 +1

Right Rotation Through Carry rrc Some Uses: To divide by 2 unsigned numbers by first clearing C To extract bits from lsb to msb Think of other possibilities

Left rollings Left rolling: add dest,dest  multiply by 2 (may need carry) Other uses: extract bits from msb to lsb Examples: -----

Left Rotation Through Carry Arithmetic Interpretation: 2x + C Think of other uses