Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ERROR IN ASSEMBLY CODE, ASIGNMENT, ERROR AND ASSIGNMENT PROVIDED lab 7 7 7 . S: Assembler messages: lab 7 7 7 . S: 1 5

ERROR IN ASSEMBLY CODE, ASIGNMENT, ERROR AND ASSIGNMENT PROVIDED
lab777.S: Assembler messages:
lab777.S:15: Error: operand type mismatch for `add'
.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 (This line is correct)
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
movb %al,(%rdi, %rcx) # 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,8),%rbx # Load a (first 8 bytes of struct)
imulq 8(%rdi, %rcx,8),%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

SQL Antipatterns Avoiding The Pitfalls Of Database Programming

Authors: Bill Karwin

1st Edition

1680508989, 978-1680508987

More Books

Students also viewed these Databases questions

Question

b. Why were these values considered important?

Answered: 1 week ago