Computer Systems: Program... -Access
3rd Edition
ISBN: 9780134071923
Author: Bryant
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
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.
- 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.
- 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.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents 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.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
- Part (a) Above is the assembly code for the function declared as: tomato(int array[], int x, int y). Assume that“myarray” is an array of 500 integers, and the function is called as tomato(myarray, 5, 21).(i) How many times is the “slt” instruction executed? Justify your answer to receive credit. ((ii) How many times is the “lw” instruction executed? Justify your answer to receive credit. ?Part (b) Calculate the total number of cycles it takes to execute tomato(myarray, 5, 21). Show your work ?Part (c) What is the execution time in milliseconds for the tomato(myarray, 5, 21) function if the processor operates at60KHz? Show your workPart (d) Your manager claims that it is possible to achieve an overall speedup of 2.2x by optimizing the data memoryaccess time. Is this claim correct? If so how much speed up is necessary for the data memory accesses to achieve anoverall speedup of 2.2x?arrow_forwardBelow is the flow diagram of the Selection Sort algorithm. The array elements are listed in the sample table below according to the flow chart above. According to this information;a) Calculating the average value of array elements and assigning it to the avg variable,b) Implementing the Selective Sorting algorithm in assembly language with the option aWrite the code in the blank space below, explain the code. n= 10 (Number of elements of array a) a[10] = { 32, 16, 64, 128, 2, 8, 0, 4, 1, 3 } Answer: MY_DATA SEGMENT PARA 'DATA' n DB 10 a DB 32, 16, 64, 128, 2, 8, 0, 4, 1, 3 ort DW ? MY_DATA ENDS MY_CODE SEGMENT PARA 'CODE' MY_PROG PROC FAR ASSUME CS:MY_CODE, DS:MY_DATA MOV AX,MY_DATA MOV DS,AX .......... MOV AH, 04CH INT 21H RET MY_PROG ENDP MY_CODE ENDS END MY_PROGarrow_forwardWrite a c++ function that accepts an array of doubles and the array’s size as its only arguments. The function should use dynamic memory allocation to create a new array that is double the size of the argument array. The function should copy the contents of the argument array to the second half of the new array and initialize the first half of the new 0s. The function should return a pointer to the new array. So, if the original array contained 1 2 3 4, the new array should contain 0 0 0 0 1 2 3 4. So, if the original array contained 1 2 3 4, the new array should contain 0 0 0 0 1 2 3 4.arrow_forward
- Microprocessor8086 Write the assembly of Write on the data segment and create number1 and number2 variables in byte size and initialize the variables Then compute the sum ,subtraction,multiplication and division of the defined variables and load the values to the variables which you create on the data segment Perform the operations below in sequence with defined on the data segment numbers in array Find the sum of array and average of array Find the maximum and minimum numbers of array If it’s possible on emu8086 apparrow_forwardWrite 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 Multiple( )c) In Multiple( ) multiply each element of array by 5d) And display each element of arrayarrow_forwardQuestion P Implement the following C++ code fragment in assembly language. Use the block-structured .IF and .WHILE directives. Assume that all variables are 32-bit integers. int array[] = {3,1,4,1,5,9,2,6,5,3,5,8,9,7,9,3,2,3,8,4}; int lower = 3; int upper = 8; int ArraySize = sizeof array / sizeof lower; int index = 0; int sum = 0; while( index < ArraySize ) { if( array[index] >= lower && array[index] <= upper ) { sum += array[index]; } index++; } Your assembly language program must also display as output the number of times a member of ' array ' qualified for inclusion into the ' sum ' and what the final value of the variable ' sum ' was. ( Full explain this question and text typing work only We should answer our question within 2 hours takes more time then we will reduce Rating Dont ignore this line )arrow_forward
- 3.) Write a C++ program that will prompt the user for the size of a list of integers. Your program will 1. dynamically allocate an array of that size and allow the user to enter the values. 2. Your program will then go through the list and copy all even numbers to another dynamically allocated array. The functionality of 1 and 2 need to be accomplished by separate functions. 4.) Redo question number 3 with these changes. Instead of dynamically allocating an array to store the data, your program will will an STL array. Even numbers will also be copied to an STL array. The input of the data and copying of even numbers will require the program to start at the beginning of the array and walk thorugh the values to the end. This must be done using iterators.arrow_forwardConsider the following C++ Code - Write a C++ code that outputs the contents of the array to which strPtr Points and deallocates the memory space occupied by the array to which strPtr points. - Can you modify the code to use a different array size for strPtr? How would this affect the output of the program?arrow_forward. What will be the output of the following code, consider the memory address of variable x is 0x0044c and pointer variable ptr is 0x0066f, and consider int data type take 2 byte in the memory void main() { int x[5] = { 1,2,3,4,5 }; int *ptr = x; ptr = ptr + 1; cout << ptr << endl; cout << *ptr << endl; cout << &ptr << endl; cout << &x[0] << endl; cout << *x << endl; x += 2; cout << x << endl; }arrow_forward
- 4. Write a program to sort the elements of 1D array in descending order and also implement linear search on the same array. Both sorting and searching operations should be done inside one user defined function: “Task”. So, for achieving the required functionality, pass, array into the function: Task () from main () using Pass by reference/ or address approach.arrow_forwardWrite a C function and program that calculates the array size after deleting a certain element of a 10-element integer array from the array. Sample: Series: 1 2 2 3 4 4 5 5 6 6 Array size after 4 deleted: 8 Note: A CALL BY REFERENCE function will be written. The element we want to delete will be entered by the user. The entered number can be repeated more than once in the array, the asking array size will be calculated after all duplicates are deleted.arrow_forwardWrite a C++ program that will implement and test the five functions described below that use pointers and dynamic memory allocation. The Functions: You will write the five functions described below. Then you will call them from the main function, to demonstrate their correctness. findLast: takes an array of integers, its size and a target integer value. Returns an index of the last occurrence of the target element in the array. If the target value doesn't exist, returns -1. For this function only: Do not use square brackets anywhere in the function, not even the parameter list (use pointer notation instead). nextFibonacci. Modify the following function to use pointers as parameters (instead of reference parameters). The Fibonacci sequence is a series of numbers where each number is the addition of the previous two numbers, starting with 0, and 1 (specifically: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55…). This function updates the given i-th and (i+1)-st Fibonacci numbers to (i+1)-st and…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning