From: David Gow <david@ingeniumdigital.com>
Date: Mon, 7 Jul 2014 01:49:48 +0000 (+0800)
Subject: Clear the carry/borrow flag before add/sub
X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=319b6b36b1354e944e76246a093f103188746369;p=ipdf%2Fcode.git

Clear the carry/borrow flag before add/sub
---

diff --git a/src/add_digits_asm.s b/src/add_digits_asm.s
index 39f4af9..8144acc 100644
--- a/src/add_digits_asm.s
+++ b/src/add_digits_asm.s
@@ -9,6 +9,7 @@
 # Result in %rax is the final result in the carry flag
 # Exploits the fact that inc and dec do not affect the carry flag
 add_digits:
+	addq $0, %rax
 	loop:
 		movq (%rsi), %rax # Temporarily store digit from second array
 		adcq %rax, (%rdi) # Add digits in second and first array, store in first
diff --git a/src/sub_digits_asm.s b/src/sub_digits_asm.s
index 1a6ee3b..17d81c1 100644
--- a/src/sub_digits_asm.s
+++ b/src/sub_digits_asm.s
@@ -9,6 +9,7 @@
 # Result in %rax is the final result in the carry flag
 # Exploits the fact that inc and dec do not affect the carry flag
 sub_digits:
+	subq $0, %rax		# Reset the carry/borrow flag
 	loop:
 		movq (%rsi), %rax # Temporarily store digit from second array
 		sbbq %rax, (%rdi) # Subtract digits in second and first array, store in first