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
Question
Book Icon
Chapter 4.5, Problem 4.44PP

A.

Program Plan Intro

Assembly code for Conditional jump:

long absSum(long *start, long count)

start in %rdi, count in %rsi

absSum:

irmovq $8, %r8

irmovq $1, %r9

xorq %rax, %rax     

andq %rsi, %rsi

jmp test

loop:

mrmovq (%rdi),%r10

xorq %r11, %r11

subq %r10, %r11

jle pos

rrmovq %r11, %r10

pos:

addq %r10, %rax

addq %r8, %rdi

subq %r9, %rsi

test:

jne loop

ret

Assembly code for Conditional move:

long absSum(long *start, long count)

start in %rdi, count in %rsi

absSum:

irmovq $8, %r8

irmovq $1, %r9

xorq %rax, %rax

andq %rsi, %rsi

jmp test

loop:

mrmovq (%rdi),%r10

xorq %r11, %r11

subq %r10, %r11

cmovg %r11, %r10

addq %r10, %rax

addq %r8, %rdi

subq %r9, %rsi

test:

jne loop

ret

Processing stages:

  • The processing of an instruction has number of operations.
  • The operations are organized into particular sequence of stages.
  • It attempts to follow a uniform sequence for all instructions.
  • The description of stages are shown below:
    • Fetch:
      • It uses program counter “PC” as memory address to read instruction bytes from memory.
      • The 4-bit portions “icode” and “ifun” of specifier byte is extracted from instruction.
      • It fetches “valC” that denotes an 8-byte constant.
      • It computes “valP” that denotes value of “PC” plus length of fetched instruction.
    • Decode:
      • The register file is been read with two operands.
      • It gives values “valA” and “valB” for operands.
      • It reads registers with instruction fields “rA” and “rB”.
    • Execute:
      • In this stage the ALU either performs required operation or increments and decrements stack pointer.
      • The resulting value is termed as “valE”.
      • The condition codes are evaluated and destination register is updated based on condition.
      • It determines whether branch should be taken or not in a jump instruction.
    • Memory:
      • The data is been written to memory or read from memory in this stage.
      •  The value that is read is determined as “valM”.
    • Write back:
      • The results are been written to register file.
      • It can write up to two results.
    • PC update:
      • The program counter “PC” denotes memory address to read bytes of instruction from memory.
      • It is used to set next instruction’s address.

B.

Program Plan Intro

Assembly code for Conditional jump:

long absSum(long *start, long count)

start in %rdi, count in %rsi

absSum:

irmovq $8, %r8

irmovq $1, %r9

xorq %rax, %rax     

andq %rsi, %rsi

jmp test

loop:

mrmovq (%rdi),%r10

xorq %r11, %r11

subq %r10, %r11

jle pos

rrmovq %r11, %r10

pos:

addq %r10, %rax

addq %r8, %rdi

subq %r9, %rsi

test:

jne loop

ret

Assembly code for Conditional move:

long absSum(long *start, long count)

start in %rdi, count in %rsi

absSum:

irmovq $8, %r8

irmovq $1, %r9

xorq %rax, %rax     

andq %rsi, %rsi

jmp test

loop:

mrmovq (%rdi),%r10

xorq %r11, %r11

subq %r10, %r11

cmovg %r11, %r10

addq %r10, %rax

addq %r8, %rdi

subq %r9, %rsi

test:

jne loop

ret

Processing stages:

  • The processing of an instruction has number of operations.
  • The operations are organized into particular sequence of stages.
  • It attempts to follow a uniform sequence for all instructions.
  • The description of stages are shown below:
    • Fetch:
      • It uses program counter “PC” as memory address to read instruction bytes from memory.
      • The 4-bit portions “icode” and “ifun” of specifier byte is extracted from instruction.
      • It fetches “valC” that denotes an 8-byte constant.
      • It computes “valP” that denotes value of “PC” plus length of fetched instruction.
    • Decode:
      • The register file is been read with two operands.
      • It gives values “valA” and “valB” for operands.
      • It reads registers with instruction fields “rA” and “rB”.
    • Execute:
      • In this stage the ALU either performs required operation or increments and decrements stack pointer.
      • The resulting value is termed as “valE”.
      • The condition codes are evaluated and destination register is updated based on condition.
      • It determines whether branch should be taken or not in a jump instruction.
    • Memory:
      • The data is been written to memory or read from memory in this stage.
      •  The value that is read is determined as “valM”.
    • Write back:
      • The results are been written to register file.
      • It can write up to two results.
    • PC update:
      • The program counter “PC” denotes memory address to read bytes of instruction from memory.
      • It is used to set next instruction’s address.

