Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

keep receiving errors, my code is provided below and assignment instructions lab 7 7 7 . S: Assembler messages: lab 7 7 7 . S:

keep receiving errors, my code is provided below and assignment instructions
lab777.S: Assembler messages:
lab777.S:17: Error: operand type mismatch for `add'
intlab777.S:83: Error: expecting scale factor of 1,2,4, or 8: got `16'
lab777.S:84: Error: expecting scale factor of 1,2,4, or 8 : got `16'
seed: .quad 1 # Initialize seed with a value
.section .text
.global randint
.global fill_array
.global dot
.global dot_pair
randint:
# Arguments: none
# Returns: Random number in %rax
movq seed(%rip),%rax # Load the seed value
movabsq $6364136223846793005,%rbx # Load multiplier
imulq %rbx,%rax # Multiply seed with multiplier
addq $1442695040888963407,%rax # Add increment
movq %rax, seed(%rip) # Store the new seed value
ret
fill_array:
# Arguments:
# rdi: array pointer
# rsi: number of elements
pushq %rbx
xorq %rcx,%rcx # Initialize loop counter
.fill_loop:
cmpq %rsi, %rcx # Compare counter with number of elements
jge .done # If counter >= number of elements, exit loop
call randint # Generate a random number
andq $0xff,%rax # Mask to keep the value within 0-255
subq $128,%rax # Adjust to range -128 to 127
movq %rax, (%rdi,%rcx,8) # Store the value in the array
incq %rcx # Increment the counter
jmp .fill_loop # Repeat the loop
.done:
popq %rbx
ret
dot:
# Arguments:
# rdi: pointer to first array
# rsi: pointer to second array
# rdx: length of arrays
pushq %rbx
xorq %rcx,%rcx # Initialize loop counter
xorq %rax, %rax # Initialize dot product accumulator
.dot_loop:
cmpq %rdx,%rcx # Compare counter with length
jge .dot_done # If counter >= length, exit loop
movq (%rdi,%rcx,8),%rbx # Load element from first array
imulq (%rsi,%rcx,8),%rbx # Multiply with element from second array
addq %rbx,%rax # Add to accumulator
incq %rcx # Increment the counter
jmp .dot_loop # Repeat the loop
.dot_done:
popq %rbx
ret
dot_pair:
# Arguments:
# rdi: pointer to array of structs (pair64_t)
# rsi: length of array
pushq %rbx
xorq %rcx,%rcx # Initialize loop counter
xorq %rax, %rax # Initialize dot product accumulator
.dot_pair_loop:
cmpq %rsi, %rcx # Compare counter with length
jge .dot_pair_done # If counter >= length, exit loop
movq (%rdi,%rcx,16),%rbx # Load a (first 8 bytes of struct)
imulq 8(%rdi,%rcx,16),%rbx # Multiply with b (second 8 bytes of struct)
addq %rbx,%rax # Add to accumulator
incq %rcx # Increment the counter
jmp .dot_pair_loop # Repeat the loop
.dot_pair_done:
popq %rbx
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

Practical Database Programming With Visual Basic.NET

Authors: Ying Bai

1st Edition

0521712351, 978-0521712354

More Books

Students also viewed these Databases questions