Assembly HW 5

Ace your homework & exams now with Quizwiz!

What is in $8, $9, and $10 after this program executes? Test in spim: spim> re "q8.s" spim> breakp main spim> run spim> s spim> p $8 spim> s spim> p $9 spim> s spim> p $10 # file: q8.s .text .globl main main: ori $15, $0,0x0DA5 # load bit pattern register into $15 ori $8,$15,0x368F # OR with second pattern andi $9,$15,0x368F # AND with second pattern xori $10,$15,0x368F # XOR with second pattern ## End of file

$15 = 0000 1101 1010 0101 OR 0011 0110 1000 1111 -------------------- $8 = 0011 1111 1010 1111 3 F A F $15 = 0000 1101 1010 0101 AND 0011 0110 1000 1111 -------------------- $9 0000 0100 1000 0101 0 4 8 5 $15 = 0000 1101 1010 0101 XOR 0011 0110 1000 1111 -------------------- $10= 0011 1011 0010 1010 3 B 2 A

What is loaded into $10 when you execute this code? ## Program to bitwise OR two patterns .text .globl main main: ori $8,$0,0x0DA5 # put first pattern into register $8 ori $10,$8,0x368F # or ($8) with second pattern. Result to $10. ## End of file

0000 1101 1010 0101 0DA5 | 0011 0110 1000 1111 368F -------------------- ----- 0011 1111 1010 1111 3FAF

All MIPS registers are 32-bits. That means that $0 is a bit string of 32 zeros. The operand in this bitwise immediate OR is only 16 bits. How does MIPS handle this? ori $8, $0, 0x2

MIPS zero extends the 16-bit operand 0x2 by 16 bits. In other words, 0x2 is padded with zeros on the left to make it 32 bits.

. Can you use ori to load a register with a signed integer?

No. A signed integer has a sign bit in the most significant bit location. Since ori zero-extends the 16-bits to 32 bits, you can never have a 1 in the sign bit to represent a negative integer.

What is the outcome of these MIPS instructions? ori $9, $0, 0x5 sll $10, $9, 3

Positive 5 is loaded into $9. 5 is shift left-ed by 3 which means 5 is multiplied by 2^3 (8). 0x28 (40 decimal) is loaded into $10. Thus 5 * 8 is performed as it should be.

Explain this MIPS instruction and give the result. ori $8, $0, 0x2

The 16-bit 0x2 immediate operand has been zero-extended and loaded into register $8; i.e., positive decimal two is in $8. This is a very inexpensive way to load a register with a positive integer. You cannot load a negative integer, however.

Explain in detail what this instruction does and give the result. andi $8, $0, 0xFFFF

This is MIPS bitwise immediate and. The constant 0xffff is zero extended to 32 bits to the left. A bitwise AND is performed with 0xffff and 32 zeros. The result is a 32 bit string of zeros. This is a quick way to clear a register (filling a register with all zero bits).

Where is the operand 0x2 placed in the binary encoding of this instruction? ori $8, $0, 0x2

This is a bitwise immediate OR between 0x2 and the contents of register 0. Since $0 contains zero, the result is 0x2 and is loaded into $8. The immediate operand 0x2 (hex 2) is loaded into the last 16 bits of the instruction. This means that immediate instructions are limited to 16-bit operands. ori with zero is a move operation

What is wrong with the following instruction? ori $0, $9, 0x32

You are trying to load register $0 with hex 32. $0 is zero and cannot be changed. You may not get an error if you do this but $0 remains zero

Let b1 and b2 be loaded as shown below. What is in b1 after these C xor operations? Is there a generalization you can make for any arbitrary bit string? // load b1 with 1011 a) b1 = b1 ^ b1; // caret in C is bitwise exclusive or // load b1 with 1010 and b2 with 1001 b) b1 = b1 ^ b2; b2 = b2 ^ b1; b1 = b1 ^ b2;

a) any bit string bitwise xor-ed with itself is all zeros b) b2 Let b1=1010. Let b2=1001. (length 4 tests all possible outcomes) 1010 1001 0011 ^ 1001 ^ 0011 ^ 1010 ----- ----- ----- b1: 0011 b2: 1010 b1: 1001. Note that b1 and b2 are swapped. XOR can be used to swap two arbitrary bit strings without using temp storage)


Related study sets

Chapters 1-4 Quiz Questions Network+

View Set

Teaching Reading: Elementary (5205)

View Set

EAQ #6 Transient Ischemic Attack (TIA) and Stroke & Neuro and M/S

View Set

Lecture 13: Microevolution: Population genetics and speciation (Major Concepts)

View Set

Principles of Business: Chapter 18

View Set

economics : saving and borrowing

View Set

Ch. 16: Program Management, Chapter 16: Program Management, NURS 450 - Ch. 21

View Set