BITWISE OPERATIONS 353156 – Microprocessor Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.

Slides:



Advertisements
Similar presentations
ARM versions ARM architecture has been extended over several versions.
Advertisements

Embedded Systems Programming
Overheads for Computers as Components 2nd ed.
Multiplication – Microprocessor
1 ECE 5465 Advanced Microcomputers Group 11: Brian Knight Benjamin Moore Alex Williams.
Embedded System Design Center ARM7TDMI Microprocessor Data Processing Instructions Sai Kumar Devulapalli.
CONDITION CODE AND ARITHMETIC OPERATIONS – Microprocessor Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
COMP3221 lec10-logical-II&mul.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 10: C/Assembler Logical and Shift – II & Multiplication.
INTRODUCTION TO THE ARM PROCESSOR – Microprocessor Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
COMP3221 lec9-logical-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 9: C/Assembler Logical and Shift - I
ARM Microprocessor “MIPS for the Masses”.
Binary Logic (review) Basic logical operators: (Chapter 7 expanded)
Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 41 Today’s class More assembly language programming.
Modified from the notes by
Instruction Set Architecture & Design
Thumb Data Processing Instructions and Breakpoint Instructions 02/18/2015 Mingliang Ge Yi (Leo) Wu Xinuo (Johnny) Zhao.
COMP3221 lec08-arith.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 8: C/Assembler Data Processing
Logical, Shift, and Rotate Operations CS208. Logical, Shift and Rotate Operations  A particular bit, or set of bits, within the byte can be set to 1.
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
Elec2041 lec-11-mem-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 11: Memory Access - I
Computer Architecture CPSC 321 E. J. Kim. Overview Logical Instructions Shifts.
Logical & shift ops (1) Fall 2007 Lecture 05: Logical Operations.
ARM Instructions I Prof. Taeweon Suh Computer Science Education Korea University.
Embedded System Design Center Sai Kumar Devulapalli ARM7TDMI Microprocessor Thumb Instruction Set.
Topic 8: Data Transfer Instructions CSE 30: Computer Organization and Systems Programming Winter 2010 Prof. Ryan Kastner Dept. of Computer Science and.
Ch. 7 Logic, Shift and Rotate instr.
Lecture 4. ARM Instructions Prof. Taeweon Suh Computer Science & Engineering Korea University COMP427 Embedded Systems.
CSC 3210 Computer Organization and Programming Chapter 8 MACHINE INSTRUCTIONS D.M. Rasanjalee Himali.
Making Decision – Microprocessor
Assembly Language A Brief Introduction. Unit Learning Goals CPU architecture. Basic Assembler Commands High level Programming  Assembler  Machine Language.
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
CS 111 – Sept. 15 Chapter 2 – Manipulating data by performing instructions “What is going on in the CPU?” Commitment: –Please read through section 2.3.
1 Logic, Shift, and Rotate Instructions Read Sections 6.2, 7.2 and 7.3 of textbook.
Lecture 2: Advanced Instructions, Control, and Branching EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer.
Arithmetic and Logic Chapter 5
1 Sec (2.4) Arithmetic / logic instruction:. 2 Logical operations: Ex: XOR OR AND
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.
Instruction Set Architectures Early trend was to add more and more instructions to new CPUs to do elaborate operations –VAX architecture had an instruction.
ARM Shifts, Multiplies & Divide??. MVN Pseudo Instructions Pseudo Intruction: Supported by assembler, not be hardware.
Binary Logic (review) Basic logical operators:(Chapter 7 expanded) NOT AND – outputs 1 only if both inputs are 1 OR – outputs 1 if at lest one input is.
CS2100 Computer Organisation
Programming in Machine Language
ARM Registers Register – internal CPU hardware device that stores binary data; can be accessed much more rapidly than a location in RAM ARM has.
Assembly Language Assembly Language
Morgan Kaufmann Publishers
Microprocessor Systems Design I
Processor Instructions set. Learning Objectives
March 2006 Saeid Nooshabadi
March 2006 Saeid Nooshabadi
The University of Adelaide, School of Computer Science
Arithmetic and Logic Chapter 5
The Processor and Machine Language
MISP Assembly.
Computer Architecture & Operations I
Topic 6: Bitwise Instructions
Shift & Rotate Instructions)
Multiplication by small constants (pp. 139 – 140)
Introduction to Micro Controllers & Embedded System Design
Shift & Rotate Instructions)
MIPS Assembly.
Arithmetic and Logic Chapter 5
The ARM Instruction Set
Branching instructions
ARM Bitwise Logic.
Overheads for Computers as Components 2nd ed.
MIPS Assembly.
Computer Architecture
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.
Presentation transcript:

