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
Expert Solution & Answer
Chapter 3.7, Problem 3.35PP
A.
Explanation of Solution
Given assembly code:
x in %rdi
rfun:
pushq %rbx
movq %rdi, %rbx
movl $0, %eax
testq %rdi, %rdi
je .L2
shrq $2, %rdi
call rfun
addq %rbx, %rax
.L2:
popq %rbx
ret
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:
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...
B.
Explanation of Solution
Corresponding C code:
// Define method rfun
long rfun(unsigned long x)
{
//If x equals 0
if(x==0)
//Return 0
return 0;
//Assign value after right shit
unsigned long nx = x>>2;
//Call method
long rv = rfun(nx);
//Return value
return x+rv;
}
Explanation:
- The register “%rdi” stores value of “x”.
- The instruction “pushq” stores the data.
- The instruction “movq %rdi, %rbx” saves value of register “%rdi” on “%rbx”.
- The instruction “movl $0, %eax” saves 0 in variable “%eax”.
- The instruction “testq %rdi, %rdi” checks whether value in register “%rdi” is zero.
- The statement “if(x==0)” is corresponding to C statement...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
####### in python ##########
Calculate the approximate solution of the
system of equations.
xy = (z^2)+1
xyz + y^2=(x^2)+2
(e^x)+z=(e^y)+3
Stop conditions - a norm of the function
value (||x|| infinty) less than - 1.10^-6
The code will print to the screen the
solution in each iteration and the norm of
the function values.
1. A. Convert the following C code into AT&T assembly:
x at 8(%ebp)
if (x>5){
X++;
}
else {
X--;
}
while (x<10){
x++;
}
B. Annotate each line of the assembly code to describe how it operates.
C. Write a goto version of the function (in C) that mimics how the assembly code program
operates.
PROBLEM 21 - 0517:
Write a subroutine which computes
the roots of the quadratic
equation a,x2 + a,x + a, = 0
according to the quadratic
formula:
X12 = (-az/2a,) + V[(a,/2a,)2 –
(a,/a,))
(= [{a,
+ v(a?, - 4a,a,)} / 2a,])
(START
SUBROUTINE QUAD
COMPUTE, DISCRIMINANT
(DISC)
DISC
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++ I need simple solution for this example in 20 minutesarrow_forwardC++ (clear answer) Consider the following function main: ... const int N_COLS = 4; int main() { const int N = 20; const int N_ROWS = 10; int alpha[N]; int beta[N]; int matrix[N_ROWS][N_COLS]; ... return 0; } Write a C++ program that tests the function main and the functions discussed in parts 1 through 5. (Add additional functions, such as printing a two-dimensional array, as needed.) Write the definition of the function doubleAlpha that takes two integer arrays and its size as parameters (Hint: both arrays have the same size). Initializes the elements of beta to two times the corresponding elements in alpha. Make sure that you prevent the function from modifying the elements of alpha.arrow_forward(4) [8]Write code for a function multBy3divBy4, that for argument int x, computes 3*x/4, but follows the bit-level integer coding rules (text p.128) like in problem 3 of the assignment 1. (you may assume ints are 32 bits). (Note: The operation in your code 3*x is allowed to cause overflow.)arrow_forward
- Using C++ programmingarrow_forwardProblem 10 void fun (void) { Consider the following C program. int a, b, c; //definition 1 while (. .) { int b, c, d; //definition 2 For each of the four marked points 1 in this function, list each visible ... while (. . .) { variable, along with the number of int c, d, e; //definition 3 2 the definition statement that } defines it. 3 } 4arrow_forwardProblem 1.10: Simplify F(A, B,C, D) = ACD+ A'B + D'arrow_forward
- (1) A function with prototype long decode (long x, long y, long z); Has the following assembly code from gcc (Note that the line numbers in the first column have no functional value, but are supplied to help): 1. decode: subą %rdi, % rsi imulq %rsi, movq %rsi, salq $63, $63, 2. 3. %rdi 4. %rax 5. %rax %rax %rax 6. sarq 7. xorq %rdi, 8. ret (a) Annotate the assembly code. (b) Hence write C code for decode that has the equivalent effect to the assembly code.arrow_forwardQUESTION 2 Develop a C++ program to calculate integration of the non-linear equations You need to consider the following requirements: a. Lets f(x) = ax^2 +bx +c is a non-linear equation. Your program should be able to get input from user (any value of a, b and c) b. Find the integration of the equation. c. Ask the user to enter upper limit and lower limits. d. Calculate the area between the curve in question a) and the x-axis within the upper and lower limit. Find the x-intercept. If the x-intercept is in between the upper and lower limits, you have to consider positive and negative area as what you have learnt in the class. e. Display the output in question b, c, d.arrow_forwarduse c++.arrow_forward
- 2. C++ Implement a function for integrating a function by means of Riemann sums. Use the formula Write a function that returns the numerical derivative of a given function fat a given point x. using a given tolerance h. Use the formula Yx+h) -f(x-h) f(x) = %3D 2harrow_forwardH.W 2: Using: 1) 32 - to - 1 MUX 2) 16- to - 1 MUX 3) 4- to -1 MUX 4) 2- to - 1 MUX To realize the following function F= 2.3.7,9,13.14,19,20,22,25,27,29,30,31)arrow_forwardUSING MATLAB 2.10arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr