Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following code used to implement the instruction: foo $s0, $s1, $s2 mask: .word 0xfffff83f start: lw $t0,mask($zero) lw $s0,shifter($zero) and $s0,$s0,$t0 andi $s2,$s2,0x1f

Consider the following code used to implement the instruction:

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

2. What kinds of communication help sustain long-distance romances?

Answered: 1 week ago

Question

Be familiar with the integrative servicescape model.

Answered: 1 week ago

Question

Determine the roles of spatial layout and functionality.

Answered: 1 week ago