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, Problem 3.60HW
A.
Explanation of Solution
Registers for holding values:
- The parameter “x” is been passed to function in register “%rdi”.
- The parameter “n” is been passed to function in register “%esi”.
- The register “%rax” is initialized to variable “result”...
B.
Explanation of Solution
Initial values of result and mask:
- The instruction “movl $1, %edx” sets value of “mask” to 1...
C.
Explanation of Solution
Test condition for mask:
- The instruction “testq %rdx, %rdx” denotes test condition for “mask”...
D.
Explanation of Solution
Condition to update mask:
- The instruction “salq %cl, %rdx” performs left shift on “mask”...
E.
Explanation of Solution
Condition to update result:
- The instruction “orq %r8, %rax” performs “OR” operation on “result”...
F.
Explanation of Solution
Given assembly code:
long loop(long x, int n)
x in %rdi, n in %esi
loop:
movl %esi, %ecx
movl $1, %edx
movl $0, %eax
jmp .L2
.L3:
movq %rdi, %r8
andq %rdx, %r8
orq %r8, %rax
`salq %cl, %rdx
.L2:
testq %rdx, %rdx
jne .L3
Rep; 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
It is the compiler's job to associate program variables with registers. Take, for
instance, the assignment statement from our earlier example:
f = (g + h)
(i+j):
The variables f, g, h, i, and j are assigned to the registers X 19, X20, X21, X22,
and X 23, respectively. What is the compiled LEGV8 code?
MIPS Simulator QtSpim: You are to have a complete program in MIPS assembly language that behaves exactly as the included C program. This program contains four functions in addition to the main() one. Your solution must contain all five C routines as they have been coded in the example. Make sure to run the program in MIPS and show the same output on MIPS as well to make sure there are no errors. Below is the five C routines and attached is the image of what the output must print out on QtSpim.
#include <stdio.h>
int getMax(int arr[], int n){int mx = arr[0];for (int i = 1; i < n; i++)if (arr[i] > mx)mx = arr[i];return mx;}void countSort(int arr[], int n, int exp){int output[n];int i, count[10] = { 0 };for (i = 0; i < n; i++)count[(arr[i] / exp) % 10]++;for (i = 1; i < 10; i++)count[i] += count[i - 1];for (i = n - 1; i >= 0; i--) {output[count[(arr[i] / exp) % 10] - 1] = arr[i];count[(arr[i] / exp) % 10]--;}for (i = 0; i < n; i++)arr[i] = output[i];}void…
MIPS Simulator QtSpim: You are to have a complete program in MIPS assembly language that behaves exactly as the included C program. This program contains four functions in addition to the main() one. Your solution must contain all five C routines as they have been coded in the example. Make sure to run the program in MIPS and show the same output on MIPS as well to make sure there are no errors. Below is the five C routines and attached is the image of what the output must print out on QtSpim.
#include <stdio.h>
int getMax(int arr[], int n){int mx = arr[0];for (int i = 1; i < n; i++)if (arr[i] > mx)mx = arr[i];return mx;}void countSort(int arr[], int n, int exp){int output[n];int i, count[10] = { 0 };for (i = 0; i < n; i++)count[(arr[i] / exp) % 10]++;for (i = 1; i < 10; i++)count[i] += count[i - 1];for (i = n - 1; i >= 0; i--) {output[count[(arr[i] / exp) % 10] - 1] = arr[i];count[(arr[i] / exp) % 10]--;}for (i = 0; i < n; i++)arr[i] = output[i];}void…
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
- This is a program that needs to be written in AssemblyGOAL: Write a PEP/8 machine language simulator 1. Use an array to represent the memory. 2. Use variables or arrays for the PEP8 registers. I recommendputting it all into a structure. I also recommend using an array of16 bit values for A, X, PC, SP so that you can use the r bit fromthe instructions to point directly to A or X. You do NOThave toinclude the Status bits. 3. Use unions of structures to break up the registers andinstructions into the correct bits (for example, use a structurethat can be unioned to break up the 8 bit specifier into thefollowing bit combos (4, 1, 3), (5, 3), (7, 1), (8). This willallow you to instantly extract the instruction, register andaddressing modes from each instruction. Also use a union to breakup the 16 bit operand into two 8 bit values. 4. Have the instructions be inputted either through the commandline or better yet, through a file, in the following format foreach instruction: a. 6 Hexadecimal…arrow_forwardprint the values Response question back.arrow_forwardWrite the Mnemonics of the code and show the output in SIM8085arrow_forward
- Instruction: Answer question 4 (a,b & c) only (1) Create a C++ project for your assignment 3, with the name format prescribed in the Information section. Add a source file and name it SwapCount. In this file, write the C++ program that will perform the tasks specified in question 2.(2) Declare and implement a function called sortSwapCount that passes three parameters, the array, the size and the reference of proportion, and returns the count. The functiondeclaration is int sortSwapCount(int data[], int size, double& proportion) (i) The function sorts the integers in data[] in ascending order using the bubble sort method. The purpose is to count or determine the number of exchanges (swaps) made by the bubble sort algorithm. (ii) The expected number of sorting swaps (expectedSwapCount) is size * (size - 1) if the array was unsorted. Calculate the proportion of the array status by first converting (or casting) the integers, swapCount and expectedSwapCount into floating-point,…arrow_forwardInstruction: Please write this code in javascript and let me know if there is an issue. Questions 1. Description a). You are to develop a JavaScript file (problems.js) that contains the implementation of 5functions. Each function is represented as one step, b). Each function is independent and solves a unique problem, as such, treat and implement each function in isolation of the others, that is, you should only focus on one problem at a time. 2). Objective • Write decision-making statements and control structures to solve problems• Apply programming logic to solve basic to intermediate problems• Testing and debuggingarrow_forwardInstruction: Please write this code in javascript and let me know if there is an issue. Questions 1. Description a). You are to develop a JavaScript file (problems.js) that contains the implementation of 5functions. Each function is represented as one step, b). Each function is independent and solves a unique problem, as such, treat and implement each function in isolation of the others, that is, you should only focus on one problem at a time. 2). Objective • Write decision-making statements and control structures to solve problems• Apply programming logic to solve basic to intermediate problems• Testing and debuggingarrow_forward
- Local Variables and Parameters Here is the entire assembly code for the body of a function (but excluding the activation record set-up code and the return statement of the function) in a C program. ADD R7, R4, 5 LDR R7, R7, He STR R7, R5, ue LDR R7, R5, He STR R7, R5, H-1 ADD R7, R4, 14 LDR R7, R7, ne STR R7, R5, ne And here is the entire global data section of that program GLOBAL_DATA_START g .FILL 12 L1_activi .FILL 1c3_L1_activi f .FILL 1c3_t L5_activi .FILL lc3_L5_activi L7_activi .FILL 13 L6_activi .FILL H6 L4_activi .FILL 184 L3_activi .FILL 1 L2_activi .FILL 45 .END How many lines of C code does the body of this function have? How many local variables does this function have? What is the value in the first local variable just before the function returns? If the function has two parameters, how many memory cells does the activation record for this function occupy?arrow_forwardSoftware: sim8085 Write 8085 microprocessor code and attach output screenshot.arrow_forwardThe cos(x) function is available once cmath has been declared in the preprocessor. True Falsearrow_forward
- Computer sciencearrow_forwardWrite and simulate a MIPS assembly-language routine that: 1. Prints your group number, for example “Group 1”, 2. Computes the dot product of two vectors, A_vec and B_vec, as described in Lab 4 of the Lab Manual, 3. Stores the result at memory word DOTPROD, and 4. Prints the result preceded by the phrase: “The result of the dot product is: “. Your data segment should look like the following: .data group: .asciiz “\nGroup x” msg: .asciiz "\nThe result of the dot product is: " A_vec: .word x, 4, 20, 13, 3, 10, 5 B_vec: .word 4, 2, 1, 2, 5, 2, 4 n: .word 7 DOTPROD: .word 0 Replace each “x” with your group number.arrow_forwardComplete the following task with steps: Here is how you might call a module to add numbers a and b from a C program: addem(a, b, &res); Assume that you have written the same subprocedure in assembly emu8086. You may also assume a, b, and res are memory locations declared in the data segment. Write how you would call the subprocedure, making sure you show how the variables get "passed" with instructions or comments or both.arrow_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