diff --git a/sumSquareDifference/main b/sumSquareDifference/main new file mode 100755 index 0000000..8cc25ef Binary files /dev/null and b/sumSquareDifference/main differ diff --git a/sumSquareDifference/main.c b/sumSquareDifference/main.c new file mode 100644 index 0000000..e134c66 --- /dev/null +++ b/sumSquareDifference/main.c @@ -0,0 +1,7 @@ +#include + +int func(); + +int main() { + printf("%d\n",func()); +} diff --git a/sumSquareDifference/main.s b/sumSquareDifference/main.s index 0f2dba2..802c29c 100644 --- a/sumSquareDifference/main.s +++ b/sumSquareDifference/main.s @@ -2,13 +2,42 @@ .section .text func: @ Find the difference between the sum of the squares and the square of the sum, for the first hundred numbers. -@ (a^2+b^2) = a^2 + b^2 + 2ab -@ Therefore, the difference must be 2ab +@ (a+b)^2 = a^2 + b^2 + 2ab +@ (a+b+c)^2 = a^2 + b^2 + c^2 + 2(ab +bc + ca) +@ Therefore, the difference must be 2(ab + ac + ad .... + bc + bd + be ... + cd + ce .....) +MOV R0,#0 +MOV R2,#1 @ 'a' from the equation above +MOV R3,#2 @ 'b' from the equation above +mainloop: +MUL R1,R2,R3 @ 'a' * 'b' - keep in mind we need to do this for all possible 2-number permutations in the sequence +ADD R0,R0,R1 @Add the result to R0, which will be returned +incr_b: +ADD R3,R3,#1 @ Increments 'b' +chk_b: +CMP R3,#100 @ If 'b' is less than or equal to 100, we continue the multiplication +BLE mainloop +incr_a: +ADD R2,R2,#1 @ Increments 'a' +new_b: @This is a way for me to store R2+1 into R3 +ADD R2,R2,#1 +MOV R3,R2 +SUB R2,R2,#1 + +chk_a: +CMP R2,#100 +BLT mainloop + + +mul2: +LSL R0,R0,#1 @Bitwise left shit by 1 - Multiplies by 2 + +return: +BX LR .section .data