1 / 25

MIPS Logic & Shift

MIPS Logic & Shift. Bitwise Logic. Bitwise operations : logical operations applied to each bit Bitwise OR:. Immediate Value. Immediate Value Value hard coded into instruction. Immediate Value. Immediate Value Value hard coded into instruction 16 bits available to store immediate:.

Download Presentation

MIPS Logic & Shift

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MIPS Logic & Shift

  2. Bitwise Logic • Bitwise operations : logical operations applied to each bit • Bitwise OR:

  3. Immediate Value • Immediate ValueValue hard coded into instruction

  4. Immediate Value • Immediate ValueValue hard coded into instruction • 16 bits available to store immediate:

  5. Register • Registers = 32 bits, Immediate 16 bits • Must extend immediate

  6. Max Immediate • Immediate value can't require 17+ bits • Unless you use Pseudo instructions • Must be UNCHECKED for now

  7. OR vs ORI • OR $6, $5, $4 • ORI $6, $0, 0xffff

  8. Logical Ops to Know • Immediate instructionsori, andi, xoriinstruction $dest, $source, immediate • Register-Register Instructionsor, and, xor, norinstruction $dest, $source1, $source2

  9. Quick Reminders • A or 0 = A • Anything or'd with 0 is that thing • A and 1 = A • Anything and'd with 1 is that thing • A and 0 = 0 • Anything and'd with 0 is 0 • A xor 1 = not(A) • Xoring with 1 flips bit

  10. Common Tricks • ORILoad a value to register by ori $0 and value

  11. Common Tricks • ORClear a register by oring $0 with self

  12. Common Tricks • ORCopy register by or with $0

  13. Common Tricks • ORCombine non-overlapping patterns:

  14. Common Tricks • ANDKeep only specified bits byanding with 1's in desireddigits

  15. Common Tricks • NORDo NOT by NOR with $0

  16. Logical Shift • Logical Shifts • Add 0's to fill empty space • sll, srl instructions:instruction$dest, $source, number of bits

  17. NOP • NOP : No operation • Done with sll $0, $0, $0 • Opcode for sll is 0 • 0x00000000 is nop!

  18. Loading Large Value • Loading 32bit immediate takes 3 steps:Load (ori) 16bits (in right part of register)Shift left 16 bits (move to left half of register)Load (ori) 16bits (in right part of register)

  19. Bit Isolation • Getting particular bits out of pattern • Strategy 1: • Shift to wipe out others • Want to clear left 8 bits:1010 1011 1111 0110 1010 1011 1111 0110 • Shift left 8 bits:1111 0110 1010 1011 1111 0110 0000 0000 • Shift back right 8 bits:0000 0000 1111 0110 1010 1011 1111 0110

  20. Bit Isolation • Getting particular bits out of pattern • Strategy 1: • Shift to wipe out others • Now want to isolate green five bits0000 0000 1111 0110 1010 1011 1111 0110 • Shift right 190000 0000 0000 0000 0000 0000 0001 1110

  21. Bit Isolation • Getting particular bits out of pattern • Strategy 2: • Masking : binary pattern showing bits to keep 0x00 : keep no bits 0x01 : keep bit 1 (0000 0001) 0x04 : keep bit 3 (0000 0100) 0x05 : keep bit 1 & 3 (0000 0101) 0xF0 : keep bit 5-8 (1111 0000)

  22. Using Masks • AND with a mask 0's out unmasked portions:

  23. Hex Mask • F (1111) mask a whole hex digit

  24. Bit Isolation • Getting particular bits out of pattern • Strategy 2: • Masking : binary pattern showing bits to keep • Want to keep just green bits1010 1011 1111 0110 1010 1011 1010 0110 • Create mask… 0x01F00000 0000 0000 0000 0000 0001 1111 0000 • AND0000 0000 0000 0000 0000 0001 1010 0000

  25. Bit Isolation • Want to keep just green bits1010 1011 1111 0110 1010 1011 1010 0110 • Create mask… 0x01F00000 0000 0000 0000 0000 0001 1111 0000 • AND0000 0000 0000 0000 0000 0001 1010 0000

More Related