Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

SEGMENTATION ERROR I DONT KNOW WHY ASSEMBLY DEBUGGER SAYS THAT LINE IS WRONG. IMG PROVIDED . data seed: . quad 0 . text . global

SEGMENTATION ERROR I DONT KNOW WHY ASSEMBLY DEBUGGER SAYS THAT LINE IS WRONG. IMG PROVIDED
.data
seed:
.quad 0
.text
.global randint
randint:
movq seed(%rip),%rax
movabsq $6364136223846793005,%rbx
movabsq $1442695040888963407,%rcx
imulq %rbx
addq %rcx,%rax
movq %rax, seed(%rip)
ret
.global fill_array
fill_array:
movq %rsi, %rcx # rcx = number of elements
testq %rcx,%rcx
jz .done_fill
.fill_loop:
call randint
andq $0xff,%rax # limit to range -128 to 127
subq $128,%rax
movq %rax, (%rdi) # store in array
addq $8,%rdi # move to next element
loop .fill_loop
.done_fill:
ret
.global dot
dot:
xorq %rax, %rax
xorq %rcx,%rcx
.dot_loop:
cmpq %rdx,%rcx # compare rcx with length of arrays (rdx)
jge .done_dot
movq (%rdi,%rcx,8),%r8 # load elements from array 1
imulq (%rsi,%rcx,8) # multiply with corresponding element from array 2
addq %r8,%rax # accumulate result
incq %rcx # increment counter
jmp .dot_loop
.done_dot:
ret
.global dot_struct
dot_struct:
xorq %rax, %rax
xorq %rcx,%rcx
.struct_loop:
cmpq %rsi, %rcx # compare rcx with length of struct array (rsi)
jge .done_struct
movq (%rdi,%rcx,16),%r8 # load first element of struct pair
movq 8(%rdi,%rcx,16),%r9 # load second element of struct pair
imulq %r9,%r8 # multiply elements
addq %r8,%rax # accumulate result
incq %rcx # increment counter
jmp .struct_loop
.done_struct:
ret
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions