Question: .386 Assembly Code: Given the following data segment where matrix1 and matrix2 represent square matrices of size n x n (n = 3 in the
.386 Assembly Code:
Given the following data segment where matrix1 and matrix2 represent square matrices of size n x n (n = 3 in the given case but it can be of any dimension) stored in row major order, write a program that multiply these two matrices and store the resultant matrix in resultantmatrix again in row major order. .data matrix1 dword 1,2,3,4,5,6,7,8,9 matrix2 dword 1,2,3,4,5,6,7,8,9 resultantmatrix 9 dup(?) Since the matrices can be of any dimension, you must write a procedure named squareroot to figure out the dimension by taking the square root of the length of array. To find square root, use method of repeated odd numbers subtraction. For scalar multiplication, use the multiply procedure developed in Problem 1. The arguments must be passed through stack and the answer must be returned in EAX register. Also make sure that the procedure must preserve the registers being used except the EAX register.
Square root procedure:
sqrt proc uses ecx edx
mov ecx, [esp+12]
mov eax, 0
mov edx, 1
startLoop:
sub ecx, edx
cmp ecx, 0
jl endLoop
inc eax
add edx, 2
jmp startLoop
endLoop:
ret 4
sqrt endp
Multiply Proceedure
Multiply proc uses ecx ebx
mov eax, 0
mov ebx, [esp+12]
mov ecx, [esp+16]
L1:
add eax, ebx
loop L1
ret 8
Multiply endp
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
