sol ch 2

sol ch 2 - Solutions of Homework 1 2.2 Convert 7fff fffahex...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Solutions of Homework 1 2.2 Convert 7fff fffa hex to binary and decimal. 7fff fffa hex = 0111 1111 1111 1111 1111 1111 1111 1010 two = 2,147,483,642 ten 2.3 Convert from binary to hexadecimal. 1100 1010 1111 1110 1111 1010 1100 1110 two = cafe face hex 2.4 Why doesn’t MIPS have a subtract immediate instruction? Since MIPS includes add immediate and since immediates can be positive or negative, subtract immediate would be redundant. 2.5 Consider the following code used to implement the instruction sllv $s0, $s1, $s2 which uses the least significant 5 bits of the value in register $s2 to specify the amount register $s1 should be shifted left: .data mask: .word 0xfffff83f .text start: lw $t0, mask lw $s0, shifter and $s0,$s0,$t0 andi $s2,$s2,0x1f sll $s2,$s2,6 or $s0,$s0,$s2 sw $s0, shifter 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
sll $s0,$s1,0 Add comments to the code and write a paragraph describing how it works. Note that the two lw instructions are pseudo- instructions that use a label to specify a memory address that contains the word of data to be loaded. Why do you suppose that writing “self-modifying code” such as this is a bad idea (and oftentimes not actually allowed)? Note about pseudo-instruction lw $t0, address: lui $at, upper_half(address) ori $at, $at, lower_half(address) lw $t0, 0($at) .data mask: .word 0xfffff83f # shamount mask .text start: lw $t0, mask # load the mask lw $s0, shifter # load the shift instr and $s0,$s0,$t0 # clear shamount andi $s2,$s2,0x1f # take the 5 LSBs of the shift sll $s2,$s2,6 # align it to shamount position or $s0,$s0,$s2 # insert the shamount sw $s0, shifter # overwrite the shift instr shifter: sll $s0,$s1,0 # perform the modified instr The last shift instruction is modified so that its shamount field is written by the 5 LSBs from $s2. 2
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

sol ch 2 - Solutions of Homework 1 2.2 Convert 7fff fffahex...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online