with the following code I calculate first 30 elements of fibonacci sequence. Note that every two element of arr represent one element of the fibonacci sequence while the fibonnaci numbers after 26th element will need more than 2 byte to represent.
StSeg Segment STACK 'Stack'
DB 100H DUP (?)
StSeg Ends
DtSeg Segment
arr dw 62 dup (?)
the30 dd ?
DtSeg Ends
CDSeg Segment
ASSUME CS:CDSeg, DS:DtSeg, SS:StSeg
Start:
MOV AX, DtSeg ; set DS to point to the data segment
MOV DS,AX
; PROBLEM: STORE FIRST TWENTY ELEMENTS OF FIBONACCI IN AN ARRAY FROM MEMORY.
; SOLUTION:
mov bx, offset arr
add bx, 2
mov [bx], 00H
add bx, 4
mov [bx], 01H
; inited fibo[0] = 00000000H and fibo[1] = 00000001H
mov cx, 29; make while loop counts 29 times.
while:
;first part addition
mov ax, [bx]
mov dx, [bx-4]
add ax, dx
mov dx, 00H
jnc else
mov dx, 01H
; second part addition
else:
mov [bx+4], ax
mov ax, [bx-2]
add dx, [bx-6]
add ax, dx
mov [bx+2], ax
add bx, 4
loop while
MOV AH, 4CH
MOV AL, 0
INT 21H
CDSeg ENDS
END Start
my college assignment asks to store the 30th element in variable named the30 which DD but I do not know how is that even possible when all of the registers are 16 bits at most.
Is there any way to do that?