BITWISE OPERATIONS – Microprocessor Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat

Objectives  To understand  Bitwise Logical Operations OR AND XOR  Shift Operations Shift Left Shift Right Rotate

Bitwise Operations (1)  Up until now, we’ve done :  Arithmetic (ADD, SUB, RSB,..etc..)  Some of data movement (MOV)  All of these instructions view content of register as a single quantity  But for bitwise operations, we will see the content of register as 32 bits rather than as a single 32-bit number

Bitwise Operations (2)  Since register are composed of 32 bits, we may want to access individual bits rather than the whole.  Introduction two new classes of instructions/operations :  Logical Instruction  Shift Operations

Logical Operations  Operator Names:  AND  BIC  ORR  EOR  Operands  Destination : Register  Operand1 : Register  Operand2 : Register, Shifted Register, Immediate  Example  AND a1, v1, v2  AND a1, v1, #0x40

Logical AND Operator  AND (truth table)  AND : bit-by-bit operation leaves a 1 in the result only if both bits of the operands are 1 ABA AND B

Example : Logical AND Operator  Assume that register A and B are 8-bit register  Let A stores value  Let B stores value  Find A AND B AND

Exercise 1: Logical AND Operator  What is the value store in register R0 after the execution of program is done AREA ex1_1, CODE, READONLY ENTRY start MOV a2, #0x42 MOV a3, #0xFC AND a1, a2, a3 END AREA ex1_2, CODE, READONLY ENTRY start MOV a2, #0xBC AND a1, a2, #0xFF END (1)(2)

Logical BIC (AND NOT) Operator  BIC (BIt Clean) : bit-by-bit operation leaves a 1 in the result only if bit of the first operand is 1 and the second operands 0  Example 0011BIC

Exercise 2: Logical BIC Operator  What is the value store in register R0 after the execution of program is done AREA ex2_1, CODE, READONLY ENTRY start MOV a2, #0x42 MOV a3, #0xFC BIC a1, a2, a3 END AREA ex2_2, CODE, READONLY ENTRY start MOV a2, #0xBC BIC a1, a2, #0xFF END (1)(2)

MASK  AND and BIC normally use to create a mask  Example : Given R0 stores 0x  if we want to keep only the value of the last 2 bytes and we want to clear the first 2 bytes to 0 (0x ) R1 stores 0xFFFF AND R0, R0, R1 ; short written constant value  if we want to keep only the value of the first 2 bytes and we want to clear the last 2 bytes to 0 (0x ) R1 stores 0xFFFF0000 AND R0, R0, R1 ; long written constant value R2 stores 0xFFFF BIC R0, R0, R2 ; better ?

Logical OR Operator  OR (truth table)  OR : bit-by-bit operation leaves a 1 in the result if either bit of the operands is 1 ABA OR B

Example : Logical OR Operator  Assume that register A and B are 8-bit register  Let A = , and B =  Find A OR B OR  Example : ARM Instruction  ORRR0, R0, #0x

Exercise 3 : Logical OR Operator  What is the value store in register R0 after the execution of program is done AREA ex3_1, CODE, READONLY ENTRY start MOV a2, #0x34 MOV a3, #0x86 ORR a1, a2, a3 END

Logical XOR Operator  XOR (truth table)  XOR : bit-by-bit operation leaves a 1 in the result if bit of the operands are different ABA XOR B

Example : Logical XOR Operator  Assume that register A and B are 8-bit register  Let A = , and B =  Find A XOR B XOR  Example : ARM Instruction  EORR0, R0, #0x

Exercise 4 : Logical XOR Operator  What is the value store in register R0 after the execution of program is done AREA ex4_1, CODE, READONLY ENTRY start MOV a2, #0x34 MOV a3, #0x86 EOR a1, a2, a3 END

Shift Operations  Shift means move all the bits in a word to the left or right by number of bits  In ARM, there are 3 types of shift operations  Fill emptied bits with 0s (LSL, LSR)  Fill emptied bits with sign bits (ASR)  Fill emptied bits with the bits falling (rotation) (ROR)

Shift Operations (Type 1)  Move all the bits in a word to the left or right by a number of bits, filling the emptied bits with 0s  Example : Given A an 8-bit register which stores data Shift right by 4 bits Shift left by 4 bits

