.ORIG x3000 msg .STRINGZ "This is a small test!" char .STRINGZ "i" ; reset to zero and r0, r0, x0 ; r0 is the matching character and r2, r2, x0 ; r2 is the offset into the string and r7, r7, x0 ; r7 is the total number of occurances (in the end) ; initializiation lea r0, char ldr r0, r0, x0 ; r0 <- character 'i' lea r1, msg ; r1 <- address of msg loop ; load char in r5 add r4, r1, r2 ; r4 <- current offset ldr r5, r4, x0 ; r5 <- current character ; bail out of the loop if zero is found brz end ; compare if r5 equal to r0, using r6 as a temporary register not r6, r5 and r6, r6, r0 brnp skip ; increment count add r7, r7, x1 skip ; increment offset add r2, r2, x1 brnzp loop end halt .END