C.

Program Plan Intro

Assembly code for Conditional jump:

long absSum(long *start, long count)

start in %rdi, count in %rsi

absSum:

irmovq $8, %r8

irmovq $1, %r9

xorq %rax, %rax     

andq %rsi, %rsi

jmp test

loop:

mrmovq (%rdi),%r10

xorq %r11, %r11

subq %r10, %r11

jle pos

rrmovq %r11, %r10

pos:

addq %r10, %rax

addq %r8, %rdi

subq %r9, %rsi

test:

jne loop

ret

Assembly code for Conditional move:

long absSum(long *start, long count)

start in %rdi, count in %rsi

absSum:

irmovq $8, %r8

irmovq $1, %r9

xorq %rax, %rax     

andq %rsi, %rsi

jmp test

loop:

mrmovq (%rdi),%r10

xorq %r11, %r11

subq %r10, %r11

cmovg %r11, %r10

addq %r10, %rax

addq %r8, %rdi

subq %r9, %rsi

test:

jne loop

ret

Processing stages:

  • The processing of an instruction has number of operations.
  • The operations are organized into particular sequence of stages.
  • It attempts to follow a uniform sequence for all instructions.
  • The description of stages are shown below:
    • Fetch:
      • It uses program counter “PC” as memory address to read instruction bytes from memory.
      • The 4-bit portions “icode” and “ifun” of specifier byte is extracted from instruction.
      • It fetches “valC” that denotes an 8-byte constant.
      • It computes “valP” that denotes value of “PC” plus length of fetched instruction.
    • Decode:
      • The register file is been read with two operands.
      • It gives values “valA” and “valB” for operands.
      • It reads registers with instruction fields “rA” and “rB”.
    • Execute:
      • In this stage the ALU either performs required operation or increments and decrements stack pointer.
      • The resulting value is termed as “valE”.
      • The condition codes are evaluated and destination register is updated based on condition.
      • It determines whether branch should be taken or not in a jump instruction.
    • Memory:
      • The data is been written to memory or read from memory in this stage.
      •  The value that is read is determined as “valM”.
    • Write back:
      • The results are been written to register file.
      • It can write up to two results.
    • PC update:
      • The program counter “PC” denotes memory address to read bytes of instruction from memory.
      • It is used to set next instruction’s address.

Blurred answer
Students have asked these similar questions
Q4. Write a MATLAB program to create a (3×3) matrix using single instruction, where the sum of elements in each column, each row, and each diagonal are equal, then perform the following requirements: 1) Clear the elements of upper triangular part. 2) Calculate the product of elements of the diagonal. 3) Calculate average of all the elements. 4) Calculate the number of all the elements. 5) Invert the rows to columns and the columns to rows.
2. [4pts] Use the following C-Code for the problems below. int recFunc (int a, int b) { if (b = 0) == return a; else return 1+recFunc (a, b-1); a. Give the flowchart for the C-Code b. Convert to MIPS assembly and comment each assembly instruction to indicate corresponding C-Code.
(c) The following Sigma 16 program has been loaded into memory at address 0000: load R3,y[RO] load R4,x[RO] lea R5, 2[RO] sub R1,R4,R3 mul R2,R1,R5 store R2,w[RO] trap RO,RO,RO x data 10 y data 12 w data 0 Show the content of the memory writing hexadecimal representation and using a table with 3 columns: the memory address, the contents of that memory address, and an explanation of what "the content (of that memory address) means". As a reference, here are the opcodes for RRR instructions: add 0, sub 1, mul 2, trap c. And here the opcodes for RX instructions: lea 0, load 1, store 2. [7]

Chapter 4 Solutions

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

Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education