Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The function FIs defined as FU)-F)Fa)-1 and for n 2 3, F(n + 1) = F(n) + (F(n-1)

ID: 3706952 • Letter: T

Question

The function FIs defined as FU)-F)Fa)-1 and for n 2 3, F(n + 1) = F(n) + (F(n-1): F(n-2)) i.e., the (n 1)th value is given by the sum of the nth value and the product of the (n 1)th and (n 2)th values. Write an assembly program for computing the kth value F(k), where k is an integer bigger than 3 read from a memory location M, and storing F(k) at memory location M. Show the execution of your program on a superscalar processor for k 5. Assume that all the decoded instructions are already loaded into an instruction window IW on board. The remaining pipeline stages are RR, EX and WB. Assume that there are two functional units (reading and writing to registers, and execution units) for each of the pipeline stages. Make your additional as- sumptions explicit. Explain where and why delay slots appear.

Explanation / Answer

.file "fibonacci.c"

.section .rodata

.align 8

.LC0:

.string "Enter the nth number in fibonacci series: "

.LC1:

.string "%d"

.align 8

.LC2:

.string "Fibonacci of negative number is not possible."

.align 8

.LC3:

.string "The %d number in fibonacci series is %d "

.text

.globl main

.type main, @function

main:

.LFB0:

.cfi_startproc

pushq %rbp

.cfi_def_cfa_offset 16

.cfi_offset 6, -16

movq %rsp, %rbp

.cfi_def_cfa_register 6

subq $16, %rsp

movq %fs:40, %rax

movq %rax, -8(%rbp)

xorl %eax, %eax

leaq .LC0(%rip), %rdi

movl $0, %eax

call printf@PLT

leaq -16(%rbp), %rax

movq %rax, %rsi

leaq .LC1(%rip), %rdi

movl $0, %eax

call __isoc99_scanf@PLT

movl -16(%rbp), %eax

testl %eax, %eax

jns .L2

leaq .LC2(%rip), %rdi

call puts@PLT

jmp .L3

.L2:

movl -16(%rbp), %eax

movl %eax, %edi

call fibo

movl %eax, -12(%rbp)

movl -16(%rbp), %eax

movl -12(%rbp), %edx

movl %eax, %esi

leaq .LC3(%rip), %rdi

movl $0, %eax

call printf@PLT

.L3:

movl $0, %eax

movq -8(%rbp), %rcx

xorq %fs:40, %rcx

je .L5

call __stack_chk_fail@PLT

.L5:

leave

.cfi_def_cfa 7, 8

ret

.cfi_endproc

.LFE0:

.size main, .-main

.globl fibo

.type fibo, @function

fibo:

.LFB1:

.cfi_startproc

pushq %rbp

.cfi_def_cfa_offset 16

.cfi_offset 6, -16

movq %rsp, %rbp

.cfi_def_cfa_register 6

pushq %rbx

subq $24, %rsp

.cfi_offset 3, -24

movl %edi, -20(%rbp)

cmpl $0, -20(%rbp)

jne .L7

movl $1, %eax

jmp .L8

.L7:

cmpl $1, -20(%rbp)

jne .L9

movl $1, %eax

jmp .L8

.L9:

cmpl $2, -20(%rbp)

jne .L10

movl $1, %eax

jmp .L8

.L10:

movl -20(%rbp), %eax

subl $1, %eax

movl %eax, %edi

call fibo

movl %eax, %ebx

movl -20(%rbp), %eax

subl $2, %eax

movl %eax, %edi

call fibo

addl %eax, %ebx

movl -20(%rbp), %eax

subl $3, %eax

movl %eax, %edi

call fibo

addl %ebx, %eax

.L8:

addq $24, %rsp

popq %rbx

popq %rbp

.cfi_def_cfa 7, 8

ret

.cfi_endproc

.LFE1:

.size fibo, .-fibo

.ident "GCC: (Ubuntu 7.2.0-8ubuntu3.2) 7.2.0"

.section .note.GNU-stack,"",@progbits

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote