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 2.1, Problem 4E
Program Plan Intro
To state the problem formally and also write the pseudo code for adding two integers.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
I could use some help converting this problem into code for IA32 x86 Assembly
floatIsEqual - Compute f == g for floating point arguments f and g. Both the arguments are passed as unsigned int's, but they are to be interpreted as the bit-level representations of single-precision floating point values. If either argument is NaN, return 0 +0 and -0 are considered equal.
translate the following MIPS code to C. Assume that the variables i, j, and k areassigned to the registers $s0, $s1, and $s2, respectively. Assume that the baseaddress of the array A is in registers $s6.Loop: blt $s0, $s1, Exitbge $s1, $s2, Exitaddi $s1, $s1, 5j LoopExit:addi $t0, $zero, 4ble $s0, $t0, Donesll $t1, $s0, 2add $t2, $s6, $t1sw $zero, 0($t2)Done:
Translate the following MIPS code to C. Assume that the variables f, g, h, i, and jare assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively. Assume that the baseaddress of the arrays A and B are in registers $s6 and $s7, respectively and that A and B are arrays of words.
addi $t0, $s6, 4lw $t0, 0($t0)add $t0, $t0, $t0sw $t0, 0($s6)
Chapter 2 Solutions
Introduction to Algorithms
Knowledge Booster
Similar questions
- a. Translate with a three-address statement, the following expression: n = f((x+2), y) – 5; b. If A is an array of integers with width = 4; Translate with three-address statement, the following expression: x = a[i] + 2;arrow_forwardWrite a C program to accept the user input (a positive integer) n, which represents thesize (or length) of an int array. Allocate the memory for this array according to n, andfurther initialise this array (from the first element to the last) using the number from n to1. You will need to consider the (potential) memory management issue.arrow_forwardPlease C-progra Given: Two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array and return the sorted array as a new array. The number of elements initialized in nums1 and nums2 are m and n respectively. Example 1: Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3 Output: [1,2,2,3,5,6]arrow_forward
- Q) Write a program in assembly language to compares the elements of two arrays, A(1) and B(1), each array contains 100 16-bit signed number. Assume that the arrays start in the current data segment at offset addresses A000H and B000H respectively. If the two arrays are found to be unequal, save the address of the first unequal element of A(1) in the memory location with offset F00011. Otherwise, if the two arrays are found to be equal, write all O's into this location.arrow_forwardShow the content of the individual bytes allocated in memory in hexadecimal for the following declarations. Assuming that the address of I is 404000h, what are the addresses of J, K, and L? What is the total number of allocated bytes?arrow_forwardWrite a function in MIPS assembly that copy the value of the 8th element of a word array to the 5th element. The starting address of the array is in $s0. Note thatthe index of the array starts with 0; i.e., the index of the 1st element in the array is 0. Please only modify $t0 in the code you write.arrow_forward
- Translate the following LEGv8 code to C. Assume that the variables f, g, h, i, and j are assigned to registers X0, X1, X2, X3, and X4, respectively. Assume that the base address of the arrays A and B are in registers X6 and X7, respectively. ADDI X9, X6, #8 ADD X10, X6, XZR STUR X10, [X9, #0] LDUR X9, [X9, #0] ADD X0, X9, X10arrow_forwardWriting CODE in Masm615: Write a program to define an array consists of 3 signed elements of 16 bit each. Initialize it to any values . - Swap the first element with the third one. Print your array after swapping - Find the average of the array. Print your result and remainder in decimal format.arrow_forwardQ1: Write C++ program, to input elements of matrix 8 x 6 then find (search) X value in matrix, and print the index of its location. Q2: Write C++ program, to input elements of 1D-array that size [16] and convert it into 2D-array that size of [4] [4] then print the resulted matrix. Q3: Write C++ program, to input elements of matrix 6 x 5 and convert it into 1D-array then print the resulted array. Q4: Write C++ program, to input the degrees of 50 students each has 7 degrees and store all degrees in matrix, then find the average of each student and store averages in 1D- array and print the resulted array.arrow_forward
- Write a program that will: a. Create an array of bytes containing the values: 12h, 34h, 56h, 78h, 9Ah, BCh, DEh, F0h b. Loop over the array and compute the sum in the EAX register. Note: the array contains bytes and you convert the bytes in the array to a 32-bit value before performing the sum. c. Show the contents of the EAX and ECX register at each iteration of the loop.arrow_forwardA=[ 1,2,6,7,8,3,2,1,9 ] and B=[ 3,5,6,4,8 ] Sequences A and B are given. Write C ++ code that transfers and writes numbers that are in Array A and not in Array B to Array C.arrow_forwardwrite your own MIPS program that allocates space for two integer arrays (P and Q) of size 9 each. You can use pointers or indices for traversing arrays. The program should do the following:a. Read in the value of N (a digit between 1 and 9, the actual working size of your array).b. Read in from the keyboard the first N values of the array P. Note that we want both arrays P and Q to haveidentical elements (see the example below for additional explanation).c. Output to the console the N values of both arrays P and Q (use any format and additional text you like).Textbook i use is "Computer Organization and Design 4th Edition by John L hennesyExample: let’s say that the digit read from the keyboard was 3. This means that N=3; them our program will initialise two arrays with elements P[0], P[1], P[2] and Q[0], Q[1], Q[2]. Elements of the arrays are to be read from the keyboard, let’s assume that they were: 25, 11 and 2. The arrays are to be initialised as following:Q[0]=25 Q[1]=11 Q[2]=…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