Answered step by step
Verified Expert Solution
Link Copied!

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 FILL_ARRAY_LOOP IN MOV %RAX, (%R8) I DONT KNOW WHY HELP FIX PLS assignmemt provided in attached images------------------------------------
.section .data
seed:
.quad 0
.section .text
.global randint
.global fill_array
.global dot
.global dot_struct
# Function: uint64_t randint(void)
randint:
# Load the seed
mov seed(%rip),%rax
# Load constants into registers
movabs $6364136223846793005,%r8
movabs $1442695040888963407,%r9
# Compute new seed value
mul %r8 # %rax = seed *6364136223846793005
add %r9,%rax # %rax +=1442695040888963407
# Store new seed
mov %rax, seed(%rip)
# Return the new seed
ret
# Function: void fill_array(int64_t* array, uint64_t length)
fill_array:
# Save registers
push %rbp
mov %rsp,%rbp
mov %rdi, %r8 # array pointer
mov %rsi, %r9 # length
I GET THE ERROR SEGMENTATION ERROR IN LINE 51 WITHIN FILL_ARRAY_LOOP WHERE IT SAYS MOV %RAX, (%R8), HOW TO FIX?
.fill_array_loop:
test %r9,%r9
je .fill_array_done
# Generate random number
call randint
# Restrict to -128 to 127
and $0xff,%rax
sub $128,%rax
# Store in array
mov %rax, (%r8)
# Move to the next element
add $8,%r8
dec %r9
jmp .fill_array_loop
.fill_array_done:
# Restore registers
mov %rbp,%rsp
pop %rbp
ret
# Function: int64_t dot(int64_t* arr1, int64_t* arr2, uint64_t n)
dot:
# Save registers
push %rbp
mov %rsp,%rbp
mov %rdi, %r8 # arr1 pointer
mov %rsi, %r9 # arr2 pointer
mov %rdx,%r10 # length
xor %rax, %rax # accumulator
.dot_loop:
test %r10,%r10
je .dot_done
# Load elements from arr1 and arr2
mov (%r8),%r11
mov (%r9),%r12
# Multiply and accumulate
imul %r12,%r11
add %r11,%rax
# Move to the next elements
add $8,%r8
add $8,%r9
dec %r10
jmp .dot_loop
.dot_done:
# Restore registers
mov %rbp,%rsp
pop %rbp
ret
# Function: int64_t dot_struct(pair64_t* pairs, uint64_t n)
dot_struct:
# Save registers
push %rbp
mov %rsp,%rbp
mov %rdi, %r8 # pairs pointer
mov %rsi, %r9 # length
xor %rax, %rax # accumulator
.dot_struct_loop:
test %r9,%r9
je .dot_struct_done
# Load pair elements
mov (%r8),%r10 # load a
mov 8(%r8),%r11 # load b
# Multiply and accumulate
imul %r11,%r10
add %r10,%rax
# Move to the next pair
add $16,%r8
dec %r9
jmp .dot_struct_loop
.dot_struct_done:
# Restore registers
mov %rbp,%rsp
pop %rbp
ret
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

2nd Edition

1597499471, 978-1597499477

More Books

Students also viewed these Databases questions