Write mips assembly language define and initialize variables

Assignment Help Assembly Language
Reference no: EM13771646

1  Instructions

You may work in pairs with a partner on this assignment if you wish or you may work alone. If you work with a partner, only submit one zip archive with both of your names in the PDF document and source code file; you will each earn the same number of points. Your zip archive must be uploaded to Blackboard by the assignment deadline. Section 3 describes what to submit and by when.

2  Exercises

1. A MIPS word is stored at memory address 0x1000_100A. Is this word naturally aligned? If so, explain why, and if
     not, explain why not.

2. Consider this C code. Assume the values of variables e, f, g, and h have been loaded from memory into registers $t0, $t1, $t2, and $t3, respectively. Assume we are associating variable i with register $s0. Write the MIPS instructions not a complete program-that implements the assignment statement.
int e, f, g, h, i;
i = e * (f + g - h);

3. (a) Explain why we cannot write addi $t0, $zero, 65536 to load the immediate 65,536 into $t0. (b) Write a single lui instruction that loads the immediate 65,536 into $t0.

4. Many processor ISA's have instructions which rotate the bits of a word left or right. During a rotate left operation, bits that would normally be lost during a shift left are instead rotated into the least significant bits. For example, suppose $t0 contains 0x9122_3344 and we rotate $t0 left n bit positions,

$t0 before rotate left:                              1001 0001 0010 0010 0011 0011 0100 0100

$t0 after rotate left 1 bit position:             0010 0010 0100 0100 0110 0110 1000 1001

$t0 before rotate left:                              1001 0001 0010 0010 0011 0011 0100 0100

$t0 after rotate left 7 bit positions:           1001 0001 0001 1001 1010 0010 0100 1000

A rotate right works similarly, except bits that would normally be lost during a shift right are rotated into the most significant bits. MIPS does not have rotate left or rotate right instructions. However, they can be implemented as pseudoinstructions. For this exercise, write the MIPS physical instruction sequence which would implement a pseudo- instruction rotl1 $dst, $src (rotate left by 1) that rotates the bits in $src one position to the left and writes the result to $dst. You are only allowed to use three registers in your code: $src, $dst, and $at; $src shall not be modified. Note, $src and $dst are not real MIPS registers, but rather, are placeholders for the registers that are actually used when writing the rotl1 instruction. For example, if the programmer writes rotl $t0, $t1 then $src is $t1 and $dst is $t0. I'll give you a hint, these are your instructions, which I wrote in this order: srl, sll, or.

5. Write MIPS assembly language code that would define and initialize these variables in the  .data section.

int e = 0 , f = 10, g = -1;
char ch = ' ';
char char_array[128] = { '\0' };
int int_array1[100] = { 0 };
int int_array2[3] = { 1, 2, 3 };

6. Write assembly language instructions-not a complete program-that: (1) loads $t1 with the immediate 0x1C59; (2) loads $t2 with the immediate 0x3687; (3) performs a logical AND of $t1 and $t2 and writes the result to $s0; (4) performs a logical OR of $t1 and $t2 and writes the result to $s1; (5) performs a logical XOR of $t1 and $t2 and writes the result to $s2; (6) performs a logical NOR of $t1 and $t2 and writes the result to $s3.

7. Continuing, for each of the four logical instructions (and, or, xor, and nor) what value would be written to the destination registers? Write your answer as a 8-hexdigit number.

8. Name your source code file hw02-8.s. Write a complete MIPS assembly language program that implements this pseudocode:

Define global integer variables a = 0, b = 0, c = 0 (in the .data section)
Program hw02-6
SysPrintStr("Enter a: ")
a = SysReadInt()
SysPrintStr("Enter b: ")
b = SysReadInt()
3 2
c = 2a + b - 1
SysPrintStr("2a^3 + b^2 - 1 = ")
SysPrintInt(c)
SysExit()
End Program

Miscellaneous program requirements and hints:

a. Write the code so its behavior would match this sample output, where sample user input is in bold:

Enter a: 7
Enter b: -5
2a^3 + b^2 - 1 = 710

b. The information on the MARS system calls can be found by selecting Help | Help on the main menu (or hit F1). In the Help window click on the Syscalls tab. Information on MARS-implemented MIPS32 instructions can be found by clicking on the Basic Instructions and Extended (pseudo) Instructions tabs. Information on MARS- implemented assembler directives can be found by clicking on the Directives tab. For this program you will need to use the following directives: .data for the data section; .text for the text section; .word for the definitions of integer variables a, b, and c; asciiz to place the string literals in the data section.

b. Define a, b, and c as global variables in the .data section using the .word directive. Initialize them to 0.

c. Place the strings in the .data section using the .asciiz directive.

e. For my solution, I used these MIPS32 instructions, so familiarize yourself with them: add (add signed); addi (add immediate signed); la (load address); li (load immediate); lw (load word); mul (multiply); sll (shift logical left,  used to quickly multiply a3 by 2); sw (store word); and syscall (make a system call).

