Given the n + 1 vertices x[0], y[0] .. x[N], y[N] of a simple polygon described in a clockwise direction, then the polygon's area can be calculated by:

abs( (sum(x[0]*y[1] + ... x[n-1]*y[n]) + x[N]*y[0]) -
     (sum(x[1]*y[0] + ... x[n]*y[n-1]) + x[0]*y[N])
   ) / 2
(Where abs returns the absolute value)

Task

Write a function/method/routine to use the the Shoelace formula to calculate the area of the polygon described by the ordered points:

     (3,4), (5,11), (12,8), (9,5), and (5,6) 



Show the answer here, on this page.




*        SHOELACE                  25/02/2019
SHOELACE CSECT
         USING  SHOELACE,R15       base register
         MVC    SUPS(8),POINTS     x(nt+1)=x(1); y(nt+1)=y(1)
         LA     R9,0               area=0
         LA     R7,POINTS          @x(1)
         LA     R6,NT              do i=1 to nt
LOOP     L      R3,0(R7)             x(i)
         M      R2,12(R7)            *y(i+1)
         L      R5,8(R7)             x(i+1)
         M      R4,4(R7)             *y(i)
         SR     R3,R5                x(i)*y(i+1)-x(i+1)*y(i)
         AR     R9,R3                area=area+x(i)*y(i+1)-x(i+1)*y(i)
         LA     R7,8(R7)             @x(i++)
         BCT    R6,LOOP            enddo
         LPR    R9,R9              area=abs(area)
         SRA    R9,1               area=area/2
         XDECO  R9,PG              edit area
         XPRNT  PG,L'PG            print area
         BR     R14                return to caller
NT       EQU    (SUPS-POINTS)/8    nt  number of points
POINTS   DC     F'3',F'4',F'5',F'11',F'12',F'8',F'9',F'5',F'5',F'6'
SUPS     DS     2F                 x(nt+1),y(nt+1)
PG       DC     CL12' '            buffer
         REGEQU
         END    SHOELACE