Computer Systems: Program... -Access
Computer Systems: Program... -Access
3rd Edition
ISBN: 9780134071923
Author: Bryant
Publisher: PEARSON
Question
Book Icon
Chapter 3, Problem 3.66HW
Program Plan Intro

Given assembly code:

# long sum_col(long n, long A[NR(n)][NC(n)], long j)

# n in %rdi, A in %rsi, j in %rdx

sum_col:

  leaq 1(,%rdi,4), %r8       

  leaq (%rdi,%rdi,2), %rax   

  movq %rax, %rdi            

  testq %rax, %rax           

  jle .L4                    

  salq $3, %r8               

  leaq (%rsi,%rdx,8), %rcx   

  movl $0, %eax             

  movl $0, %edx              

.L3:

  addq (%rcx), %rax          

  addq $1, %rdx              

  addq %r8, %rcx             

  cmpq %rdi, %rdx            

  jne .L3                    

  rep

  ret

.L4:

  movl $0, %eax              

  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.
    • It can either be a memory location or a register.
    • The instruction “incq” causes 8 byte element on stack top to be incremented.
    • The instruction “decq” causes 8 byte element on stack top to be decremented.
  • The details of binary operations includes:
    • The first operand denotes the source.
    • The second operand works as both source as well as destination.
    • The first operand can either be an immediate value, memory location or register.
    • The second operand can either be a register or a memory location.

Blurred answer
Students have asked these similar questions
Write a C++ program which performs the following tasks: a) Initialize an integer array of 10 elements in main( ) b) Pass the entire array to a function modify( ) c) In modify( ) multiply each element of array by 3 d) And display each element of array
Reference the image below.(a) Write a code in python to implement Hoare's algorithm.(b) Using LArray = {36, 12, 39, 34, 89, 2, 47, 95, 17, 19, 78, 22} as input, display the finaloutput and the array LArray after it has been manipulated by the algorithm.(c) Modify the algorithm to display the LArray after each swap done, being sure to indicatewhat swap is being observed.
Convert the below c++ code to corresponding Pep/9 assembly language.     #include <iostream>                       // include the required header files using namespace std; int arr[20], num, temp, i;                // declare the required variableint main(){ cin >> num;                                  // take the number of elements of the array for (i = 0; i < num; i++) {  cin >> arr[i];                                 // take the elements from the user } temp = arr[0]; for (i = 0; i < num; i++)               // loop to move the content of the array {  arr[i] = arr[i + 1]; } arr[num - 1] = temp; for ( i = 0; i < num; i++)              // loop to display the content of the final array {  cout << arr[i] << ' '; } cout << endl; return 0;}

Chapter 3 Solutions

Computer Systems: Program... -Access

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++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning