asked 11.0k views
2 votes
a) 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). ( Use only one instruction ( Don't use the same way provided in activity 3 in lab 3.)(10 points) (b) Write a program that contains a definition of each of the following data types: BYTE, SBYTE, WORD, SWORD, DWORD, SDWORD, QWORD. Initialize each variable to a value that is consistent with its data type. (10 points) (c) Write an assembly program that finds the sum for the following array elements 10000 h,20000 h,30000 h,40000 h. All elements are of DWORD type

asked
User Haste
by
7.6k points

1 Answer

3 votes

Final answer:

a) Write a program to calculate the first seven values of the Fibonacci sequence using a loop. b) Write a program that defines and initializes variables of different data types. c) Write an assembly program to find the sum of the given array elements.

Step-by-step explanation:

a) Program to calculate Fibonacci sequence:



def fibonacci(n):
fib = [1,1]
for i in range(2, n):
fib.append(fib[i-1] + fib[i-2])
return fib

# Calculate the first 7 Fibonacci numbers
fib_sequence = fibonacci(7)

# Print the Fibonacci sequence
for num in fib_sequence:
print(num)



b) Program with definitions of data types:



byte_variable = 127
sbyte_variable = -128
word_variable = 32767
sword_variable = -32768
dword_variable = 2147483647
sdword_variable = -2147483648
qword_variable = 9223372036854775807

# Print the values of the variables
print(byte_variable)
print(sbyte_variable)
print(word_variable)
print(sword_variable)
print(dword_variable)
print(sdword_variable)
print(qword_variable)



c) Assembly program to find sum of array elements:



section .data
array dw 10000h, 20000h, 30000h, 40000h
array_size equ $ - array
sum dd 0

section .text
global _start

_start:
xor ecx, ecx
xor edx, edx

loop_start:
add edx, [array + ecx * 2]
inc ecx
cmp ecx, array_size / 2
jl loop_start

exit:
; sum is stored in edx
; add any necessary code to display or use the sum
mov eax, 1
int 0x80
answered
User Mufasa
by
8.2k points
Welcome to Qamnty — a place to ask, share, and grow together. Join our community and get real answers from real people.