.TITLE ProductOfSums ; Calculates the product of the sums of two lists ; Algorithm: ; 1. Calculate sum of List1 ; 2. Calculate sum of List2 ; 3. Find Result, the product of the sums Length = 5 ; Number of elements in List ; Variables: Result: .BLKF 1 List1: .FLOAT 2.5, 2.113, 2.3, 1.23, 7.213 List2: .FLOAT 1.34, 12.32, 12.35, 4.26, 3.12 ; Argument list: ArgList2: .LONG 2 ; Number of arguments .LONG Length ; First argument, by value .ADDRESS List2 ; Address of second argument .ENTRY ProductofSums, 0 ; R3 <-- Sum(Length1, List) Start: PUSHAF List1 ; Push argument list in PUSHL #Length ; in reverse order CALLS #2, Sum ; Call function MOVF R0, R3 ; Save result in R3 ; R0 <-- Sum(Length2, List2) CALLG ArgList2, Sum ; Call function ; Result <-- R3 * R0 MULF3 R3, R0, Result Done: $EXIT_S ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * ; Function Sum (N, List) ; Argument list: ; Variable Offset Purpose Type Passed by N = 4; Number of values Longword Value List = 8; List of values Float Reference ; Register use: ; R0 Sum ; R1 Counter ; R2 Address of next item in List ; Algorithm: ; 1. Initialize the sum to 0, set up the counter and ; address of first element. ; 2. While counter > 0 do ; Add element to sum ; Decrement the counter .Entry Sum, ^M ; Initialize: CLRF R0 ; Set Sum to zero MOVL N(AP), R1 ; Copy value of N to R1 MOVL List(AP), R2 ; Copy address of List to R2 ; Calculate the sum: Loop: ADDF2 (R2)+, R0 ; Add value to Sum, ; incrementing the address DECL R1 ; Decrement counter by 1 BGTR Loop ; Repeat if not finished RET ; Finished, leave sum in R0 .END ProductOfSums