Use the lea instruction to reduce number of "inc"s
authorDavid Gow <[email protected]>
Fri, 4 Jul 2014 13:47:33 +0000 (21:47 +0800)
committerDavid Gow <[email protected]>
Fri, 4 Jul 2014 13:47:33 +0000 (21:47 +0800)
src/tests/add_digits.s

index 09d4ea3..39f4af9 100644 (file)
@@ -16,23 +16,9 @@ add_digits:
                jz end_loop # We are done
                
                # Move to next element in the first array
-               inc %rdi
-               inc %rdi
-               inc %rdi
-               inc %rdi
-               inc %rdi
-               inc %rdi
-               inc %rdi
-               inc %rdi
+               leaq 8(,%rdi,1), %rdi
                # Move to next element in the second array
-               inc %rsi
-               inc %rsi
-               inc %rsi
-               inc %rsi
-               inc %rsi
-               inc %rsi
-               inc %rsi
-               inc %rsi
+               leaq 8(,%rsi,1), %rsi
                jmp loop # Repeat
        end_loop:
                movq $0, %rax

UCC git Repository :: git.ucc.asn.au