Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pseudo-ops and Bitwise Operations

Similar presentations


Presentation on theme: "Pseudo-ops and Bitwise Operations"— Presentation transcript:

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

2 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 term 2181

3 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 term 2181

4 Pseudo-ops (pseudo-instructions)

5 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 term 2181

6 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 term 2181

7 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 term 2181

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

9 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 term 2181

10 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 term 2181

11 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 term 2181

12 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 term 2181

13 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 term 2181

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

15 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 term 2181

16 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 term 2181

17 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 term 2181

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

19 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 term 2181

20 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 term 2181


Download ppt "Pseudo-ops and Bitwise Operations"

Similar presentations


Ads by Google