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?
Give solution in C ++ Language. Write logic also which is applicable in this question. First read the instruction and hints then solve the question. Hints and Instructions : First read the number of rows and numbers of columns for the grid of information. Store them in Array (2D) These values are then followed by the elevation values, in row order. The maximum size of the grid is 5 rows by 5 columns. Then extend it to 10x10. Forget the file handling part. Just randomly fill in data in 2d array. And then try to find maximum of the array while keeping in mind the conditions mentioned. Don't store date or file in grid.text.
The following instruction set is supported by a simple processor, which is similar to what we discussed in the class, with a few new instructions added. The format of most instructions is defined as follows. bits 15:14 13:10 9 8:6 5:3 2:0 field unused opcode w srcl src2 dst where the fields are defined as follows. opcode : operation to be performed by the processor write back ALU output to register file (1= yes, 0 = no) address of the first ALU operand in the register file address of the second ALU operand in the register file address in the register file where the output is written w: srcl: src2: dst: For opcodes BEQ, BLEZ and JUMP, the 6 least significant bits (5:0) give an address in the instruction memory, which is byte-addressed. The opcode HALT has all operand bits (9:0) being 0. When an instruction has only two operands, the field for the unused operand is filled with 0-bits. For example, bits (5:3) for SLL are all zero because src2 is not used. The opcode and meaning of these…

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