A.
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.
- Fetch:
B.
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.
- Fetch:
C.
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.
- Fetch:
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
- Computer architecturearrow_forward8(s+1)(s+2) Exercise 3: A transfer function is given as T(s) = (s+10) (s+3)(s+4)' a. Use MATLAB function zpk() to define the transfer function. b. Use MATLAB command zplane() to obtain the zero-pole plot of the T (s). c. Use MATLAB to plot the step and ramp response of the system. d. Think about a way to plot the ramp response of the system by still using the MATLAB function step().arrow_forward4(c): Design an "unconventional" priority encoder as follows: It has 3 inputs D0, D1 and D2 and outputs A1, A0 and Valid. The input combination [D1,D0] = [11] is guaranteed to never happen, that is, both D1 and DO cannot be 1 at the same time. If D2 is 1, then the output code [A1A0]=[10]. Else it is either [01] or [00] depending on which of D1 or DO is logic 1. If any input is 1, Valid=1, else Valid=0. Give expressions for A1, A0 and Valid in terms of D0, D1 and D2. A1 = AO = Valid = You may DI Do yoo/01 use any lo 00 101 method you know to get your answer. Ai Ao Please draw any k-maps D2 00 01 10 used for partial credit (see below). It must be Valid. clear how you got your answer, i.e. show all "rough" work.arrow_forward
- a) b) Explain the following machine independent optimization techniques. Common sub expression and dead code elimination Copy propagation, constant folding. Instruction scheduling.arrow_forwardMIPS Low-Level Assembly Program Complete determinant function. You are given a 2x2 matrix, that each element is 16-bit. The elements, a and b, are packed and passed to placed individually in higher and lower 16 bits of the function argument register, $a0. And the elements, c and d, are in $a1. I am running into an error where my output does not match the expected output - my code: # PART 3 (Determinant)## You are given a 2x2 matrix, that each element is 16-bit.# Calculate its determinant.## Implementation details:# The four 16-bit integers are stored in registers $a0, $a1.# You need to store the answer into register $v0 in order to# be returned by the function to the caller.determinant:############################## Part 3: your code begins here ### srl $t0, $a0, 16 # $t0 = a,andi $t1, $a0, 65535 # $t1 = bsrl $t2, $a1, 16 # $t2 = candi $t3, $a1, 65535 # $t3 = dmul $t0, $t3, $t0 # $t0 = admul $t1, $t2, $t1 # $t1 = bcsub $v0, $t0, $t1 ############################## Part 3: your code ends…arrow_forward11 Using MIPS assembly code, re-arrange an array in place such that all the even numbers come before all the odd numbers. The numbers may be in any order, so long as the evens come before the odds. Register $a0 will contain the array and register $a1 will contain the length of the array.arrow_forward
- subject : computer architectures and organization (computer science)arrow_forwardmystery: mov %rdi, %rax cmp %rsi, %rax cmovl %rsi, %rax cmp %rdx, %rax cmovl %rdx, %rax ret Parameters x, Y, z are stored in registers %rdi, %rsi, and %rdx, respectively. Write C code for mystery that will have an effect equivalent to the assembly code.arrow_forwardProblem D. DNA Input file: Output file: Time limit: standard input standard output 1 second 256 megabytes Memory limit: As you know desoxyribonucleic acid consists of 4 mucleobases: adenine, guanine, cytosine, thymine. This nucleobases must form pairs: adenine with thymine and guanine with cytosine. You are given the sequence of nucleobases in the first part of DNA spiral. Please, find its second part. Input You are given the only string DNA. It is guaranteed that DNA consists only of uppercase letters 'A', "C', T', 'G'. Output Print the second part of DNA spiral. Examples standard input standard output ACTG TGÁC A GTA СATarrow_forward
- 4. A particular piece of loop iteration requires 6 registers, 2 of which are used to track array indices / loop counters. The other 4 registers are used to hold load values, compute results and store results. If the architecture has 32 general-purpose registers, then how many times can the loop be unrolled by the compiler?arrow_forwardI. (14 points) The CPU shown below, with the same registers as the Very Simple CPU (as shown in the "CPU Design" lecture notes), has the following instruction set and state diagram. Show the RTL code for the execute cycles for each instruction. Assume that the RTL code for the fetch routine is the same as that of the Very Simple CPU. This problem will test your skill in developing RTL statements of a given CPU behavior. FETCHI FETCH2 FETCH3 IR-00 IR=01 IR=10 IR=11 JMP11 INC21 ADD11 SKIP1 JMP12 INC22 ADD12 Instruction Instruction Operation Code PC← JMP1 00AAAAAA AAAAAA+1 INC2 01XXXXXX AC AC +2 AC AC+ ADD1 10AAAAAA MAAAAAA] + 1 SKIP 11XXXXXX PC PC +1arrow_forwardQ1) Consider a simple traffic light system to regulate safe pedestrian crossing on a busy lane. Consider the following system requirement:(SysReq:)The traffic lights shall allow pedestrians to safely cross the lane by stopping cars together with the following software requirements: (SofReq1:)The light switch for pedestrians will be set to 'green' within x seconds after the pedestrian button has been pressed. (SofReq2:)The light switch for cars will be set to 'red' at least y seconds before the light switch for pedestrians is set to 'green'. Find missing environment assumptions and domain properties that are necessary to build the following satisfaction argument: {SofReq1, SofReq2, assumptions?, domain properties?} =SysReq Are the missing domain properties adequate? Are the missing assumptions realistic?arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education