Answered step by step
Verified Expert Solution
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
labS: Assembler messages:
labS:: Error: operand type mismatch for add
intlabS:: Error: expecting scale factor of or : got
labS:: Error: expecting scale factor of or : got
seed: quad # Initialize seed with a value
section text
global randint
global fillarray
global dot
global dotpair
randint:
# Arguments: none
# Returns: Random number in rax
movq seedriprax # Load the seed value
movabsq $rbx # Load multiplier
imulq rbxrax # Multiply seed with multiplier
addq $rax # Add increment
movq rax, seedrip # Store the new seed value
ret
fillarray:
# Arguments:
# rdi: array pointer
# rsi: number of elements
pushq rbx
xorq rcxrcx # Initialize loop counter
fillloop:
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 $xffrax # Mask to keep the value within
subq $rax # Adjust to range to
movq rax, rdi,rcx # Store the value in the array
incq rcx # Increment the counter
jmp fillloop # 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 rcxrcx # Initialize loop counter
xorq rax, rax # Initialize dot product accumulator
dotloop:
cmpq rdxrcx # Compare counter with length
jge dotdone # If counter length, exit loop
movq rdi,rcxrbx # Load element from first array
imulq rsi,rcxrbx # Multiply with element from second array
addq rbxrax # Add to accumulator
incq rcx # Increment the counter
jmp dotloop # Repeat the loop
dotdone:
popq rbx
ret
dotpair:
# Arguments:
# rdi: pointer to array of structs pairt
# rsi: length of array
pushq rbx
xorq rcxrcx # Initialize loop counter
xorq rax, rax # Initialize dot product accumulator
dotpairloop:
cmpq rsi, rcx # Compare counter with length
jge dotpairdone # If counter length, exit loop
movq rdi,rcxrbx # Load a first bytes of struct
imulq rdi,rcxrbx # Multiply with b second bytes of struct
addq rbxrax # Add to accumulator
incq rcx # Increment the counter
jmp dotpairloop # Repeat the loop
dotpairdone:
popq rbx
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