EBK COMPUTER SYSTEMS
3rd Edition
ISBN: 8220101459107
Author: O'HALLARON
Publisher: YUZU
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 3.6, Problem 3.25PP
Explanation of Solution
Given assembly code:
a in %rdi, b in %rsi
loop_while2:
testq %rsi, %rsi
jle .L8
movq %rsi, %rax
.L7:
imulq %rdi, %rax
subq %rdi, %rsi
testq %rsi, %rsi
jg .L7
rep; ret
.L8:
movq %rsi, %rax
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...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Problem (5)
Consider the code in main() below. Write code (in C++) to
close as many memory leaks as possible. If there is still some memory leaking, describe
why you cannot take care of it.
int** pp;
int* p1, p2;
int x = 2;
p2=new int;
pp=new int*;
*pp = p2;
= new int;
%3D
p2
**pp =
p1
*p2;
*pp;
p2 = new int;
Complete problem 6.19a. Only provide the Pep/9 program file and code. Don't provided the C program. //C code for 6.19a#include <stdio.h>char myChar;char toLower(char ch) { if ((ch >= ’A’) && (ch <= ’Z’)) { return ch + ’a’ - ’A’; } else { return ch; }}int main () { scanf(”%c”, &myChar); printf(”%c\n”, toLower(myChar)); return 0;}
Sea t (k) a function that denotes the number of times that the instruction sum + = i + j will be executed in the code that follows. k is assumed to be a positive integer.
Find the exact formula for t (k). Find a simple function A (k) such that t (k) = Θ (A (k)). Justify the answer with the corresponding theorems. (Note: you are not asking what the value is end of the sum variable)
Chapter 3 Solutions
EBK COMPUTER SYSTEMS
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
- Practice Exercise: Create a simple C++ Program using the instructions below.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_forwardSolve the problem using C++ (Evaluate expression) Modify Listing 12.12 EvaluateExpression.cpp to add operators ^ for exponent and % for modulus. For example, 3 ^ 2 is 9 and 3 % 2 is 1. The ^ operator has the highest precedence and the % operator has the same precedence as the * and / operators. Sample Run Enter an expression: (5 * 2 ^ 3 + 2 * 3 % 2) * 4 (5 * 2 ^ 3 + 2 * 3 % 2) * 4 = 160arrow_forward
- 3. (15 pts.) Consider the following fragment of C code: for (i=0; i<=100; i=i+1) a [i] = b[i] + c; Assume that a and b are arrays of words and that the base address of a is in $a0 and the base address of b is in $a1. Register $t0 is associated with variable I and register $50 with the value of c. You may also assume that any address constants you need are available to be loaded from memory. (1) (10 pts.) Write the code for MIPS. (2) (5 pts.) How many instructions are executed during the running of this code if there are no array out-of-bounds exceptions thrown? (3) How many memory data references will be made during execution?arrow_forward#include using namespace std; int main() { int type; double Vth, Vg, Vd, Vs; cin>>type>>Vth>>Vg>>Vd>>Vs; return 0; }arrow_forward#include using namespace std; int main() { int type; double Vth, Vg, Vd, Vs; cin>>type>>Vth>>Vg>>Vd>>Vs; return 0; }arrow_forward
- Translate the following C++ program into MAL (MIPS Assembly Langage). Your solution should have all necessary data allocations, input/output instructions etc, and must compile and run correctly in spim. Make sure your loops are efficient (i.e., they should not have unnecessary branches). Given: max is in $s0, num is in $s1, i is in $s2. (These variables should not be allocated in the .data section.) You may use any other $s? or $t? registers as temporaries. #include using std::cin; using std::cout; int main() { int max, num, i;arrow_forwardC++ I need simple solution for this example in 20 minutesarrow_forwardUsing C++ programmingarrow_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