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