// DOTPROD Scalar Product of 3-vectors // This program will compute the scalar product // of two three-element vectors V and W. .data // Declare storage .align 8 // Desired alignment P: .skip 8 // Space for product V: data2 -1,+3,+5 // Vx, Vy, Vz W: data2 -2,-4,+6 // Wx, Wy, Wz .text // Section for code .align 32 // Desired alignment .global main // These three lines .proc main // mark the mandatory main: // 'main' program entry .body // Now we really begin... first: movl r14 = V;; // Pointer for V movl r15 = W;; // Pointer for W movl r16 = P;; // Pointer for P mov r20 = 0;; // R20 = running sum ld2 r21 = [r14],2;; // Get Vx; bump pointer ld2 r22 = [r15],2;; // Get Wx; bump pointer pmpy2.r r21 = r21,r22;; // Compute Vx times Wx sxt4 r21 = r21;; // Extend 32 bits to 64 add r20 = r20,r21;; // Update the sum ld2 r21 = [r14],2;; // Get Vy; bump pointer ld2 r22 = [r15],2;; // Get Wy; bump pointer pmpy2.r r21 = r21,r22;; // Compute Vy times Wy sxt4 r21 = r21;; // Extend 32 bits to 64 add r20 = r20,r21;; // Update the sum ld2 r21 = [r14],2;; // Get Vz; bump pointer ld2 r22 = [r15],2;; // Get Wz; bump pointer pmpy2.r r21 = r21,r22;; // Compute Vz times Wz sxt4 r21 = r21;; // Extend 32 bits to 64 add r20 = r20,r21;; // Update the sum st8 [r16] = r20;; // Store computed product // No more components... done: mov r8 = 0;; // Signal all is normal br.ret.sptk.many b0;; // Back to command line .endp main // Mark end of procedure