; ; sumabs.asm ; Douglas L. Jones ; University of Illinois at Urbana-Champaign ; November 28, 2012 ; ; (c) 2012 by Douglas L. Jones ; This work is made available according to the Creative Commons "Attribution" license ; http://creativecommons.org/licenses/by/3.0/ ; ; sumabs.asm: Computes the sum of the absolute value of an array of integers ; ; Notes: ; Register map: ; R0 sum being accumulated (sum) ; R1 temporary values (temp) ; R2 iteration counter (ii) ; R3 number of values to sum (- maxcount) ; R4 pointer to data in array (dpointer) ; ; ; .ORIG x2000 ; place program in memory starting at address x2000 LEA R4,data ; load pointer to first data memory location AND R0,R0,#0 ; set sum to zero AND R3,R3,#0 ; set R3 to -maxcount ADD R3,R3,#-10 ; " AND R2,R2,#0 ; set ii to zero loop ADD R1,R2,R3 ; test condition for end of loop: ii + (-maxcount) BRzp after ; loop conditional LDR R1,R4,#0 ; load next data value BRzp notneg ; negate the datum if negative NOT R1,R1 ; negate number ADD R1,R1,#1 ; " notneg ADD R0,R0,R1 ; sum = sum + |x[ii]| ADD R2,R2,#1 ; increment loop counter: ii = ii + 1 ADD R4,R4,#1 ; increment data pointer BR loop after ST R0,sum ; store result in memory TRAP x25 ; halt after completion data .FILL #3 ; data array to process .FILL #-12 .FILL #10 .FILL #0 .FILL #4 .FILL #-4 .FILL #0 .FILL #1 .FILL #2 .FILL #-1 sum .BLKW 1 .END