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

The function F is defined as F(1) = F(2) = F(3) = 1 and for n ? 3, F(n + 1) = F(

ID: 3740324 • 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.

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

Explanation / Answer

.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

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