f. Study the assembly language source code files from the course notes and posted on the course website. Format your code in a similar manner, i.e., most assembly language source code lines consist of four columns of text: column 1 is left aligned with the margin and is reserved for an optional label; column 2 is indented and is reserved for instruction mnemonics; column 3 is indented and reserved for optional operands; column four is indented and is reserved for comments. How many spaces or tabs you indent is up to you, the important thing is to line things up in columns and be consistent.

g. You are required to write a comment in column 4 for each instruction. This may seem like busy work, but it can be very helpful when your code does not work and you are trying to figure out why. Trust me on this one.

h. Even though this code could be optimized (e.g., we don't really need to allocate the variables a, b, and c in the data section because we have enough registers to store all of the values) I don't want you to optimize it. What I mean is, when you read the integer value for a, store the value that was entered in the memory location allocated to a. Later, when you need to value of a again, load it from the memory location allocated to a. Perform the same operations for b and c. There is merit in learning how to do something the hard way before seeing how to do it the easy way. Unoptimized, my solution required 32 instructions (38 if we count the actual number of physical instructions that were generated after pseudoinstructions were expanded).

i. Make sure to properly terminate the program by making a syscall to SysExit().

j. Write a header comment block at the top of the source code file in the format shown on the next page. Make sure to put both author's names in the header comment block if you worked with a partner.

Reference no: EM13771646

Questions Cloud

Compute the MACRS depreciation in that year also : A group of investors has formed Trump Corporation to purchase a small hotel. The price is $150,000 for the land and $850,000 for the hotel building. If the purchase takes place in June, compute the MACRS depreciation for the first three calendar year..
What is the price of the combined test : What is the price of the combined test assuming marginal cost pricing - assume that allied wants a contribution margin of $10 per test. What price must be set to achieve this goal?
Mass of test tube and sample before heating : Mass of empty test tube 7.597 gMass of test tube and sample before heating 8.089 gMass of test tube and sample after heating 7.956 g
Explain the benefits of cloud computing at riordan : Explain the Benefits of Cloud Computing at Riordan. A full description of the new system, a description of its components, and the benefit it will provide to Riordan.
Write mips assembly language define and initialize variables : Write a header comment block at the top of the source code file in the format shown on the next page. Make sure to put both author's names in the header comment block if you worked with a partner.
The solvent flows through the membrane : Osmosis and dialysis differ in a. whether the solvent flows through the membrane or not b. the effects of temperature on determining the net flow c. the size and type of particle that can pass through the membrane d. more than one choice is correct
Cost when the dollar value of the rupiah fell : If a pound of U.S. pork cost 40 rupiah in Indonesia before the Asian crisis, how much did it cost when the dollar value of the rupiah fell by 80 percent?
Making earthmoving equipment is considering investment : A profitable company making earthmoving equipment is considering an investment of $150,000 on equipment that will have a 5 year useful life and a $50,000 salvage value. Use a spreadsheet function to compute the MACRS depreciation schedule.
When we look at different economic policies : When we look at different economic policies we see that Keynesian, monetarist and supply-side economics advocate for restraining inflation and reducing unemployment?

Reviews

Write a Review

Assembly Language Questions & Answers

  Create a assembly language subroutine

Create a assembly language subroutine MULSUM that takes an array named A containing n bytes of positive numbers, and fills two arrays, array B containing n words and array C containing n long words

  Write a function in linux assembly

Write a function in Linux assembly

  Analog measurements

Prepare an assembly program for the correctly measures the wind direction

  Design a simple digital clock

Design a simple digital clock

  Write an assembly program

Prepare an Assembly program that reads in a number of cents.

  Write an assembly language program

Write an assembly language program for encrypting alphabates of a string

  Greatest common divisor of integers-masm assembly language

Must be done in MASM assembly language: Greatest common divisor of two integers is largest integer which will evenly divide both integers. GCD algorithm involves integer division in a loop.

  Write assembly program-find right admission price to movie

Write the Assembly program to find correct admission price to movie. Price of admission to a movie is $7 for kids (under 12) and $9 for adults.

  Create simple 8-bit alu using add-subtract-shift functions

Create a simple 8-bit ALU. Requirements:The eight functions that you will implement are: add, subtract, and, or, shift left logical, less than, shift right logical.

  Write assembly program print binary representation-integers

Write the assembly program called hw6_ex1, stored in file hw6_ex1.asm. This program must prompt user to enter signed 32-bit integer. Program must print out binary representation of the integer.

  Allot op-codes and add microcode to microprogram

Allot op-codes and add microcode to microprogram of Mic-1 to implement following instructions which are then included with IJVM instruction set.

  Write mips assembly program to read two non-negative numbers

Write MIPS assembly program to repeatedly read two non-negative integers and print integer product and quotient without using multiplication and division instructions.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd