In: Computer Science
( Assembly Language )
Write a program that computes the 7th fibonacci number.
The fibonacci sequence -
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, …
what is the initialization of a, b, and d?
- |
a |
b |
d |
1 |
? |
? |
1 |
2 |
? |
? |
1 |
3 |
1 |
1 |
2 |
4 |
1 |
2 |
3 |
5 |
2 |
3 |
5 |
6 |
3 |
5 |
8 |
7 |
5 |
8 |
13 |
wrong initialization
- |
a |
b |
d |
1 |
0 |
1 |
1 |
2 |
1 |
1 |
2 |
3 |
1 |
2 |
3 |
4 |
2 |
3 |
5 |
5 |
3 |
5 |
8 |
6 |
5 |
8 |
13 |
7 |
8 |
13 |
21 |
the following statements are the body of the loop
a := b
b := d
d := a + b
your assembly language code begins here:
N dword 7
FibN dword ?
…
mov ecx, N
mov eax, 0
mov ebx, 1
toploop:
…
loop toploop
mov FibN, edx
.MODEL SMALL .DATA NUM_1 DB ? NUM_2 DB ? NUM_3 DB ? V1 DB ? V2 DB ? NL DB ' ', 0DH,0AH,'$' .CODE MAIN PROC MOV AX,@DATA MOV DX,AX MOV CX,10 MOV CH,0 MOV NUM_1,0 MOV NUM_2,1 MOV DL,NUM_1 OR DL,30H MOV AH,02H INT 21H MOV DL,NUM_2 OR DL,30H MOV AH,02H INT 21H L1: MOV AL,NUM_1 ADD AL,NUM_2 MOV AH,0 MOV BL,AL MOV DL,10 DIV DL ADD AX,3030H MOV V1,AL MOV V2,AH MOV DL,V1 MOV AH,02H INT 21H MOV DL,V2 MOV AH,02H INT 21H SHIFT: MOV AL,NUM_2 MOV NUM_1,AL MOV NUM_2,BL LOOP L1 MOV AX,4C00H INT 21H MAIN ENDP END MAIN ;********************************************* ; OUTPUT ;********************************************* ;0 1 1 02 03 05 08 13 21 34 55 89