; ;; Program to compute the dot product of two vectors, which are inteleaved ;; in memory. ;; ; ;out: .equ 0 ;dim: .equ 1 ;veca: .equ 2 ;vecb: .equ 3 ; 0x100 ; .text 0x030203020101 ;0x0100 main: subge i,i,next 0x000000000102 ;0x0101 subge out,out,next 0x030303030103 ;0x0102 loop: subge tmp,tmp,next ; i < dim, so i-dim < 0 ; ; or not i-dim >= 0 0x030403040104 ;0x0103 subge tmp2,tmp2,next 0x030403020105 ;0x0104 subge tmp2,i,next 0x030303040106 ;0x0105 subge tmp,tmp2,next 0x030300010116 ;0x0106 subge tmp,dim,done ; 0x030303030108 ;0x0107 subge tmp,tmp,next 0x030903090109 ;0x0108 subge x,x,next 0x03030002010a ;0x0109 A0: subge tmp,veca,next 0x03090303010b ;0x010a subge x,tmp,next ; 0x03030303010c ;0x010b subge tmp,tmp,next 0x030a030a010d ;0x010c subge y,y,next 0x03030003010e ;0x010d A1: subge tmp,vecb,next 0x030a0303010f ;0x010e subge y,tmp,next ; 0x010903000110 ;0x010f subge A0,nextElt,next 0x010d03000111 ;0x0110 subge A1,nextElt,next ; .text ; 0x012001200112 ;0x0111 subge negMultRet,negMultret,next 0x012003010113 ;0x0112 subge negMultRet,L0,next 0x030303030119 ;0x0113 subge tmp,tmp,negMult ;0x0114 L1: ; .text ; 0x000003080115 ; subge out,negProd,next 0x030203070102 ;0x0115 subge i,neg1,loop ; assume never overflow ; 0x030303030116 ;0x0116 done: subge tmp,tmp,done ; done w/ loop, 0x000000000000 ;0x0117 .word 0 0x000000000000 ;0x0118 .word 0 ; ; ; .text 0x030b030b011a ;0x0119 negMult: subge xx,xx,next 0x030b0309011b ;0x011a subge xx,x,next ; xx = -x 0x03080308011c ;0x011b subge negProd,negProd,next ; negProd = 0 ; ; ; ; loop invariant: -x y = negProd + xx * y ; ; 0x030b03060120 ;0x011c multLoop: subge xx,zero,negMultRet ; xx = xx + 0 ; ; = -x + 0 >= 0 ; ; or 0 >= x. 0x0308030a011e ;0x011d subge negProd,y,next ; negProd = negProd - y 0x030b0307011f ;0x011e subge xx,neg1,next ; xx = xx + 1 0x03030303011c ;0x011f subge tmp,tmp,multLoop ; ; ; ; exit when xx = 0, so invariant tells us that ; ; -x y = negProd + 0 * y = negProd ; ; which is the desired return value ; ; 0x000000000000 ;0x0120 negMultRet: .word 0,0,0 ; negProd = -(x * y)