Você está na página 1de 3

EXPERIMENT NO: DOT PRODUCT USING ASSEMBLY PROGRAM CALLING AN ASSEMBLY FUNCTION AIM : To find dot product of two

array using assembly program calling an assembly function. THEORY: The sum of products of two arrays, each array with four numbers .The assembly program(main program), which initializes the two arrays of numbers and calls the assembly function, which takes the sum of products of the two arrays. It also sets a return address through register B3 and the result address to A0. The addresses of the two arrays and the size of the array are passed to the function through registers A4, A6, and B4, respectively. The result from the called function is sent back through A4. The resulting sum of the products is stored in memory whose address is result_addr. Register A0 serves as a pointer with the address result_addr.

PROCEDURE :
Create and build this project as dotp4a_init.asm and add the following files to the project. 1.dotp4a_init.asm : asm source file 2.dotp4afunc.asm : calling asm function 3.vectors.asm : vector file defining entry address init 4.c6xdsk.cmd :linker command file 5.Set a breakpoint at the first branch instruction. 6.Select view memory set address to result _addr . 7.Run execution stop at the breakpoint .The content in the memory address is zero. 8.Run again , the halt , verify the resulting sum A4=0x28(hex). 9.Ao contain the result address of result_addr. 10.viewregister core register verify the result and address in A4 and A0 respectively

Dotp4a_init.asm ASM program to init variables . Calls dotp4afunc

.def init .ref dotp4afunc .text .short 1,2,3,4 .short 0,2,4,6 .short 0 MVK result_addr,A4 MVK 0,A3 STH A3,*A4 MVK x_addr,A4 MVK y_addr,B4 MVK 4,A6 B dotp4afunc MVK ret_addr,b3 NOP 3 ret_addr MVK result_addr,A0 STW A4,*A0 B wait NOP 5

x_addr y_addr result_addr products init

;starting address ;called ASM function ;section for code ;numbers in x array ;numbers in y array ;initialize sum ;result addr -->A4 ;A3=0 ;init result to 0 ;A4 = address of x ;B4 = address of y ;A6 = size of array ;B to function dotp4afunc ;B3=return addr from dotp4a ;3 more delay slots(branch) ;A0 = result address ;store result ;wait here

wait

Dotp4afunc.asm FUNCTION .def dotp4afunc .text MV A6,A1 ZERO A7 accumulation ;dot product function ;text section ;move loopcount->A1 ;init A7 for

dotp4afunc

loop

LDH *A4++,A2 LDH *B4++,B2 NOP 4 MPY A2,B2,A3 NOP ADD A3,A7,A7

;A2=content of x address ;B2=content of y address ;4 delay slots for LDH ;A3 = x * y ;1 delay slot for MPY ;sum of products ;decrement loop counter ;branch back to loop till A1=0 ;5 delay slots for branch ;A4=result ;return from func to addr in B3 ;5 delay slots

in A7 SUB A1,1,A1 [A1] B loop NOP 5 MV A7,A4 B B3 NOP 5

Vector.asm MODIFIED FOR DEFINING THE STARTING ADDRESS init .ref init rst: .sect "vectors" mvkl .s2 init,b0 mvkh .s2 init,b0 b b0 nop 5 RESULT : The dotproduct of 2 arrays had heen computed ;starting addr in init file ;in section vectors ;init addr 16 LSB ->B0 ;init addr 16 MSB ->B0 ;branch to addr init

Você também pode gostar