The function F is defined as F(1) = F(2) = F(3) = 1 and for n >= 3, F(n + 1) = F
ID: 3741058 • Letter: T
Question
The function F is defined as F(1) = F(2) = F(3) = 1 and for n >= 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.
a) 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.
b) 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.
Use the instruction set in the Instruction Set Architecture below:
LOAD a, b a <- b
STOR a, b a <- b
ADD a, b, c a <- b + c
SUB a, b, c a <- b - c
MUL a, b, c a <- b * c
DIV a, b, c a <- b / c
AND a, b, c a <- b & c
OR a, b, c a <- b | c
NOT a, b a <- !b
ASH a, b, c r <- b (arithmetically) shifted by c positions
LSH a, b, c a <- b (logically) shifted by c positions
BR a PC <- a
BEQ a, b, c PC <- a if b is equal to c
BNE a, b, c PC <- a if b is not equal to c
BLT a, b, c PC <- a if b is less than c
BGT a, b, c PC <- a if b is greater than c
BLE a, b, c PC <- a if b is less than or equal to c
BGE a, b, c PC <- a if b is greater than or equal to c
please make sure to use the instruction set given above.
Explanation / Answer
As per the given data wrote a PROGRAM as :
.LC0:
.string "Enter the number of terms: "
.LC1:
.string "%d"
.LC2:
.string "Fibonacci Series: "
.LC3:
.string "%d, "
main:
push rbp
mov rbp, rsp
sub rsp, 32
mov DWORD PTR [rbp-8], 0
mov DWORD PTR [rbp-12], 1
mov edi, OFFSET FLAT:.LC0
mov eax, 0
call printf
lea rax, [rbp-20]
mov rsi, rax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call __isoc99_scanf
mov edi, OFFSET FLAT:.LC2
mov eax, 0
call printf
mov DWORD PTR [rbp-4], 1
jmp .L2
.L3:
mov eax, DWORD PTR [rbp-8]
mov esi, eax
mov edi, OFFSET FLAT:.LC3
mov eax, 0
call printf
mov edx, DWORD PTR [rbp-8]
mov eax, DWORD PTR [rbp-12]
add eax, edx
mov DWORD PTR [rbp-16], eax
mov eax, DWORD PTR [rbp-12]
mov DWORD PTR [rbp-8], eax
mov eax, DWORD PTR [rbp-16]
mov DWORD PTR [rbp-12], eax
add DWORD PTR [rbp-4], 1
.L2:
mov eax, DWORD PTR [rbp-20]
cmp DWORD PTR [rbp-4], eax
jle .L3
mov eax, 0
leave
ret
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.