Question: Consider the following code used to implement the instruction: Mips assembly language only foo $s0, $s1, $s2 mask: .word 0xfffff83f start: lw $t0,mask($zero) lw $s0,shifter($zero)

Consider the following code used to implement the instruction: Mips assembly language only

foo $s0, $s1, $s2

mask: .word 0xfffff83f start: lw $t0,mask($zero) lw $s0,shifter($zero) and $s0,$s0,$t0 andi $s2,$s2,0x1f sll $s2,$s2,6 or $s0,$s0,$s2 sw $s0, shifter($zero) shifter:sll $s0,$s1,0 Add meaningful comments to the code and write a paragraph describing how it works. Why do you suppose that writing "self-modifying code" such as this is a bad idea (and often times not actually allowed)? Explanatory Notes:

Labels are equivalent to immediates corresponding to the address that the OS will decide for them. For example, if the OS decides to start the program at 100010, mask is the immediate 100010.

You may assume that the program is loaded at an address whose upper 16 bits are 0s. This assumption is needed since MIPS immediates are 16-bits, and references to shifter/mask are immediates interpreted as the lower 16-bits of shifter/mask. You may also assume that shifter and mask both have a msb (bit 15) of 0 - this assumption is needed since offsets are sign-extended.

We have not covered the .word directive yet. This is an assembler directive, which is essentially an instruction to the assembler (NOT an assembly language instruction). In this case, it tells the assembler to reserve a word of memory initialized to 0xfffff83f. Mask is the address of this word (just as start is the address of the word in memory containing the machine code for that lw instruction).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!