Assembly Language fibonacci.asm - computes the following. a. Compute fib(n) for
ID: 3669802 • Letter: A
Question
Assembly Language
fibonacci.asm
- computes the following.
a. Compute fib(n) for n = 2, 3, …, 6 using an array.
b. Store each computed value in an array of the appropriate size and type.
c. Store fib(3) through fib(6) in consecutive bytes of the ebx register starting from the lowest byte; that is, fib(3) is stored in the low byte (bl) of ebx, fib(4) is stored in the next byte (bh), fib(5) is stored in the next byte of ebx and fib(6) is stored in the highest byte.
d. If you don’t know what the Fibonacci sequence is, there is a lot of information online that you can find.
Notes
1. Assume fib(0)=0, fib(1)=1.
2. You may use any instruction/directive/operator through chapter 4 pg 128, including any of the arithmetic operators +, *, /, -.
3. Your program must use indirect operands in some way as discussed in chapter 4.
4. Your program must make one call to DumpRegs before quitting to display the ebx register.
Indirect Operand
• Can be any 32-bit general purpose register
– Surrounded by brackets
• The register is assumed to contain the address of some data
Here is the example for Indirect Operand
.data
byteval BYTE 10h
.code
mov esi, OFFSET byteval
mov al, [esi] ; al = 10h
mov [esi], al
Explanation / Answer
First we will wirte c language program to get clear idea .. exact meaning of assembly program
C code
#include<stdio.h>
int main()
{
int n=5, two = 1, temp, i;
printf("Fibonnaci series are: ");
for ( i = 0 ; i < n ; i++ )
{
if ( i <= 1 )
temp = i;
else
{
temp = one + two;
> two = temp;
}
printf("%d ",temp);
}
return 0;
}
Assembly code:
.LC0:
.ascii "Fibonnaci series are: "
.LC1:
.ascii "%d
"
main:
push {r7, lr}
sub sp, sp, #24
add r7, sp, #0
mov r3, #5
str r3, [r7, #4]
mov r3, #0
str r3, [r7, #20]
mov r3, #1
str r3, [r7, #16]
movw r0, #:lower16:.LC0
movt r0, #:upper16:.LC0
bl printf
mov r3, #0
str r3, [r7, #8]
b .L2
.L5:
ldr r3, [r7, #8]
cmp r3, #1
bgt .L3
ldr r3, [r7, #8]
str r3, [r7, #12]
b .L4
.L3:
ldr r2, [r7, #20]
ldr r3, [r7, #16]
adds r3, r2, r3
str r3, [r7, #12]
ldr r3, [r7, #16]
str r3, [r7, #20]
ldr r3, [r7, #12]
str r3, [r7, #16]
.L4:
movw r0, #:lower16:.LC1
movt r0, #:upper16:.LC1
ldr r1, [r7, #12]
bl printf
ldr r3, [r7, #8]
add r3, r3, #1
str r3, [r7, #8]
.L2:
ldr r2, [r7, #8]
ldr r3, [r7, #4]
cmp r2, r3
ite ge
movge r3, #0
movlt r3, #1
uxtb r3, r3
cmp r3, #0
bne .L5
mov r3, #0
mov r0, r3
add r7, r7, #24
mov sp, r7
pop {r7, pc}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.