Bitwise Logic and Immediate Operands

Slides:



Advertisements
Similar presentations
Assembly Language Programming
Advertisements

– © Yohai Devir 2007 Technion - IIT Tutorial #10 MIPS commands.
Systems Architecture Lecture 5: MIPS Instruction Set
COMP3221 lec9-logical-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 9: C/Assembler Logical and Shift - I
Instruction Set Architecture & Design
Feb 18, 2009 Lecture 4-2 instruction set architecture (Part II of [Parhami]) MIPS encoding of instructions Spim simulator more examples of MIPS programming.
Computer Architecture CPSC 321 E. J. Kim. Overview Logical Instructions Shifts.
Logical & shift ops (1) Fall 2007 Lecture 05: Logical Operations.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
Table 1. Software Hierarchy Levels.. Essential Tools An assembler is a program that converts source-code programs into a machine language (object file).
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 6: Logic/Shift Instructions Partially adapted from Computer Organization and Design, 4.
Bit Operations C is well suited to system programming because it contains operators that can manipulate data at the bit level –Example: The Internet requires.
A bit can have one of two values: 0 or 1. The C language provides four operators that can be used to perform bitwise operations on the individual bits.
Development. Development Environment Editor Assembler or compiler Embedded emulator/debugger IAR Embedded Workbench Kickstart Code Composer Essentials.
1. 2 Instructions: Words of the language understood by CPU Instruction set: CPU’s vocabulary Instruction Set Architecture (ISA): CPU’s vocabulary together.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
Module : Algorithmic state machines. Machine language Machine language is built up from discrete statements or instructions. On the processing architecture,
Logic Conditional Processing. Status flags - review The Zero flag is set when the result of an operation equals zero. The Carry flag is set when an instruction.
MIPS Logic & Shift. Bitwise Logic Bitwise operations : logical operations applied to each bit Bitwise OR:
IFT 201: Unit 1 Lecture 1.3: Processor Architecture-3
Chapter 2 CSF 2009 The MIPS Assembly Language: Introduction to Binary System.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Chapter 10 Instruction Sets: Characteristics and Functions Felipe Navarro Luis Gomez Collin Brown.
EET 4250 Instruction Representation & Formats Acknowledgements: Some slides and lecture notes for this course adapted from Prof. Mary Jane Penn.
Integer Multiplication, Division Arithmetic shift Twice the number of places MIPS multiply unit. mult, multu Significant bits Mfhi, mflo, div, divu Arithmetic.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 9 Binary Representation and Logical Operations.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic6: Logic, Multiply and Divide Operations José Nelson Amaral.
Shift Instructions and Logical Instructions
Instruction Sets: Characteristics and Functions  Software and Hardware interface Machine Instruction Characteristics Types of Operands Types of Operations.
Pirouz Bazargan SabetDecember 2003 Effective Implementation of a 32-bit RISC Processor Pirouz Bazargan Sabet University of Paris 6 - LIP6 - ASIM
Bit Manipulation in 'C' 'C' bit operators
Microprocessor & Assembly Language
CS Computer Organization Numbers and Instructions Dr. Stephen P. Carl.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Yaohang Li.
Memory Access Instructions Load and Store Addressing Modes Memory Addressing. Base addressing mode. Load byte and store byte: lb, lbu, sb Address alignment.
Floating Point. Binary Fractions.
MIPS Arithmetic is 32 bits
Computers’ Basic Organization
Integer Multiplication, Division Arithmetic shift
Memory Access Instructions
Integers’ Representation. Binary Addition. Two's Complement.
Assembly Language Programming of 8085
COMPUTER ARCHITECTURE & OPERATIONS I
Integers/Characters Input/Output
Morgan Kaufmann Publishers
Computer Organization and Design Instruction Sets - 2
The University of Adelaide, School of Computer Science
Chapter 5 The LC-3.
MPIS Instructions Functionalities of instructions Instruction format
MISP Assembly.
The University of Adelaide, School of Computer Science
How to represent signed integers
Computer Architecture & Operations I
The University of Adelaide, School of Computer Science
CS-401 Computer Architecture & Assembly Language Programming
ECEG-3202 Computer Architecture and Organization
The University of Adelaide, School of Computer Science
Part II Instruction-Set Architecture
MIPS Assembly.
ECEG-3202 Computer Architecture and Organization
CS 206D Computer Organization
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
ARM Bitwise Logic.
Logical instructions And rd rs rt Nor rd rs rt Or rd rs rt
Example 1: (expression evaluation)
Logical Instructions And rd rs rt Nor rd rs rt Or rd rs rt
MIPS Arithmetic and Logic Instructions
Chapter 10 Instruction Sets: Characteristics and Functions
Presentation transcript:

Bitwise Logic and Immediate Operands Bitwise operation Zero Extension Immediate operand instructions (ori, andi, xori)   Textbook: Appendix A – A.10. MIPS R2000 assembly language. Central Connecticut State University, MIPS Tutorial. Chapter 11.

Bitwise Operation 0110 1100 operand 0101 0110 operand ------------ A bitwise operation is where a logical operation is performed on the bits of each column of the operands. With a bitwise logic operation two bit patterns are "lined up" Then a logic operation (such as OR, AND, …) is performed between pairs of bits. Here is the bitwise OR between two 8-bit patterns. 0110 1100 operand 0101 0110 operand ------------ 0111 1110 result

Zero Extension of decimal numbers When doing operations with decimal numbers everyday we do zero extension of that numbers intuitively if they have different amount of digits.

Zero Extension or padding with zeros with binary numbers Suppose we have this 16 bit number as a first operand 0000 0000 0000 0010 And this 32 bit number as a second operand 0000 0000 0000 0000 0000 0000 0000 0000 We want to perform OR operation between 2 operands. First we should do zero extension of the first operand Then perform the operation with the full length of both operands. zero extended part ---- ---- ---- ---- 0000 0000 0000 0000 0000 0000 0000 0010 -- zero extended 1st operand 0000 0000 0000 0000 0000 0000 0000 0000 -- 2nd operand --------------------------------------- 0000 0000 0000 0000 0000 0000 0000 0010 -- result

What is immediate operand ? A machine instruction can use some of its bits as one of the operands for a machine operation. This is called an immediate operand. Using this kind of operations the program can set up the registers with the desirable known values. Immediate operand example   address machine code assembly code —————————— —————————— ————————————— 0x00400000 0x34080002 ori $8,$0,0x2    The last 16 bits (4 nibbles) of the machine instruction contain the immediate operand 0x0002.

Zero Extension of immediate operand ori $8,$0,0x2 16 bits of immediate operand 0000 0000 0000 0010 32 bits of register zero 0000 0000 0000 0000 0000 0000 0000 0000 zero extension ---- ---- ---- ---- 0000 0000 0000 0000 0000 0000 0000 0010 --------------------------------------- An OR operation is done in each column. The 32-bit result is placed in register $8.

OR Immediate used with Non-zero Operands ori d,s,const register d <-- bitwise OR of const with the contents of register $s(source) const represents a positive integer 0 <= const <= 65535 (0xFFFF -16 bits) The three operands of the assembly instruction d, $s, and const must appear in that order.

OR programming tricks What is the value of Xs ? 0000 0000 0000 0000 0000 0000 000X 00X0 - R1 0000 0000 0000 0000 0000 0000 0001 0000 - R2 --------------------------------------- 0000 0000 0000 0000 0000 0000 0001 0010 – R3 Set the value of a bit to 1 Get the value of a bit

OR Immediate used with Zero Register – setup the register ori d,$0,const register d <-- const. (d – destination)  const represents a positive integer 0 <= const <= 65535 (0xFFFF -16 bits) . The three operands of the assembly instruction d, $0, and const must appear in that order.

ORI Example ## Program to bitwise OR two patterns .text .globl main main: ori $8,$0,0x0FA5 ori $10,$8,0x368F ## End of file

AND Immediate Instruction andi d,s,const register d <-- bitwise AND of immediate operand const and the contents of register $s. const is a 16-bit pattern 0x0000 ... const ... 0xFFFF Simple AND Rules  AND-ing the Register with 0s sets the Register value to 0s. AND-ing the Register with the pattern (mask) 0s and 1s selects the original Register’s bits by mask of 1s. The original values are not changed only where the mask bits are 1s. The other bits are set to 0s.

AND programming tricks What is the value of Xs ? 0000 0000 0000 0000 0000 0000 XXXX XXXX - R1 0000 0000 0000 0000 0000 0000 0001 1111 - R2 --------------------------------------- XXXX XXXX XXXX XXXX XXXX XXXX 0001 0010 – R3 What is the value of R1 ? XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX - R1 1111 1111 1111 1111 1111 1111 1111 1111 - R2 --------------------------------------- 0000 0000 0000 0000 0000 0000 0000 0000 – R3

Exclusive Or Immediate (XOR) Simple XOR Rules   XOR the Register with itself sets the Register value to 0s. XOR the Register with 1s inverts the original Register’s content. XOR compares 2 operand and sets 1s in result bits where the operands are different. xori d,s,const register d <-- bitwise XOR of immediate operand const and the contents of register $s. const is a 16-bit pattern 0x0000 ... const ... 0xFFFF

XOR programming tricks Invertion - What is the value of X ? 0000 0000 0000 0000 0000 0000 000X 0000 - R1 0000 0000 0000 0000 0000 0000 0001 0000 - R2 --------------------------------------- 0000 0000 0000 0000 0000 0000 0001 0000 – R3 Comparison - Is R1==R2 ? XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX - R1 XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX - R2 --------------------------------------- 0000 0000 0000 0000 0000 0000 0000 0000 – R3 if (R3==0) then ...

Example Program .text .globl main main: ori $15, $0,0x0FA5 ## Program to bitwise OR, AND, and XOR two patterns .text .globl main main: ori $15, $0,0x0FA5 ori $8,$15,0x368F andi $9,$15,0x368F xori $10,$15,0x368F ## End of file