- Commit
- 4d47f39a3b44b7e2f24e44bf6400337771e15c96
- Parent
- 1fde0a0bfe6073de9a2c38b9c7ee093312ba3aeb
- Author
- Gark Garcia <37553739+GarkGarcia@users.noreply.github.com>
- Date
Merge pull request #1 from Androthi/patch-1
Update PROGRAM.ASM
An exercise on polyglossy: the same problem solved on multiple languages
Merge pull request #1 from Androthi/patch-1
Update PROGRAM.ASM
1 file changed, 67 insertions, 35 deletions
Status | File Name | N° Changes | Insertions | Deletions |
Modified | x86/PROGRAM.ASM | 102 | 67 | 35 |
diff --git a/x86/PROGRAM.ASM b/x86/PROGRAM.ASM @@ -9,7 +9,10 @@ max dw 0 a dw 0 b dw 0 - + sumsAB dw 0 + sumsA dw 0 + sumsB 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: ($" @@ -89,7 +92,7 @@ read_loop: cmp cl, buffer[1] jbe short read_loop - mov [max], ax + mov max, ax ret invalid_input: @@ -128,56 +131,70 @@ invalid_input_end: iter: call test_num - inc [a] - mov ax, [a] - cmp ax, [max] + inc a + cmp ax, max jbe short iter call proved -; Iterate bx from 0 to ax + ; Iterate bx from a to max test_num: - mov [b], 0 + mov ax, a + mov b, ax + ;mov b, 0 test_loop: call test_pair cmp dx, 0 jne short disproved - inc [b] - - mov ax, [b] - cmp ax, [a] + inc b + mov ax, b + ;cmp ax, a + cmp ax, max jbe short test_loop ret test_pair: ; Calculate the a + b into cx - mov ax, [a] - add ax, [b] - - push ax ; Push a + b to the stack - - mov ax, [a] + mov ax, a + add ax, b + + call sum_digits ; calculate S(a+b) + mov sumsAB, bx + + ;push ax ; Push a + b to the stack + + mov ax, a call sum_digits ; Calculate S(a) into bx + mov sumsA, bx - mov ax, [b] ; Store the value of b in ax - push bx ; Push S(a) to the stack + mov ax, b ; Store the value of b in ax + ;push bx ; Push S(a) to the stack call sum_digits ; Calculate S(b) into bx - - pop ax ; Store S(a) in ax - add ax, bx ; Store S(a) + S(b) in ax - pop bx ; Store a + b in bx - push ax ; Push S(a) + S(b) to the stack - - mov ax, bx ; Store a + b in ax - call sum_digits ; Calculate S(a + b) into bx - - pop ax ; Store S(a) + S(b) in ax - sub bx, ax ; Calculate S(a + b) - (S(a) + S(b)) into bx - - - mov ax, bx ; Store S(a + b) - (S(a) + S(b)) in ax + mov sumsB, bx + + ;pop ax ; Store S(a) in ax + ;add ax, bx ; Store S(a) + S(b) in ax + ;pop bx ; Store a + b in bx + ;push ax ; Push S(a) + S(b) to the stack + ;mov ax, bx ; Store a + b in ax + + ;call sum_digits ; Calculate S(a + b) into bx + + ;pop ax ; Store S(a) + S(b) in ax + + + ; get diff in ax - calculate S(a+b) - S(a) - S(b) + mov ax, sumsAB + sub ax, sumsA + sub ax, sumsB + + ; are you sure you want to add (S(a) + S(b)) ?? + ;sub bx, ax ; Calculate S(a + b) - (S(a) + S(b)) into bx + + + ;mov ax, bx ; Store S(a + b) - (S(a) + S(b)) in ax mov cx, 9 ; Set the devident to 9 mov dx, 0 ; Clear the register where the rest will be stored div cx @@ -275,7 +292,23 @@ print_uint_loop: ja short print_uint_loop ret + ; print decimal value in ax, and a '.' to separate them. + ; for debug +print_dot_dec: + push bx + push cx + push dx + push ax + call print_uint + mov dx, '.' + int 21h + pop ax + pop dx + pop cx + pop bx + ret + quit: mov ax, 4c00h int 21h -end start- \ No newline at end of file +end start