; ; CPE 221 Assembly Example ; ; This program counts the number of negative and positive values in an ; array and stores them in neg_count and pos_count, respectively ; AREA COUNT_NEG_POS, CODE, READONLY ENTRY ADR r10, nums ; pointer to first element of array LDR r1, size ; holds size of array LDR r2, i ; i = 0 LDR r3, =0 ; neg = 0 MOV r4, #0 ; pos = 0 loop CMP r2, r1 ; Check to see whether i < size. BPL store ; If not, done. ADD r5, r10, r2, LSL #2 ; Add index to base array pointer. LDR r5, [r5] ; Load nums[i] into r5. ADD r2, r2, #1 ; i++ CMP r5, #0 ; Set status bits ADDPL r4, r4, #1 ; pos++ ADDMI r3, r3, #1 ; neg++ B loop ; Go back to loop. store STR r3, neg STR r4, pos done B done size DCD 10 neg SPACE 4 pos SPACE 4 i DCD 0 nums DCD 5, 3, -1, 2, 4, 37, -100, 13, -5, 0 END