Write a program that uses a loop to calculate the first seve

Write a program that uses a loop to calculate the first seven values of the Fibonacci number sequence described by the following formula: Fib(1) = 1, Fib(2) = 1, Fib(n) = Fib(n -1) +Fib(n-2). I need this program written in Assembly language. Use the comments in the program template as instructions to write the code in Assembly language. I would like the program to be written in Assembly language following this programming logic:

.data

;declare an array .

code main proc

;move 0 into ebx to initialize ;move 1 into edx to store the first Fib value ;move edx into an array ; store the first Fib value ; prepare to loop ; loop counter for 6 more values ; move esi,4 ; array index for 3rd Fib value

L1:

;move ebx into eax ;add edx and eax ;move edx into the array of esi ; eax = ebx ; eax = eax + edx ; store the Fib value ;move edx into ebx ; prepare for next iteration ;move eax into edx ;add 4 to esi ;

Loop L1

invoke ExitProcess,0

Solution

.file 1 \"\" .section .mdebug.abi32 .previous .gnu_attribute 4, 1 .abicalls .text .align 2 .globl _Z9fibonaccii $LFB0 = . .set nomips16 .ent _Z9fibonaccii .type _Z9fibonaccii, @function _Z9fibonaccii: .frame $fp,40,$31 # vars= 0, regs= 3/0, args= 16, gp= 8 .mask 0xc0010000,-4 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro addiu $sp,$sp,-40 $LCFI0: sw $31,36($sp) $LCFI1: sw $fp,32($sp) movz $31,$31,$0 $LCFI2: sw $16,28($sp) $LCFI3: move $fp,$sp $LCFI4: .cprestore 16 sw $4,40($fp) lw $2,40($fp) nop bne $2,$0,$L2 nop move $2,$0 b $L3 nop $L2: lw $3,40($fp) li $2,1 # 0x1 bne $3,$2,$L4 nop li $2,1 # 0x1 b $L3 nop $L4: lw $2,40($fp) nop addiu $2,$2,-1 move $4,$2 lw $2,%got(_Z9fibonaccii)($28) nop move $25,$2 jalr $25 nop lw $28,16($fp) move $16,$2 lw $2,40($fp) nop addiu $2,$2,-2 move $4,$2 lw $2,%got(_Z9fibonaccii)($28) nop move $25,$2 jalr $25 nop lw $28,16($fp) addu $2,$16,$2 $L3: move $sp,$fp lw $31,36($sp) lw $fp,32($sp) lw $16,28($sp) addiu $sp,$sp,40 j $31 nop .set macro .set reorder .end _Z9fibonaccii $LFE0: .size _Z9fibonaccii, .-_Z9fibonaccii .rdata .align 2 $LC0: .ascii \"Result: %d\\000\" .text .align 2 .globl main $LFB1 = . .set nomips16 .ent main .type main, @function main: .frame $fp,40,$31 # vars= 8, regs= 2/0, args= 16, gp= 8 .mask 0xc0000000,-4 .fmask 0x00000000,0 .set noreorder .cpload $25 .set nomacro addiu $sp,$sp,-40 $LCFI5: sw $31,36($sp) $LCFI6: sw $fp,32($sp) movz $31,$31,$0 $LCFI7: move $fp,$sp $LCFI8: .cprestore 16 li $4,6 # 0x6 lw $2,%got(_Z9fibonaccii)($28) nop move $25,$2 jalr $25 nop lw $28,16($fp) sw $2,24($fp) lw $2,%got($LC0)($28) nop addiu $4,$2,%lo($LC0) lw $5,24($fp) lw $2,%call16(printf)($28) nop move $25,$2 jalr $25 nop lw $28,16($fp) move $2,$0 move $sp,$fp lw $31,36($sp) lw $fp,32($sp) addiu $sp,$sp,40 j $31 nop .set macro .set reorder .end main $LFE1: .size main, .-main .section .eh_frame,\"aw\",@progbits $Lframe1: .4byte $LECIE1-$LSCIE1 $LSCIE1: .4byte 0x0 .byte 0x1 .globl __gxx_personality_v0 .ascii \"zP\\000\" .uleb128 0x1 .sleb128 -4 .byte 0x1f .uleb128 0x5 .byte 0x0 .4byte __gxx_personality_v0 .byte 0xc .uleb128 0x1d .uleb128 0x0 .align 2 $LECIE1: $LSFDE1: .4byte $LEFDE1-$LASFDE1 $LASFDE1: .4byte $LASFDE1-$Lframe1 .4byte $LFB0 .4byte $LFE0-$LFB0 .uleb128 0x0 .byte 0x4 .4byte $LCFI0-$LFB0 .byte 0xe .uleb128 0x28 .byte 0x4 .4byte $LCFI3-$LCFI0 .byte 0x11 .uleb128 0x10 .sleb128 3 .byte 0x11 .uleb128 0x1e .sleb128 2 .byte 0x11 .uleb128 0x1f .sleb128 1 .byte 0x4 .4byte $LCFI4-$LCFI3 .byte 0xd .uleb128 0x1e .align 2 $LEFDE1: $LSFDE3: .4byte $LEFDE3-$LASFDE3 $LASFDE3: .4byte $LASFDE3-$Lframe1 .4byte $LFB1 .4byte $LFE1-$LFB1 .uleb128 0x0 .byte 0x4 .4byte $LCFI5-$LFB1 .byte 0xe .uleb128 0x28 .byte 0x4 .4byte $LCFI7-$LCFI5 .byte 0x11 .uleb128 0x1e .sleb128 2 .byte 0x11 .uleb128 0x1f .sleb128 1 .byte 0x4 .4byte $LCFI8-$LCFI7 .byte 0xd .uleb128 0x1e .align 2
Write a program that uses a loop to calculate the first seven values of the Fibonacci number sequence described by the following formula: Fib(1) = 1, Fib(2) = 1

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site