Question

In: Computer Science

Suppose the target assembly language for a compiler has these five instructions for integers: load address,...

Suppose the target assembly language for a compiler has these five instructions for integers:

load address, reg

add reg, reg, reg

sub reg, reg, reg

mul reg, reg, reg

store reg, address

In these instructions, an address is the name of a static variable (whose actual address will be filled in by the loader). A reg is the name of an integer register,
a special extra-fast memory location inside the processor. The target assembly language has three integer registers: r1, r2, and r3. The load instruction loads
the integer from the given memory address into the given register. The add instruc- tion adds the second register to the first register and places the result in the third register. The sub instruction subtracts the second register from the first register and places the result in the third register. The mul instruction multiplies the first register by the second register and places the result in the third register. The store instruction stores the integer from the given register at the given memory ad- dress. So, for example, the compiler might translate the assignment result := offset+(width*n)

into this:

load width,r1

load n,r2

mul r1,r2,r1

load offset,r2

add r2,r1,r1

store r1,result

a.) net : = gross - costs

b.) volume : = (length * width) * height

c.) cube : = (x * x) * x

d.) final : = ((a - abase) * (b - bbase)) * (c - cbase)

Solutions

Expert Solution

1.

load       gross,r1 ; Initialize the gross

load         costs,r2 ; initialize the costs

sub          r1,r2,r1 ; subtract the numbers and store it in r1

store        r1, net

2.

load       length,r1 ; Initialize the length

load         width,r2 ; initialize the width

mul           r1,r2, r1 ;multiply r1 and r2 and store the result in r1

load     height, r2 ; load height in r2

mul      r1, r2, r1; store the result of r1*r2 into r1

store r1, volume; store the final result in volume

3.

Load x,r1 ; initialize the length of cube

Load x,r2 ;

Mul r1,r2,r1; multiplies the number and stores the result in r1

Mul r1,r2,r1 ; multiplies the number again and stores the result in r1

Store r1, cube

4.

Load r1, a

Load r2, abase

Sub r1, r2,r1

Load r2, b

Load r3, bbase

Sub r2, r3, r2

Mul r1, r2, r1

Load r2,c

Load r3,cbase

Sub r2,r3,r2

Mul r1,r2,r1

Store r1, final


Related Solutions

1. Convert the machine language instructions into assembly language instructions: 7976C1 06
1. Convert the machine language instructions into assembly language instructions: 7976C1 06
Write a sequence of assembly language instructions to subtract each entry of an array A of...
Write a sequence of assembly language instructions to subtract each entry of an array A of five two’s complement 16-bit binary integers from the corresponding entry of an array B of five two’s complement 16-bit binary integers and construct a third array C of two’s complement 16-bit binary integers. i.e. C[i] = A[i] - B[i]. Use the following data for the arrays A and B. A: 10, -15, 20, 4, -5 B: 25, -5, -30, 6, 10 please answer in...
Use MIPS assembly language program to swap two of the integers in an integer array. The...
Use MIPS assembly language program to swap two of the integers in an integer array. The program should include the Swap function to swap the integers and the main function to call the Swap function. The main function should: • Pass the starting address of the array in $a0. • Pass the indices of the two elements to swap in $a1 and $a2. • Preserve (i.e. push onto the stack) any T registers that it uses. • Call the Swap...
Write a mips assembly language program to ask the user to enter two integers A and...
Write a mips assembly language program to ask the user to enter two integers A and B and then display the result of computing the expression: A + 2B - 5.
Write a RARS assembly language program to solve the following: For a set of integers stored...
Write a RARS assembly language program to solve the following: For a set of integers stored in an array, calculate the sum of the positive numbers and the sum of the negative numbers, storing the results into memory. In the data segment of the program, define an array consisting of 25 integers (words) that are a mix of positive and negative values. You can select any values you wish but try to create a balance of positive and negative numbers....
Must use AT&T x64/GNU Assembly syntax. Write an assembly language program that reads in two integers,...
Must use AT&T x64/GNU Assembly syntax. Write an assembly language program that reads in two integers, A and B, and uses them to compute the following expressions. You must use the same values for A and B throughout all three expressions. 1) A * 5 2) (A + B) - (A / B) 3) (A - B) + (A * B)
For the PIC16F887, using the execution delay of instructions, write assembly language commands to implement a...
For the PIC16F887, using the execution delay of instructions, write assembly language commands to implement a delay of 3 seconds
Write a possible assembly language instruction or set of instructions to accomplish the following: a) Compare...
Write a possible assembly language instruction or set of instructions to accomplish the following: a) Compare the byte stored at the memory location pointed to by register R4 to the upper (higher) byte stored in register R5 b) Branch to instruction at label ‘ZERO’ if the lower byte of register R6 is zero c) Jump to the instruction at label ‘EVEN’ if the value in register R7 is an even number
1. Write an assembly language program that prompts the user for and reads four integers (x1,...
1. Write an assembly language program that prompts the user for and reads four integers (x1, y1, x2, y2) which represent the coordinates of two points. Make sure you keep track of which number is which. 2. Treat the line between the points as the radius of a sphere and compute the surface area of the sphere. Print the output with a label, such as “The surface area of the sphere is: …”. Hint: The distance between the points is...
Assignment Description: Write a MIPS assembly language program that adds the following two integers and displays...
Assignment Description: Write a MIPS assembly language program that adds the following two integers and displays the sum and the difference. In the .data section, define two variables num1 and num2 both words. Initialize num1 to 92413 10 and num2 to D4B 16 (use 0xD4B to initialize, Note that D4B is a hexadecimal number). Your main procedure/function should load the values of num1 and num2 into two temporary registers, and display them on the console window. Then add the values...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT