Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;int mat_mult(int * mat1, int * mat2, int * mat3, int mat1row, int mat1col, int mat2row, int mat2col){
- ;;mat_mult_asm( mata, matb, matc,matarow, matacol, matbrow, matbcol);
- segment .txt
- global mat_mult_asm
- mat_mult_asm: enter 18h,0
- ;mov ezx, [ebp-04h] ;; i1 storage
- ;mov ezx, [ebp-08h] ;; i2 storage
- ;mov ezx, [ebp-0Ch] ;; mat3 size
- ;mov ezx, [ebp-10h] ;; X
- ;mov ezx, [ebp-14h] ;; Y
- ;mov esp, [ebp-18h] ;; esp location for pushpops
- ;mov ezx, [ebp+08h] ;; arg 1 mat1 pointer
- ;mov ezx, [ebp+0Ch] ;; arg 2 mat2 pointer
- ;mov ezx, [ebp+10h] ;; arg 3 mat3 pointer
- ;mov ezx, [ebp+14h] ;; arg 4 mat1 rows
- ;mov ezx, [ebp+18h] ;; arg 5 mat1 cols
- ;mov ezx, [ebp+1Ch] ;; arg 6 mat2 rows
- ;mov ezx, [ebp+20h] ;; arg 7 mat2 cols
- ;; 0 EAX [???] running product goes here
- ;; 1 EBX [???] running sum of products goes here
- ;; 2 ECX [???] i1 counter & i2 counter & X & Y, X & Y will also have memory
- ;; 3 EDX [???] register to mul by ;; mul edx
- ;; 4 ESI [???] mat1 pointer
- ;; 5 EDI [???] mat3 pointer ;; will be permanently incremented
- ;; 6 EBP [DNC] ;; dear Paloma: DO NOT change
- ;; 7 ESP [???] mat2 pointer
- mov [ebp-18h], esp ;; storing esp value in case
- mov eax, [ebp+14h]
- mov ebx, [ebp+20h]
- mul ebx ;; could possible be simplified, will leave as is for now
- mov [ebp-0Ch], eax ;; total size of mat3
- mov eax, 00000000h ;; initialize
- mov [ebp-04h], eax ;; i1 storage //i<mat1row*mat2col
- ;mov [ebp-08h], eax ;; i2 storage
- mov esi, [ebp+08h] ;; mat1
- mov esp, [ebp+0Ch] ;; mat2
- mov edi, [ebp+10h] ;; mat3
- ;; X=(i1/mat2col)*mat1col+i2; Y=i2*mat2col+i1%mat2col
- ;mov eax, [ebp-04h] ;; load i1
- i1_loop: mov ecx, eax ;; copy i1 into ecx
- mov ebx, [ebp+20h] ;; load mat2col
- div ebx ;; eax = i1/mat2col ;; don't exceed 255 then
- ;; this part right here, gives me a wrong answer, it's this stupid DIV operation that I've spent all night on
- ;; I'm about ready to give up on DIV, here's what I know:
- ;; DIV [8bit] stores the quotient in al & the remainder in ah
- ;; DIV [16bit or 32bit] stores the quotient in ax/eax & remainder in dx/edx. how annoying is that?
- ;; on top of that, I am not even getting the right quotient & it is screwing everything up. I give up for the night
- ;; I'm going to bed. Sorry Paloma. Feel free to turn this assgnt in, but just know that each product from the second
- ;; row on down is incorrect because the mata & matb values being fetched (although within the respective matrix)
- ;; are the wrong indexes. all I wanted was: floor(i1/mat2col)
- mov edx, [ebp-04h] ;;BUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUG
- cmp edx, 2
- jge bug_done ;;BUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUG
- bug_not_done:
- mov edx, [ebp+14h] ;; load mat1col
- mul edx ;; eax = (i1/mat2col)*mat1col done with the i1 part
- mov [ebp-10h], eax ;; store i1 part of X
- ;; i1 dividend
- int_modulus: cmp ecx, ebx ;; you CANNOT, under any condition, put 0 into the divisor
- jl modu_done
- sub ecx, ebx
- jmp int_modulus
- modu_done: mov [ebp-14h], ecx ;; storing i1 part of Y
- mov ebx, 00000000h ;; initialize sum of producs
- mov [ebp-08h], ebx ;; set i2 to 0
- i2_loop:
- mov ecx, [ebp-10h] ;; load X
- mov eax, [esi+04*ecx] ;; load mat1 index X
- inc ecx ;; increment X by 1
- mov [ebp-10h], ecx ;; store next X
- mov ecx, [ebp-14h] ;; load Y
- mov edx, [esp+04*ecx] ;; load mat2 index Y
- add ecx, [ebp+20h] ;; increment Y by mat2col
- mov [ebp-14h], ecx ;; store Y
- mul edx ;; eax = eax*edx
- add ebx, eax ;; add product to running sum of products
- mov eax, [ebp-08h] ;; load i2
- inc eax ;; increment i2
- mov [ebp-08h], eax ;; store i2
- cmp eax, [ebp+18h] ;; compare i2 to mat 1 columns
- je i2_done ;; done with the running sum of products
- jmp i2_loop ;; repeat the i2_loop
- i2_done:
- mov [edi], ebx ;; store ebx(sum of products) to mat3pointer(edi)
- mov eax, [ebp-04h] ;; load eax i1
- inc eax ;; inc i1
- mov [ebp-04h], eax ;; store i1
- add edi, 00000004h ;; increment mat3pointer by sizeof(int)
- cmp eax, [ebp-0Ch] ;; compare i1 to mat3size ;; i1 already in eax here
- jge mat_done ;; if we got size, we done
- jmp i1_loop ;; jump i1 loop
- mat_done:
- mov eax, edx ;;BUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUG
- leave
- ret
- bug_done: ;;BUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGBUGvBUGBUG
- ;mov edx, [ebp-08h]
- ;cmp edx, 0
- ;jl bug_not_done
- jmp mat_done
Advertisement
Add Comment
Please, Sign In to add comment