Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
expand_more
expand_more
format_list_bulleted
Question
Chapter 17.2, Problem 3E
Program Plan Intro
To show the implementation of a counter as an array of sequence so that INCREMENT and RESET operations take
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Assume (hypothetically) that there is a version of QtSpim that simulates a 4-core processor. Write a MIPS Assembly program that would take advantage of the 4 cores to speed up the execution of mathematical calculations. Specifically, write a program that receives as input two arrays of equal length, and replaces the content of each element in Array 1 with the sum of the corresponding elements in Array 1 and 2.
This problem is adapted from an earlier edition of P&H, and should be submitted.Consider the following code used to implement a new instruction: foo $t3,$t1,$t2:mask : . word 0xFFFFF83Fs t a r t : l a $t0 , masklw $t0 , 0 ( $ t 0 )l a $t3 , s h f t rlw $t3 , 0 ( $ t 3 )and $t3 , $t3 , $ t 0a ndi $t2 , $t2 , 0 x 0 0 1 fs l l $t2 , $t2 , 6o r $t3 , $t3 , $ t 2l a $t5 , s h f t rsw $t3 , 0 ( $ t 5 )s h f t r : s l l $t3 , $t1 , 0Add meaningful comments to the code and write a brief (2 sentence max) description of what foo does. Thisis not the same as saying how it does it - e.g., when asked to describe what a pedestrian is doing, you wouldsay they are walking, not that they are ilfting their left leg, angling it forward, putting it down, . . ..State at least one reason why writing “self-modifying code” such as this is a bad idea (and often times notactually allowed by the operating system)?
For each of the following two code segments, decide whether it is suitable for parallel execution and response according to your justification: add OpenMP pragmas to make the loop parallel or briefly explain why the code segment is not suitable for parallel execution.
(A): for ( i = 0; i < n; i++ ) {
x [ i ] = 3 * i + 5;
y [ i ] = log ( x [ i ] );
}
(B): x [ 0 ] = 1;
x [ 1 ] = 2;
for ( i = 2; i < n; i++ )
x [ i ] = x [ i – 1 ] * x [ i – 2 ] ;
Knowledge Booster
Similar questions
- Write pseudo code for it & what conditions) what else should change in Semigroup computation on a PRAM algorithm? to avoid the final broadcasting phase which essentially doubles the execution time of the semigroup computation algorithm in the EREW PRAM, it has been suggested that we replace the indices j + s in the algorithm with j + s mod p (i.e., allow the computations to wrap around). And under what conditions would this method yield correct results in all processors? (Write pseudo code for it)arrow_forwardWrite a subroutine of the ARM assembler that returns to register R0 the difference between the number of non-negative and negative elements of an array of words with a starting address and the number of words in registers R1 and R0, respectively.arrow_forwardIn this exercise we compare the performance of 1-issue and 2-issue processors, taking into account program transformations that can be made to optimize for 2-issue execution. Problems in this exercise refer to the following loop(written in C):for(i=0;i!=j;i+=2)b[i]=a[i]–a[i+1];When writing MIPS code, assume that variables are kept in registers as follows, and that all registers except those indicated as Free are used to keep various variables, so they cannot be used for anything else. i j a b c Free R5 R6 R1 R2 R3 R10,R11,R12 Translate this C code into MIPS instructions. Your translation should be direct, without rearranging instructions to achieve better performance.arrow_forward
- What the code below does? Consider the following code used to implement a new instruction: foo $t3,$t1,$t2: mask : . word 0xFFFFF83Fstart : la $t0 , masklw $t0 , 0 ( $ t 0 )la $t3 , s h f t rlw $t3 , 0 ( $ t 3 )and $t3 , $t3 , $ t 0andi $t2 , $t2 , 0 x 0 0 1 fsll $t2 , $t2 , 6or $t3 , $t3 , $ t 2la $t5 , s h f t rsw $t3 , 0 ( $ t 5 ) shftr: sll $t3 , $t1 , 0 What does foo does?arrow_forwardImplement integer division in MIPS assembly via rounding rather than truncating. Divide the remainder of the division by the first divisor to achieve this. If the final quotient is more than or equal to one, multiply it by one. Otherwise, leave the starting quotient alone.arrow_forwardWrite an ARM assembly program to check whether an N x N matrix is a magic square. A magic square is an N x N matrix in which the sums of all rows, columns, and the two diagonals add up to N(N + 1)/2. All matrix entries are unique numbers from 1 to N. If the matrix is a magic square, register RO will be set (i.e. all ones) upon completion; otherwise it will be cleared. Test the following matrix 16 5 9 4 3 10 6 15 2 11 7 14 13 8 12 1 Store the matrix element numbers in memory starting at location 0x20004000. Assume all numbers are Bytesarrow_forward
- What the code below does? Consider the following code used to implement a new instruction: foo $t3,$t1,$t2: mask : . word 0xFFFFF83Fs t a r t : l a $t0 , masklw $t0 , 0 ( $ t 0 )l a $t3 , s h f t rlw $t3 , 0 ( $ t 3 )and $t3 , $t3 , $ t 0a ndi $t2 , $t2 , 0 x 0 0 1 fs l l $t2 , $t2 , 6o r $t3 , $t3 , $ t 2l a $t5 , s h f t rsw $t3 , 0 ( $ t 5 )s h f t r : s l l $t3 , $t1 , 0 What does foo does?arrow_forwardThe array sum function below is called on an array of length four starting at address B. List, in order, the data addresses referenced by this function during execution. add1: add $v0, $0, $0beq1: beq $a1, $0, jr1addi1: addiu $a1, $a1, -1lw1: lw $t0, 0($a0)add2: add $v0, $v0, $t0addi2: addiu $a0, $a0, 4beq2: beq $0, $0, beq1jr1: jr $raarrow_forwardWrite a program in PLP assembly that repeatedly reads the value of the switches (address: 0xf0100000) and displays a pattern on the LED array based on what switches. Each time the switch value is read, the pattern should be displayed (regardless of whether the switch value has changed or not since the last time it was read). The table below indicates the pattern that should be displayed for each possible switch setting. - please use"sw" "li", labels, loops, "beq" and "lw" to create the code. The code is for assambly language and it will be compiled and run on PLPTool version 5.2. I have created the following code it is not completed it. I seem to be stuck here. Please complete it, following the task instructions. # main source file .org 0x10000000 _start: # Initialization li $t0,0xf0100000 # Load address of switches li $t1,0xf0200000 # Load address of LEDs li $t5,1 # Load value of switch 0 address of LEDs li $t6,2 # Load value of switch 1 address of LEDs…arrow_forward
- Write a assembly code for 8086/8088 that replace the contents of each cell with the sum of the contents of all the cells in the original array from the left end to the cell in question. Thus, for example, if the array passed to the function looks like this: 5 2 9 3 7 then when the function returns, the array will have been changed so that it looks like this: 5 7 16 19 26arrow_forwardFor the (pseudo) assembly code below, replace X, Y, P, and Q with thesmallest set of instructions to save/restore values on the stack and update the stackpointer. Assume that procA and procB were written independently by two differentprogrammers who are following the MIPS guidelines for caller-saved and callee-savedregisters. In other words, the two programmers agree on the input arguments andreturn value of procB, but they can't see the code written by the other person. procA:$s0 = ...$s1 = ...$s2 = ...$t0 = ...$t1 = ...$t2 = ...X$a0 = ...$a1 = ...jal procBY... = $s1... = $t0... = $t1... = $a0jr $raprocB:P... = $a0... = $a1$s2 = ...$t0 = ...Qjr $raarrow_forward15. Consider the following Java-like code: int number = <<read number from user>>; int mask = MASK; int result = number OP mask; if (result != 0) { print("Bit 8 was set"); } The above code is supposed to print “Bit 8 was set” if bit 8 of user’s number was set to 1. If bit 8 was not set, then this code should not print anything (result==0). What hexadecimal value should MASK be, and what bit-wise operation should OP be, for the above code to work correctly?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education