diff --git a/x86/PROGRAM.ASM b/x86/PROGRAM.ASM
@@ -3,23 +3,28 @@
.stack 1000h
.data
- input db 22 DUP(0)
- invalid db "' is not a natural number!", 0dh, 0ah, 0dh, 0ah, "$"
-
- max dw 0
- a dw 0
- b dw 0
- sumAB dw 0
- sumA dw 0
- sumB dw 0
+ input db 22 DUP(0)
+ invalid db "' is not a natural number!", 0dh, 0ah, 0dh, 0ah, "$"
+
+ max dw 0
+ a dw 0
+ b dw 0
+ sumAB dw 0
+ sumA dw 0
+ sumB dw 0
+
+ start_time dw 0
+ end_time dw 0
- proof db 0dh, 0ah, "The conjecture is proved for all natural numbers smaller or equals to $"
- counter db 0dh, 0ah, "The conjecture is disproved! Here's a counterexample: ($"
+ proof db 0dh, 0ah, "The conjecture is proved for all natural numbers smaller or equals to $"
+ counter db 0dh, 0ah, "The conjecture is disproved! Here's a counterexample: ($"
+ loading db 0dh, 0ah, "LOADING. . .$"
+ loaded db 0dh, 0ah, "LOADED. . . in $"
- intro1 db 0dh, 0ah, "This program is a simple test for the following conjecture:", 0dh, 0ah, "$"
- intro2 db 0dh, 0ah, "Let S: N -> N be the sum of the digits of a positive integer.", 0dh, 0ah, "$"
- intro3 db "For all A and B in N, S(A + B) = S(A) + S(B) - 9k, where k is an integer.", 0dh, 0ah, "$"
- intro4 db 0dh, 0ah, "What value would you like to test the conjecture for? $"
+ intro1 db 0dh, 0ah, "This program is a simple test for the following conjecture:", 0dh, 0ah, "$"
+ intro2 db 0dh, 0ah, "Let S: N -> N be the sum of the digits of a positive integer.", 0dh, 0ah, "$"
+ intro3 db "For all A and B in N, S(A + B) = S(A) + S(B) - 9k, where k is an integer.", 0dh, 0ah, "$"
+ intro4 db 0dh, 0ah, "What value would you like to test the conjecture for? $"
.code
org 100h
@@ -39,8 +44,16 @@ start:
mov dx, offset intro4
int 21h
- ; Retrieve user input
- call read_uint
+ call read_uint ; Retrieve user input
+
+ ; Set the start_time variable
+ mov si, offset start_time
+ call get_time
+
+ mov ah, 9h
+ mov dx, offset loading
+ int 21h
+
call iter
read_uint:
@@ -145,7 +158,7 @@ test_num:
test_loop:
call test_pair
cmp dx, 0
- jne short disproved
+ jne disproved
inc b
mov ax, b
@@ -196,6 +209,8 @@ sum_loop:
ret
proved:
+ call print_time
+
mov ah, 9h
mov dx, offset proof
int 21h
@@ -270,8 +285,60 @@ print_uint_loop:
ja short print_uint_loop
ret
-; Print decimal value in ax, and a '.' to separate them.
-; @Debug
+print_time:
+ ; Set the end_time variable
+ mov si, offset end_time
+ call get_time
+
+ mov ah, 9h
+ mov dx, offset loaded
+ int 21h
+
+ ; Print the elepsed time in milliseconds
+ mov ax, end_time
+ sub ax, start_time
+ mov cx, 10
+ mul cx
+ call print_uint
+
+ ; Print 'ms\n'
+ mov ah, 2h
+ mov dx, 'm'
+ int 21h
+ mov dx, 's'
+ int 21h
+ mov dx, 0ah
+ int 21h
+ ret
+
+; Gets the current minute in centiseconds and stores it in [si]
+get_time:
+ ; Get system time
+ mov ah, 2ch
+ int 21h
+
+ ; Add the minutes
+ mov ax, 0
+ mov al, ch
+ mov bx, 6000
+ mul bx
+ mov [si], ax
+
+ ; Add the seconds
+ mov ax, 0
+ mov al, dh
+ mov bx, 100
+ mul bx
+ add [si], ax
+
+ ; Add the centiseconds
+ mov ax, 0
+ mov al, dl
+ add [si], ax
+
+ ret
+
+; Print decimal value in ax, and a '.' to separate them. This was created for debugging porposes.
print_dot_dec:
push bx
push cx