Pseudo-ops and Bitwise Operations

Slides:



Advertisements
Similar presentations
CDA 3100 Recitation Week 8. Question 1.data A:.word 21,3,2,9,100,22,6,15,33,90.text.globl main main: la $a0, A li $a1, 17 li $a2, 10 jal funct li $v0,
Advertisements

1 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
1 Nested Procedures Procedures that don't call others are called leaf procedures, procedures that call others are called nested procedures. Problems may.
Wannabe Lecturer Alexandre Joly inst.eecs.berkeley.edu/~cs61c-te
Recitation Material of Engineering an Assembler June 11, 2013.
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
Lecture 8: MIPS Instruction Set
Assembly Language II CPSC 321 Andreas Klappenecker.
Instruction Representation II (1) Fall 2007 Lecture 10: Instruction Representation II.
Computer Architecture CPSC 321 E. J. Kim. Overview Logical Instructions Shifts.
Instruction Representation II (1) Fall 2005 Lecture 10: Instruction Representation II.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 3.
Karnaugh Maps By: Shakil Nobes.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
MIPS Logic & Shift. Bitwise Logic Bitwise operations : logical operations applied to each bit Bitwise OR:
Addressing Modes. Register Addressing Immediate Addressing Base Addressing Indexed Addressing PC-Relative Addressing.
Control Structures Computer Organization I 1 October 2009 © McQuain, Feng & Ribbens Conditional Control Structure if ( i < j ) goto A; else.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Mental Arithmetic Strategies Scotts Primary School. Mental Arithmetic Scheme.
Programs – Calling Conventions
Virtual Memory: Implementing Paging
Memory – Caching: Writes
Programs, Instructions, and Registers
CS/COE 0447 (term 2181) Jarrett Billingsley
Mental Arithmetic Strategies
Lecture 6: Assembly Programs
Hexadecimal, Signed Numbers, and Arbitrariness
Virtual Memory: the Page Table and Page Swapping
Functions and the Stack
Breaking the mold with CSS
CS/COE 1541 (term 2174) Jarrett Billingsley
CS/COE 0447 (term 2181) Jarrett Billingsley
Bitfields and Logic Basics
Minimization and Sequential Logic
Binary Addition and Subtraction
The Register File and ALU
Conditional Branches What distinguishes a computer from a simple calculator is its ability to make decisions Decisions are made using the if statement,
The Interconnect, Control, and Instruction Decoding
Conditional Control Structure
youtube.com/watch?v=hy0ptZisr70
CS/COE0447 Computer Organization & Assembly Language
Pseudo-ops, Debugging, etc.
CSCI206 - Computer Organization & Programming
MPIS Instructions Functionalities of instructions Instruction format
These are slides from Comp411
Winter 2018 CISC101 11/29/2018 CISC101 Reminders
MIPS Instructions.
Bitwise Operations and Bitfields
More Functions and the Stack
Instruction encoding The ISA defines Format = Encoding
CS/COE0447 Computer Organization & Assembly Language
CS/COE 0447 Jarrett Billingsley
Multiplication and Division
The Interconnect, Control, and Instruction Decoding
October 24 Programming problems? Read Section 6.1 for November 5
CS/COE0447 Computer Organization & Assembly Language
CS/COE 0447 Jarrett Billingsley
MIPS function continued
Digital Logic.
FSMs, Multiplication, and Division
Arithmetic and Decisions
Instruction encoding The ISA defines Format = Encoding
Instruction encoding The ISA defines Format = Encoding
Lecture 6: Assembly Programs
Instructions in Machine Language
Conditionals and Functions
Instruction encoding The ISA defines Format = Encoding
MIPS function continued
Conditional Control Structure
Presentation transcript:

Pseudo-ops and Bitwise Operations CS/COE 0447 (term 2181) Jarrett Billingsley

Class announcements If you're confused about Lab 2… Oh my god it's due today why haven't you started it yet Don't make me make recitation attendance required again If I keep the exam on 9/28 (one week from today), how many of you will hate me? 9/21/2017 CS/COE 0447 term 2181

When do I push/pop registers and which ones?? You only need to push registers at the beginnings of functions. If you push any, then you need to pop them before you return. If you need to call another function (jal), then push/pop ra. If you need to use one or more s registers as local variables, then push/pop the ones you need to use. Otherwise, no pushing or popping needed. 9/21/2017 CS/COE 0447 term 2181

Pseudo-ops (pseudo-instructions)

I lied. move li la mul a, b, c subi blt/gt/le/ge b lw r, (t0) Many of the instructions you've learned so far do not really exist. These are pseudo-ops. They're convenient shorthand for common operations, for our squishy human brains. Why did we learn these? They're useful. They hide some of the confusing ugliness of the "real" instruction set. That lets me teach things in a better order. move li la mul a, b, c subi blt/gt/le/ge b lw r, (t0) lw r, var 9/21/2017 CS/COE 0447 term 2181

What's really going on here? They're translated by the assembler into real MIPS instructions. Never touch the 'at' register – it's used by the assembler for this. You can see the real instructions in the Execute tab's code view. 9/21/2017 CS/COE 0447 term 2181

Do we have to know what the real instructions are?? Nnnnooooooooooooo Again: dumb details you will never use. But the concept of pseudo-ops is important. Everything your computer does is made of smaller, simpler operations. Everything is a pseudo-op! Therefore, anything you need the computer to be able to do, can be built out of simpler operations. Like pushing and popping. 9/21/2017 CS/COE 0447 term 2181

Bitwise Operations 9/21/2017 CS/COE 0447 term 2181

What are "bitwise" operations? The "numbers" we use on computers aren't really numbers. It's often useful to treat them instead as a pattern of bits. Bitwise operations treat a value as a pattern of bits. 1 9/21/2017 CS/COE 0447 term 2181

The simplest operation: NOT (logical negation) If the light is off, turn it on. If the light is on, turn it off. We can summarize this in a truth table. We write NOT as ~A, or ¬A, or A with a bar over it which I spent the last twenty goddamn minutes trying to type or insert or copy or whatever and it just absolutely refuses to work so just roll with it okay. A Q 1 9/21/2017 CS/COE 0447 term 2181

Applying NOT to a whole bunch of bits If we use the not instruction in MIPS or the ~ operator in C/Java, this is what happens: This is one step of… what was it again? ~ 1 = 1 9/21/2017 CS/COE 0447 term 2181

Let's add some switches There are two switches in a row connecting the light to the battery. How do we make it light up? 9/21/2017 CS/COE 0447 term 2181

A B Q 1 AND (Logical product) 1 & 1 = 1 A&B A∧B A⋅B AB AND is a binary (two-operand) operation. It can be written a number of ways: A&B A∧B A⋅B AB If we use the and instruction (or & in C/Java): A B Q 1 1 & 1 = 1 We did 8 independent AND operations. 9/21/2017 CS/COE 0447 term 2181

"Switching" things up ;)))))))))))))))))))))) NOW how can we make it light up? 9/21/2017 CS/COE 0447 term 2181

A B Q 1 OR (Logical sum…?) 1 | 1 = 1 A|B A∨B A+B We might say "and/or" in English. It can be written a number of ways: A|B A∨B A+B If we use the or instruction (or | in C/Java): A B Q 1 1 | 1 = 1 We did 8 independent OR operations. 9/21/2017 CS/COE 0447 term 2181

lui, ori… lui at, 0xDEAD ori t0, at, 0xBEEF If I write li t0, 0xDEADBEEF in MIPS, the assembler turns it into: lui at, 0xDEAD ori t0, at, 0xBEEF The reason it splits it up is that there's only enough space in each instruction to fit half of 0xDEADBEEF. But what the heck is it doing? 9/21/2017 CS/COE 0447 term 2181

By your powers combined… lui means load upper immediate. It puts the immediate value into the upper 16 bits of the register, and zeroes out the rest. lui at, 0xDEAD Then, ori does logical OR of at and its immediate. ori t0, at, 0xBEEF 1 1 | 1 1 1 1 1 1 D E A D B E E F 9/21/2017 CS/COE 0447 term 2181

Okaaaaay… so what 9/21/2017 CS/COE 0447 term 2181

I wanna turn the light on!! I have a sequence of 0s. I wanna turn one of them into a 1. What bitwise operation can I use to do that? ? 1 1 9/21/2017 CS/COE 0447 term 2181

I wanna turn the light off!! I wanna turn one of the 1s into a 0. What bitwise operation can I use to do that? 1 1 1 ? 1 1 1 1 1 9/21/2017 CS/COE 0447 term 2181