Question

MIPS CODE

A simple problem that makes use both the shift and logic operations is the digit-packing example. Suppose that two decimal di

0 0
Add a comment Improve this question Transcribed image text
Answer #1
// none of these allocate any storage
    #define MAX_SIZE  256
    #define IF(a)    if (a) {
    #define ENDIF    }
    typedef struct {
        unsigned char red;      // 'unsigned char' is an unsigned, 8-bit int
        unsigned char green;
        unsigned char blue;
        unsigned char alpha;
    } RGBa;

    // these allocate storage
    int     i;
    int     N = 20;
    char    prompt[] = "Enter an integer:";
    int     A[MAX_SIZE];
    int*    pBArray;
    int     BSize;
    RGBa    background = {0xff, 0xff, 0xff, 0x0};
  • C code:
        i = N*N + 3*N
    
    "Unoptimized":
    (Note: There are some small disagreements in the syntax of assembler between SPIM, which is used in the book, and Cebollita, which is the tool we will be using. I have tried to follow the conventions of Cebollita here.)
        lw     $t0, 4($gp)       # fetch N
        mult   $t0, $t0, $t0     # N*N
        lw     $t1, 4($gp)       # fetch N
        ori    $t2, $zero, 3     # 3
        mult   $t1, $t1, $t2     # 3*N
        add    $t2, $t0, $t1     # N*N + 3*N
        sw     $t2, 0($gp)       # i = ...
    
    "Optimized":
        lw     $t0, 4($gp)       # fetch N
        add    $t1, $t0, $zero   # copy N to $t1
        addi   $t1, $t1, 3       # N+3
        mult   $t1, $t1, $t0     # N*(N+3)
        s
Add a comment
Know the answer?
Add Answer to:
A simple problem that makes use both the shift and logic operations is the digit-packing example....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (Packing Characters into an Integer) The left-shift operator can be used to pack four character values into a four-byt...

    (Packing Characters into an Integer) The left-shift operator can be used to pack four character values into a four-byte unsigned int variable. Write a program that inputs four characters from the keyboard and passes them to function packCharacters. To pack four characters into an unsigned int variable, assign the first character to the unsigned intvariable, shift the unsigned int variable left by 8 bit positions and combine the unsigned variable with the second character using the bitwise inclusive OR operator....

  • PROBLEM STATEMENT The mini-calculator will use a small ALU to perform arithmetic operations on two 4-bit values which are set using switches. The ALU operations described below are implemented with a...

    PROBLEM STATEMENT The mini-calculator will use a small ALU to perform arithmetic operations on two 4-bit values which are set using switches. The ALU operations described below are implemented with an Adder/Subtractor component. A pushbutton input allows the current arithmetic result to be saved. An upgraded mini-calculator allows the saved value to be used in place of B as one of the operands. The small ALU that you will design will use the 4-bit adder myadder4 to do several possible...

  • 1.) a.) Using the simplified instruction set shown for part b, write code for the following....

    1.) a.) Using the simplified instruction set shown for part b, write code for the following. Suppose memory locations 1400 to 1449 contain 16-bit words. Each word represents 2 ASCII characters. Write code to read in and write out these 100 characters. Left-side character from location 1400 should be first, right-side character from location 1400 should be second, and remaining characters follow in numeric order. Assume you have access to 4 registers: R1, R2, R3, R4. Each register holds one...

  • Python Project

    AssignmentBitmap files map three 8-bit (1-byte) color channels per pixel. A pixel is a light-emitting "dot" on your screen. Whenever you buy a new monitor, you will see the pixel configuration by its width and height, such as 1920 x 1080 (1080p) or 3840x2160 (4K). This tells us that we have 1080 rows (height), and each row has 1920 (width) pixels.The bitmap file format is fairly straight forward where we tell the file what our width and height are. When...

  • This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation...

    This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT