Computer Systems: A Programmer's Perspective (3rd Edition)
3rd Edition
ISBN: 9780134092669
Author: Bryant, Randal E. Bryant, David R. O'Hallaron, David R., Randal E.; O'Hallaron, Bryant/O'hallaron
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 3, Problem 3.66HW
Program Plan Intro
Given assembly code:
# long sum_col(long n, long A[NR(n)][NC(n)], long j)
# n in %rdi, A in %rsi, j in %rdx
sum_col:
leaq 1(,%rdi,4), %r8
leaq (%rdi,%rdi,2), %rax
movq %rax, %rdi
testq %rax, %rax
jle .L4
salq $3, %r8
leaq (%rsi,%rdx,8), %rcx
movl $0, %eax
movl $0, %edx
.L3:
addq (%rcx), %rax
addq $1, %rdx
addq %r8, %rcx
cmpq %rdi, %rdx
jne .L3
rep
ret
.L4:
movl $0, %eax
ret
Load Effective Address:
- The load effective address instruction “leaq” is a variant of “movq” instruction.
- The instruction form reads memory to a register, but memory is not been referenced at all.
- The first operand of instruction is a memory reference; the effective address is been copied to destination.
- The pointers could be generated for later references of memory.
- The common arithmetic operations could be described compactly using this instruction.
- The operand in destination should be a register.
Data movement instructions:
- The different instructions are been grouped as “instruction classes”.
- The instructions in a class performs same operation but with different sizes of operand.
- The “Mov” class denotes data movement instructions that copy data from a source location to a destination.
- The class has 4 instructions that includes:
- movb:
- It copies data from a source location to a destination.
- It denotes an instruction that operates on 1 byte data size.
- movw:
- It copies data from a source location to a destination.
- It denotes an instruction that operates on 2 bytes data size.
- movl:
- It copies data from a source location to a destination.
- It denotes an instruction that operates on 4 bytes data size.
- movq:
- It copies data from a source location to a destination.
- It denotes an instruction that operates on 8 bytes data size.
- movb:
Comparison Instruction:
- The “CMP” instruction sets condition code according to differences of their two operands.
- The working pattern is same as “SUB” instruction but it sets condition code without updating destinations.
- The zero flag is been set if two operands are equal.
- The ordering relations between operands could be determined using other flags.
- The “cmpl” instruction compares values that are double word.
Unary and Binary Operations:
- The details of unary operations includes:
- The single operand functions as both source as well as destination.
- It can either be a memory location or a register.
- The instruction “incq” causes 8 byte element on stack top to be incremented.
- The instruction “decq” causes 8 byte element on stack top to be decremented.
- The details of binary operations includes:
- The first operand denotes the source.
- The second operand works as both source as well as destination.
- The first operand can either be an immediate value, memory location or register.
- The second operand can either be a register or a memory location.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a c program
Write a program which should consists of a user defined function Task (). Pass 1D array to the function, along with number of elements of array. Find out the maximum element in 1D array using this function.[Note: Array should be passed using by reference approach]
Write, compile, and run a C program that adds equivalent elements of the two-
dimensional arrays named first and second. You must use for loops to implement the
add. Both arrays should have two rows and three columns. For example, element [1][2]
of the resulting array should be the sum of first[1][2] and second[1][2]. The first and
second arrays should be initialized as follows:
first
second
16
18
23
24
52
77
54
91
11
16
19
59
We have discussed two data structures -- arrays and array lists. Both can be used to store multiple data items of the same data type. When writing code, a programmer must decide between these two data structures.
Initial Post: State a situation in which an array would be the preferred data structure and one in which an array list would be the preferred data structure. Give reasoning for each choice.
Chapter 3 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
Ch. 3.4 - Prob. 3.1PPCh. 3.4 - Prob. 3.2PPCh. 3.4 - Prob. 3.3PPCh. 3.4 - Prob. 3.4PPCh. 3.4 - Prob. 3.5PPCh. 3.5 - Prob. 3.6PPCh. 3.5 - Prob. 3.7PPCh. 3.5 - Prob. 3.8PPCh. 3.5 - Prob. 3.9PPCh. 3.5 - Prob. 3.10PP
Ch. 3.5 - Prob. 3.11PPCh. 3.5 - Prob. 3.12PPCh. 3.6 - Prob. 3.13PPCh. 3.6 - Prob. 3.14PPCh. 3.6 - Prob. 3.15PPCh. 3.6 - Prob. 3.16PPCh. 3.6 - Practice Problem 3.17 (solution page 331) An...Ch. 3.6 - Practice Problem 3.18 (solution page 332) Starting...Ch. 3.6 - Prob. 3.19PPCh. 3.6 - Prob. 3.20PPCh. 3.6 - Prob. 3.21PPCh. 3.6 - Prob. 3.22PPCh. 3.6 - Prob. 3.23PPCh. 3.6 - Practice Problem 3.24 (solution page 335) For C...Ch. 3.6 - Prob. 3.25PPCh. 3.6 - Prob. 3.26PPCh. 3.6 - Practice Problem 3.27 (solution page 336) Write...Ch. 3.6 - Prob. 3.28PPCh. 3.6 - Prob. 3.29PPCh. 3.6 - Practice Problem 3.30 (solution page 338) In the C...Ch. 3.6 - Prob. 3.31PPCh. 3.7 - Prob. 3.32PPCh. 3.7 - Prob. 3.33PPCh. 3.7 - Prob. 3.34PPCh. 3.7 - Prob. 3.35PPCh. 3.8 - Prob. 3.36PPCh. 3.8 - Prob. 3.37PPCh. 3.8 - Prob. 3.38PPCh. 3.8 - Prob. 3.39PPCh. 3.8 - Prob. 3.40PPCh. 3.9 - Prob. 3.41PPCh. 3.9 - Prob. 3.42PPCh. 3.9 - Practice Problem 3.43 (solution page 344) Suppose...Ch. 3.9 - Prob. 3.44PPCh. 3.9 - Prob. 3.45PPCh. 3.10 - Prob. 3.46PPCh. 3.10 - Prob. 3.47PPCh. 3.10 - Prob. 3.48PPCh. 3.10 - Prob. 3.49PPCh. 3.11 - Practice Problem 3.50 (solution page 347) For the...Ch. 3.11 - Prob. 3.51PPCh. 3.11 - Prob. 3.52PPCh. 3.11 - Practice Problem 3.52 (solution page 348) For the...Ch. 3.11 - Practice Problem 3.54 (solution page 349) Function...Ch. 3.11 - Prob. 3.55PPCh. 3.11 - Prob. 3.56PPCh. 3.11 - Practice Problem 3.57 (solution page 350) Function...Ch. 3 - For a function with prototype long decoda2(long x,...Ch. 3 - The following code computes the 128-bit product of...Ch. 3 - Prob. 3.60HWCh. 3 - In Section 3.6.6, we examined the following code...Ch. 3 - The code that follows shows an example of...Ch. 3 - This problem will give you a chance to reverb...Ch. 3 - Consider the following source code, where R, S,...Ch. 3 - The following code transposes the elements of an M...Ch. 3 - Prob. 3.66HWCh. 3 - For this exercise, we will examine the code...Ch. 3 - Prob. 3.68HWCh. 3 - Prob. 3.69HWCh. 3 - Consider the following union declaration: This...Ch. 3 - Prob. 3.71HWCh. 3 - Prob. 3.72HWCh. 3 - Prob. 3.73HWCh. 3 - Prob. 3.74HWCh. 3 - Prob. 3.75HW
Knowledge Booster
Similar questions
- C++ and the focus is on Pass by Reference: The following steps are essentially under the same problem but in order to complete a step, the previous must be completed first. For example, Step #3 cannot be completed unless Step #1 and #2 have been conducted. And, Step #4 cannot be performed if the previous three steps have not been solved. Step #1) See the RAND with 5473 Step #2) create an array of 12 integer elements with the values from the rand () that range from 100 to 999. Hint see discussion of random, range and offset. Step #3) create a function that returns the value of the maximum entry Step #4) now create a second function that returns the index of the element that contains the maximum value.arrow_forwardDevelop python program of function random array(m, n) that takes two integers as an argument and returns a 2D m-by-n array with random elements in it. Develop python program of function adder(a1, a2) that reads two 2D arrays of the same size and returns an array that summarizes a1 and a2. To add the two arrays, you need to add their elements correspondingly. Develop a python program of function inverse ray(a) that takes a 2D-array as an argument and inverses the array. You will need to inverse the rows first and then inverse the columns next. For instance, if the array = [[2, 3, 4], [5, 6, 7]], the inverse will be = [[7, 6, 5], [4, 3, 2]]arrow_forwardUse the PEP/8 assembely machine language simulator to write a program that simulates the PEP/8 computer and instruction set for only the following instructions (the following instructions are in the image attached) Here are some specifics. 1.Use an array to represent the memory. 2.Use variables or arrays for the PEP8 registers. I recommend putting it all into a structure. I also recommend using an array of 16 bit values for A, X, PC, SP so that you can use the r bit from the instructions to point directly to A or X. You do NOT have to include the Status bits.arrow_forward
- Write a C++ program which performs the following tasks: a) Initialize an integer array of 10 elements in main( ) b) Pass the entire array to a function modify( ) c) In modify( ) multiply each element of array by 3 d) And display each element of arrayarrow_forwardWrite a C++ program which performs the following tasks:a) Initialize an integer array of 10 elements in main( )b) Pass the entire array to a function Multiple( )c) In Multiple( ) multiply each element of array by 5d) And display each element of arrayarrow_forward1. write a C program that will do the following : • Ask the user to enter the number of rows and the number of columns for that array • Create an integer type 2D array with the number of rows and columns requested by the user • Ask the user to enter the elements of that array • Using a user defined function, print the array elements • Print Jessica and sarah in the black console. Q X clang-7 -pthread -lm -o main main.c > ./main Omar Tbeileh enter the number of rows : 2 enter the number of columns : 3 enter the value of the element Ar[0] [0] = 5 enter the value of the element Ar[0] [1] = 6 enter the value of the element Ar[0] [2] = 9 enter the value of the element Ar[1] [0] = 33 enter the value of the element Ar[1] [1] = 22 enter the value of the element Ar[1] [2] = 11 the value of Ar[0] [0] = 5 the value of Ar[0] [1] = 6 the value of Ar[0] [2] = 9 the value of Ar[1] [0] = 33 the value of Ar[1] [1] = 22 the value of Ar[1] [2] 11 > |arrow_forward
- In this Assignment you need to design, analyze and implement an algorithm to print the elements that appear in both arrays in sorted order. Write a C/Java program to read two arrays of N int values, and print all elements that appear in both arrays in a sorted order. You need to calculate the execution time for your algorithm when the input data is randomly created and when the input data is sorted in ascending order. Your program should implement the following operations: Randomly initialize n int values starting from 0 and store them in array inputData(int X[], int n) Call this function to initialize the values of 2 arrays. Initialize n int values starting from 0 in an ascending order and store these values in array X. inputData(int X[], int n, int increment) Call this function two times to initialize the values of 2 arrays sorted in ascending order with different increment. For example, if the increment value is equal to 5 the values of…arrow_forwardWrite a code in C++ and create a two dimensional Array of size 5 X 5.(1) Inserting the following numbers.(2) Create a dynamic 2-dimensional array of size 5 X 5;(3) After inserting all numbers, display sum and average of all numbers of Array? 465 8 47 93 786 97 26 78 1327 34 77 47 5692 68 34 68 7773 69 37 78 87arrow_forwardIn this Assignment you need to design, analyze and implement an algorithm to print the elements that appear in both arrays in sorted order. Write a C/Java program to read two arrays of N int values, and print all elements that appear in both arrays in a sorted order. You need to calculate the execution time for your algorithm when the input data is randomly created and when the input data is sorted in ascending order. Your program should implement the following operations: Randomly initialize n int values starting from 0 and store them in array inputData(int X[], int n) Call this function to initialize the values of 2 arrays. Initialize n int values starting from 0 in an ascending order and store these values in array X. inputData(int X[], int n, int increment) Call this function two times to initialize the values of 2 arrays sorted in ascending order with different increment. For example, if the increment value is equal to 5 the values of…arrow_forward
- Write a program in C++ to find the transpose of a 3x3 matrix input by the user, store it in another array and display it. instructions: 1.avoid void function in the program. 2. use int function. 3. avoid copy-pasting and plagiarism 4. write a self-written code 5. give comments with each step. 6. write code with easy and basic steps as I am just a student.arrow_forward• For the following algorithm, explain what it computes, state what the input size for analysis is, state what basic operations should be counted for analyzing it, state exactly how many operations are executed as a function of the input size, and state the efficiency class or classes to which it belongs. The built-in C++ swap function is extremely efficient, and you should count it as performing exactly two basic operations. 01 void foo(vector& array) 02 { size_t size = array.size(); for (size_t pass_indx = 0; pass_indx < size - 1; pass_indx++) { size_t min_position = pass_indx; for (size_t compare_indx = pass_indx + 1; compare_indx < size; compare_indx++) { if (array.at (compare_indx) < array.at(min_position)) { min_position = compare_indx; } } 03 04 05 06 07 08 09 10 11 12 13 14 15 16 if (min_position !- pass_indx) 17 swap (array.at(pass_indx), array.at (min_position)); 18 19 } 21 } 20arrow_forwardIn C++, Can you please look at the code below and revise/fix so it will work according to instructions and criteria. Instruction 1) Write a function that copies a 1D array to a 2D array. The function’s prototype is bool copy1DTo2D(int d1[], int size, int d2[][NCOLS], int nrows); where size > 0 NCOLS > 0 nrows > 0 NCOLS is a global constant size = NCOLS * nrows the function returns true if the parameters and constants satisfy these conditions and false otherwise. the relation between 1d array indices and 2d array indices is 2d row index = 1d array index / NCOLS 2d column index = 1d array index modulus operator NCOLS 2) Write a function that copies a 2D array to a 1D array. The function’s prototype is bool copy2DTo1D(int d2[][NCOLS, int nrows, int d1[], int size); where size > 0 NCOLS > 0 nrows > 0 NCOLS is a global constant the function return true if the parameters and constants satisfy these conditions and false otherwise. the relation between 1d array indices and…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