Question

The Fibonacci sequence F is defined as F(1) = F(2) = 1 and for n>= 2,...

The Fibonacci sequence F is defined as F(1) = F(2) = 1 and for n>= 2,
F(n + 1) = F(n) + F(n − 1)

i.e., the (n + 1)th value is given by the sum of the nth value and the (n − 1)th value.

1. Write an assembly program typical of RISC machines for computing the kth value F(k), where k is a natural number greater than 2 loaded from a memory location M, and storing the result at memory location M.

Use the Instruction Set Architecture below

Instruction Set Architecture
We present a list of instructions typical of a RISC (reduced instruction set computer)
machine. In data-movement and control instructions, the addresses may be immediate #X,
direct (memory) M, indirect (memory) [M], register r, or register indirect [r] addresses.
Data-processing instructions use immediate or register addressing. PC is the programme
counter and a <- b indicates that the value of b is placed in a.
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 a <- 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
Most instructions have oating-point versions when special oating-point registers are used
(but we will not need these).
Most architectures use two addresses, where the first (or second) argument serves both
as the target and one of the sources, e.g., ADD a, b means a <- a + b. For branch instructions, BR X means to jump to instruction X (i.e., load the address of instruction x into PC).
We will use a ve-stage pipeline: IF (instruction fetch), ID (instruction decode), RR
(register read), EX (execute instruction), WB (write back result). We will assume that
for data-movement instructions the data transfer between the CPU and main memory
happens in the execute stage. Note that for some instructions (e.g., LOAD r, #X) some of
the pipeline stages (e.g., RR) are not needed.

Solution:
1. 1. LOAD r2, M
2. LOAD r0, #1
3. LOAD r1, #1
4. SUB r2, r2, #1
5. ADD r3, r0, r1
6. LOAD r0, r1
7. LOAD r1, r3
8. BNE 4, r2, #2 // jump to instruction 4 if r2 is not equal to 2
9. STOR M, r1
where # indicates immediate addressing and BNE stands for “branch if not equal”.

According to the solution above, how the solution will be for this function?

The function F is dened as F(1) = F(2) = F(3) = 1 and for n>= 3,
F(n + 1) = F(n) + (F(n - 1) x F(n - 2))
i.e., the (n + 1)th value is given by the sum of the nth value and the
multiplication of the (n - 1)th and (n - 2)th values.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The solution to the above problem will be :

1. LOAD r3, M //load n from the memory location M in r3 register

2. LOAD r0, #1 //load 1 into r0 register

3. LOAD r1, #1 //load 1 into r1 register

4. LOAD r2, #1 //load 1 into r2 register

5. SUB r3, r3, #1

6.MUL r5,r0,r1 //mul f(n-1) and f(n-2) and loading into r5

7.ADD r6,r2,r5 //add r5 with f(n) and saving into r6

8.LOAD r0, r1 //loading the values one step further in the steps(8,9,10)

9.LOAD r1, r2

10.LOAD r2, r6

11.BNE 5, r3, #3 //jump to instruction 5 if r3 is not equal to 3

12.STOR M,r2 //storing answer into the Location M

Add a comment
Know the answer?
Add Answer to:
The Fibonacci sequence F is defined as F(1) = F(2) = 1 and for n>= 2,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • computer analysis

    Questions1.  The function L is defined as L(1) = 2,L(2) = 1,L(3) = 3,L(4) = 4 and for n ≥ 4,L(n + 1) = L(n) + L(n − 1) + L(n − 2)L(n − 3)i.e., the (n + 1)-th value is given by the sum of the n-th, n − 1-th and n − 2-th values divided by the n − 3-th value.(a)  Write an assembly program for computing the k-th value L(k), where k is an integer bigger than...

  • Assume the program counter (PC) is initially equal to n. Assume that the word length of...

    Assume the program counter (PC) is initially equal to n. Assume that the word length of the processor is 1. a)      How many fetches are required to make PC equal to m if there are no branch instructions between n and m? b)      What is the content of the instruction register (IR) when the PC’s value is n+k? Justify your answer. Why we are not using a hundred pipeline stages if anoperation can be divided up into a hundred steps,...

  • Section B - ARM Assembly Language (25 marks) An ARM instruction set summary is provided at...

    Section B - ARM Assembly Language (25 marks) An ARM instruction set summary is provided at the end of this paper 1. (5 marks) Consider the following assembly instruction STMFD r13!, (r5-6} Before executing this instruction, registers hold the following values: Register Value Register r9 Value r4 0x00400040 0x00000000 r5 r10 0x11223344 0x00800080 r6 0x55667788 r11 0x10001000 r7 0x99aabbcc r12 0x20002000 r8 exddeeff00 r13 ex40004000 What memory locations are affected after executing the above instruction? In a table, with a...

  • A block diagram of MIPS architecture is given below. What is the value of the control...

    A block diagram of MIPS architecture is given below. What is the value of the control bit for each MUX during the execution of the given instruction? Note, you may use N/A if MUX output is not useful. > Add 2x MUX 4 ALU 4- Addresult Shift left 2 Instruction (31-26] RegDst Branch MemRead MemtoReg Control ALUOP MemWrite ALUSC RegWrite Instruction (25-21) PC Read address Instruction (20-16] Read register 1 Read Read data 1 register 2 Write Read MUX 2...

  • urgent A block diagram of MIPS architecture is given below. What is the value of the...

    urgent A block diagram of MIPS architecture is given below. What is the value of the control bit for each MUX during the execution of the given instruction. Note, you may use N/A if MUX output is not useful. >Add u MUX4 ALU 4 - Addresult Shift left 2) RegDst Branch MemRead Instruction (31-26) Control Memto Reg ALUOp MemWrite ALUSC RegWrite Instruction [25-21] PC Read address Instruction (20-16] Read register 1 Read Read data 1 register 2 Write Read MUX...

  • The classic five-stage pipeline MIPS architecture is used to execute the code fragments in this problem....

    The classic five-stage pipeline MIPS architecture is used to execute the code fragments in this problem. Assume the followings: The architecture fully supports forwarding, Register write is done in the first half of the clock cycle; register read is performed in the second half of the clock cycle, Branches are resolved in the third stage of the pipeline and the architecture does not utilize any branch prediction mechanism, Register R4 is initially 100. L1:  lw    R1, 0(R4)   add   R3, R1, R2 sw   ...

  • i cannot get all info in one picture so it is 2 pics Question 13 16...

    i cannot get all info in one picture so it is 2 pics Question 13 16 points A block acturing get you MUX4 Adid ALU re Rogo Branch SW Rent 2 Instruction 31-26 Contro MUSIC Pew ruction 25-29 Read 1 struction (2016 MUXI MUX 2 Zero ALULU MUX3 Instruction 1-0 Instruction memory Write Read con 15-11) Write data Register Gememory instruction (15-02 Sign22 extend ALU control Instruction 15-01 con 50 MUX 1 Instruction R1, 8(R2) MUX 2 MUX 3 ML...

  • it is the same question A block diagram of MIPS architecture is given below. What is...

    it is the same question A block diagram of MIPS architecture is given below. What is the value of the control bit for each MUX during the execution of the given instruction? Note, you may use N/Aif MUX output is not usefu Add MUX 4 ALU Add, result Shift left 2 RegDst Branch MemRead Instruction (31-26] Control Memto Reg ALUOP Mem Write ALUSrc RegWrite Instruction [25-21) PC Read address Instruction (20-16] MUXT Read register 1 Read Read data 1 register...

  • 1. Translate the following tasks into a single ARM instruction: a. Add 32 times of the...

    1. Translate the following tasks into a single ARM instruction: a. Add 32 times of the content of registers r0 and the content of r1 only if N is clear. Store the result in register r2 b. Subtract the content of register r0 from 0x990 and put the results in register r3 only if C is set and Z is clear. c. Clear the 2nd least significant byte of the content of register r1, i.e., store (00000000)2 in it, and...

  • Could you please help me doing this? Slide #14: Slide #15 The question: ARM Assembly Language...

    Could you please help me doing this? Slide #14: Slide #15 The question: ARM Assembly Language label mnemonic operand1, operand2, operand3 comments R2+R1->R3 Loc ADD R3, R2 R1 Label is a symbolic reference to this instruction's address in memory. Mnemonic represents the operation to be performed .The number of operands varies, depending on each specific instruction. Some instructions have no operands at all. operand1 is typically the destination register, and operand2 and operand3 are source operands. operand2 is usually a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT