Answered step by step
Verified Expert Solution
Question
1 Approved Answer
SEGMENTATION ERROR IN FILL _ ARRAY _ LOOP IN MOV % RAX, ( % R 8 ) I DONT KNOW WHY HELP FIX PLS assignmemt
SEGMENTATION ERROR IN FILLARRAYLOOP IN MOV RAX, R I DONT KNOW WHY HELP FIX PLS assignmemt provided in attached images
section data
seed:
quad
section text
global randint
global fillarray
global dot
global dotstruct
# Function: uintt randintvoid
randint:
# Load the seed
mov seedriprax
# Load constants into registers
movabs $r
movabs $r
# Compute new seed value
mul r # rax seed
add rrax # rax
# Store new seed
mov rax, seedrip
# Return the new seed
ret
# Function: void fillarrayintt array, uintt length
fillarray:
# Save registers
push rbp
mov rsprbp
mov rdi, r # array pointer
mov rsi, r # length
I GET THE ERROR SEGMENTATION ERROR IN LINE WITHIN FILLARRAYLOOP WHERE IT SAYS MOV RAX, R HOW TO FIX?
fillarrayloop:
test rr
je fillarraydone
# Generate random number
call randint
# Restrict to to
and $xffrax
sub $rax
# Store in array
mov rax, r
# Move to the next element
add $r
dec r
jmp fillarrayloop
fillarraydone:
# Restore registers
mov rbprsp
pop rbp
ret
# Function: intt dotintt arr intt arr uintt n
dot:
# Save registers
push rbp
mov rsprbp
mov rdi, r # arr pointer
mov rsi, r # arr pointer
mov rdxr # length
xor rax, rax # accumulator
dotloop:
test rr
je dotdone
# Load elements from arr and arr
mov rr
mov rr
# Multiply and accumulate
imul rr
add rrax
# Move to the next elements
add $r
add $r
dec r
jmp dotloop
dotdone:
# Restore registers
mov rbprsp
pop rbp
ret
# Function: intt dotstructpairt pairs, uintt n
dotstruct:
# Save registers
push rbp
mov rsprbp
mov rdi, r # pairs pointer
mov rsi, r # length
xor rax, rax # accumulator
dotstructloop:
test rr
je dotstructdone
# Load pair elements
mov rr # load a
mov rr # load b
# Multiply and accumulate
imul rr
add rrax
# Move to the next pair
add $r
dec r
jmp dotstructloop
dotstructdone:
# Restore registers
mov rbprsp
pop rbp
ret
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started