Computer Systems: A Programmer's Perspective (3rd Edition)
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
Expert Solution & Answer
Book Icon
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.

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...

Blurred answer
Students 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…
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…

Chapter 3 Solutions

Computer Systems: A Programmer's Perspective (3rd Edition)

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
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr