Question

M.A.R.I.E assembly code for 7th value of Fibonacci sequence: Fib(1) = 1, Fib(2) = 1, Fib(n)...

M.A.R.I.E assembly code for 7th value of Fibonacci sequence: Fib(1) = 1, Fib(2) = 1, Fib(n) = Fib(n-1) + Fib(n-2). The program calculates Fib(7).

I have 4 errors in my code and cannot seem to find the solutions

here is the code so far,

ORG 100

   Input
   Store x
   Input
   Store y

FOR_INIT, LOAD one
STORE i

FOR_COND, LOAD i
SUBT seven
SKIPCOND 800
JUMP FOR_BODY
JUMP END_FOR

FOR_BODY, LOAD x
ADD y
STORE z
LOAD x
STORE y
LOAD y
STORE x
LOAD i
ADD one
STORE i
JUMP FOR_COND

END_FOR, LOAD z
OUTPUT
HALT

zero,   Dec 0
one,   Dec 1
seven,   Dec 7
x,   Dec 0
y,   Dec 1
z,   Dec 0

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

Answer:

MIPS Assembly Language Code :

.zero 1
L0:
push rbp
mov rbp, rsp
push rbx
sub rsp, 24
mov DWORD PTR [rbp-20], edi
cmp DWORD PTR [rbp-20], 1
je .L2
cmp DWORD PTR [rbp-20], 2
jne .L3
.L2:
mov eax, 1
jmp .L4
.L3:
mov eax, DWORD PTR [rbp-20]
sub eax, 1
mov edi, eax
call L0
mov ebx, eax
mov eax, DWORD PTR [rbp-20]
sub eax, 2
mov edi, eax
call L0
add eax, ebx
.L4:
add rsp, 24
pop rbx
pop rbp
ret
main:
push rbp
mov rbp, rsp
mov edi, 7
call L0
mov esi, eax
mov edi, OFFSET FLAT:std::cout
call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
mov esi, OFFSET FLAT:std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)
mov rdi, rax
call std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))
mov eax, 0
pop rbp
ret
__static_initialization_and_destruction_0(int, int):
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-4], edi
mov DWORD PTR [rbp-8], esi
cmp DWORD PTR [rbp-4], 1
jne .L9
cmp DWORD PTR [rbp-8], 65535
jne .L9
mov edi, OFFSET FLAT:std::__ioinit
call std::ios_base::Init::Init()
mov edx, OFFSET FLAT:__dso_handle
mov esi, OFFSET FLAT:std::__ioinit
mov edi, OFFSET FLAT:std::ios_base::Init::~Init()
call __cxa_atexit
.L9:
nop
leave
ret
push rbp
mov rbp, rsp
mov esi, 65535
mov edi, 1
call __static_initialization_and_destruction_0(int, int)
pop rbp
ret

Add a comment
Know the answer?
Add Answer to:
M.A.R.I.E assembly code for 7th value of Fibonacci sequence: Fib(1) = 1, Fib(2) = 1, Fib(n)...
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
  • Finish the MARIE assembly language code below to determine the largest integer, the smallest integer, and...

    Finish the MARIE assembly language code below to determine the largest integer, the smallest integer, and the sum of integers for a sequence of 5 signed integers. The program already calculates the largest integer, just need it to calculate the smallest integer and the sum of the integers. The 5 integers should first be entered by the user via the input device. Your program is then assembled and run to determine the largest integer, the smallest integer, and the sum...

  • Given the instruction set for MARIE: Write the assembly language equivalent for the machine i...

    Given the instruction set for MARIE: Write the assembly language equivalent for the machine instruction: 1011 000000001111. Instruction Instruction Instruction Opcode JnS X Instruction Halt Skipcond (00 for ACO, 01 for AC-0, 10 for AC0) Jump X Clear AddI X Jumpl X Opcodde Load X8 Store X9 Add X Subt X B Input Output Instruction Instruction Instruction Opcode JnS X Instruction Halt Skipcond (00 for ACO, 01 for AC-0, 10 for AC0) Jump X Clear AddI X Jumpl X Opcodde...

  • Marie Assembly Language

    Assembly (MARIE), how can I output my input variables on exit?I am trying to compose an assembly (MARIE) program to output my input variables **on exit**. I am triggering an exit when . (period) is entered. I am transforming the input, and to later display the new value on exit.Some context, FOO will return SBB when ran through Rot-13However, my program is displaying the output on each iteration of my loop. I am instead wanting to not display anything, until . is entered...

  • Fibonacci function Fib(n) is given below. Fib(n)= Fib(n-1) + Fib(n-2) for n > 1 Fib(n)= 1...

    Fibonacci function Fib(n) is given below. Fib(n)= Fib(n-1) + Fib(n-2) for n > 1 Fib(n)= 1 for n=1 Fib(n)= 0 for n=0 Using following initialization unsigned int *Fib = new unsigned int[30]; and function prototypes void push(int n) unsigned int pop( ) insert first 30 Fibonacci numbers into dynamic array Fib and then pop them to print out first 30 numbers in descending order. The output of your program should be 514229, 317811, 196418, ......, 1, 1, 0

  • Question 15 5 pts What's stored in the Accumulator register after this code is executed? Express...

    Question 15 5 pts What's stored in the Accumulator register after this code is executed? Express your answer as a decimal value. ORG 19 LOAD X ADD Y STORE Z HALT X, DEC 7 Y, DEC 1 1, HEX

  • Fibonacci Sequence The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5,...

    Fibonacci Sequence The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... The next number is found by adding up the two numbers before it. The 2 is found by adding the two numbers before it (1+1) The 3 is found by adding the two numbers before it (1+2), And the 5 is (2+3), and so on!         Example: the next number in the sequence above is 21+34 = 55 Source:...

  • NOTE: explain the lines in comments for better understanding Write an assembly program (for x86 processors...

    NOTE: explain the lines in comments for better understanding Write an assembly program (for x86 processors - Irvine) that has two procedures, a main procedure and a procedure called Fib. The fib procedure is to uses a loop to calculate and printout the first N Fibonacci numbers. Fibonacci sequence is described by the following formula: Fib(1) = 1, Fib(2) = 1, Fib(n) = Fib(n – 1) + Fib(n – 2). The value of N is to be communicated to this...

  • 1.Take this recursive Fibonacci implementation and convert it into the caching based version discussed in class....

    1.Take this recursive Fibonacci implementation and convert it into the caching based version discussed in class. Implement your caching to store a maximum of 5 values. Create 2 variations: one that stores all values and one that only stores even values. Make sure that you don't leave any gaps in your cache — if you have 5 cache entries you must cache 5 unique and valid values. Compare the caching implementations to the recursive implementation using the time utility. How...

  • 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...

  • How do can I update this code (Code A): Code (A) #include using namespace std; int fibonacci(int n) { int a = 0,...

    How do can I update this code (Code A): Code (A) #include using namespace std; int fibonacci(int n) { int a = 0, b = 1, c; if (n <= 1) return n; for (int i = 2; i <= n; i++) { c = a + b; a = b; b = c; } return b; } int fibonacciRecursive(int n) { if (n <= 1) { return n; } return fibonacciRecursive(n-1) + fibonacciRecursive(n-2); } int main() { int n;...

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