Browse Source

fixed a bug: use unsigned comparison instead of the signed one

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@6475 8c9fc860-2736-0410-a75d-ab315db34111
eth.morozova 9 years ago
parent
commit
af47e7c2d4
1 changed files with 12 additions and 5 deletions
  1. 12 5
      source/ARM.ARMRuntime.Mod

+ 12 - 5
source/ARM.ARMRuntime.Mod

@@ -130,7 +130,7 @@ TYPE
 	(*
 		Fast 32-bit unsigned integer division/modulo (author Alexey Morozov)
 	*)
-	PROCEDURE DivModU32(dividend, divisor: ULONGINT; VAR quotient, remainder: ULONGINT);
+	PROCEDURE DivModU32*(dividend, divisor: ULONGINT; VAR quotient, remainder: ULONGINT);
 	CODE
 		MOV R2, #0 ; quotient will be stored in R2
 
@@ -139,8 +139,9 @@ TYPE
 
 		; check for the case dividend < divisor
 		CMP R0, R1
-		BLT Exit ; nothing to do than setting quotient to 0 and remainder to dividend (R0)
-
+		BEQ Equal
+		BLS Exit ; nothing to do than setting quotient to 0 and remainder to dividend (R0)
+	
 		CLZ R3, R0 ; R3 := clz(dividend)
 		CLZ R4, R1 ; R4 := clz(divisor)
 
@@ -156,12 +157,18 @@ TYPE
 		BPL Loop
 
 		; R0 holds the remainder
-
+		
+		B Exit
+		
+	Equal:
+		MOV R2, #1
+		MOV R0, #0
+		
 	Exit:
 		LDR R1, [FP,#quotient] ; R1 := address of quotient
 		LDR R3, [FP,#remainder] ; R3 := address of remainder
 
-		STR R2, [R1,#0] ; quotient := R1
+		STR R2, [R1,#0] ; quotient := R2
 		STR R0, [R3,#0] ; remainder := R0
 	END DivModU32;