LSL, LSR Instructions  In ARM, we have 2 instructions for shift operation type 1  LSL (Logical Shift Left)  LSR (Logical Shift Right)  We can use 2 formats of instruction  Opcode dest_reg, reg_contains_number_of_bit_to_shift LSL R0, R1 ; R1 must store number of bit to shift  Opcode dest_reg, src_reg, constant_number_of_bit_to_shift LSR R0, R1, #4 ; Shift right value in R1 for 4 bits and then store it to R0  ** Only R0-R7 can do Shift operations **

Exercise 5: LSL, LSR Operations  What is the value store in register R0 after the execution of program is done AREA ex5_1, CODE, READONLY ENTRY start MOV a1, #0x01 MOV a2, #4 LSL a1, a2 END AREA ex5_2, CODE, READONLY ENTRY start MOV a1, #0xFF LSR a1, a1, #0x4 END (1)(2)

Shift Operations (Type 2)  Move all the bits in a word to the right by a number of bits, filling the emptied bits with sign bits  Example :  Given A an 8-bit register which stores data  Given A an 8-bit register which stores data Shift right by 4 bits

ASR Instructions  ASR (Arithmatic Shift Right)  We can use 2 formats of instruction  Opcode dest_reg, reg_contains_number_of_bit_to_shift ASR R0, R1 ; R1 must store number of bit to shift  Opcode dest_reg, src_reg, constant_number_of_bit_to_shift ASR R0, R1, #4 ; Shift right value in R1 for 4 bits and then store it to R0  ** Only R0-R7 can do Shift operations **

Exercise 6: ASR Operations  What is the value store in register R0 after the execution of program is done AREA ex6_1, CODE, READONLY ENTRY start MOV a1, #0xFFFFFF10 MOV a2, #2 ASR a1, a2 END AREA ex6_2, CODE, READONLY ENTRY start MOV a1, #0xFF ASR a1, a1, #0x2 END (1)(2)

Shift Operations (Type 3)  Move all the bits in a word to the right by a number of bits, filling the emptied bits with the bits falling of the right  Example : Given A an 8-bit register which stores data Rotate right by 3 bits

ROR Instructions  ROR (ROtate Right)  We can use 2 formats of instruction  Opcode dest_reg, reg_contains_number_of_bit_to_shift ROR R0, R1 ; R1 must store number of bit to shift  Opcode dest_reg, src_reg, constant_number_of_bit_to_shift ROR R0, R1, #4 ; Rorate right value in R1 for 4 bits and then store it to R0  ** Only R0-R7 can do Shift operations **

Exercise 7: ROR Operations  What is the value store in register R0 after the execution of program is done AREA ex7_1, CODE, READONLY ENTRY start MOV a1, #0xFFFFFF10 MOV a2, #4 ROR a1, a2 END AREA ex7_2, CODE, READONLY ENTRY start MOV a1, #0xFF ROR a1, a1, #0x4 END (1)(2)

Review : 2 nd Operand  2 nd operand for operation :  register  immediate (numerical constant)  shifted register  Example :  MOV R0, R1  MOV R0, #0x12  MOV R0, R1, LSL #4 ; R0  (R1 << 4)

Barrel Shifter : The Second Operand  Register, optionally with shift operation applied  Shift value can be either :  5 bit unsigned integer ADD R0, R1, R2, LSL #8 ;R0  R1 + (R2 << 8 bits)  Specified in bottom of another register ADD R0, R1, R2, LSL R3 ;R0  R1 + (R2 << R3 bits) ALU Barrel Shifter Operand 1Operand 2 Result  Immediate value  8 bit number  Can be rotated right through as even number of position  Assembler will calculate rotate for you from constant ADD R0, R1, #10 ; R0  R ADD R0, R1, #0xFF00 ; R0  R1 + (0xFF << 16 bits) ADD R0, R1, #0xFFF ; ERROR

Assignment 5  What is the value store in register R0 after the execution of program is done (explain the result of each instruction) AREA hw5_1, CODE, READONLY ENTRY start MOV a1, #0xFFFFFF18 MOV a2, #16 ROR a1, a2 MOV a2, #0xFF AND a1, a1, a2, LSR #4 LSR a1, #16 END AREA hw5_2, CODE, READONLY ENTRY start MOV a1, #0xFF MOV a2, #0xCC MOV a3, #16 ADD a1, a1, a2, LSL a3 EOR a2, a2, #0x65 ORR a1, a1, a2, LSL #8 END (1) (2)