Tuesday, September 10, 2013

PROcedures-The warning

On my previous post about procedures I showed you how to do several different operations or in other words a very long problem. Well there was a big problem with that..........REDUNDANCY!(see below)


mov ecx,3
mov ebx,4
call raiseToThePower
add total,eax

mov ecx,2
mov ebx,7
call raiseToThePower
add total,eax

Now the reason these 2 sections are redundant is because they are very similar,because if you look at it it all makes sense,both sections have 2 mov's then a call and last but certainly not least an add. The only things that are different between them are the numbers that are being moved,the 1st one has 3,and 4 and the 2nd one has 2,and 7.Now this equation isn't pretty but it get's worse when you do a program and you have several numbers so it's like evil Dr. Redundancy right there. Example:

        mov ecx,2
mov ebx,7
call raiseToThePower
add total,eax
mov ecx,3
mov ebx,5
call raiseToThePower
add total,eax
mov ecx,6
mov ebx,3
call raiseToThePower
add total,eax
mov ecx,9 1
mov ebx,2
call raiseToThePower
add total,eax

The problem we're trying to solve is 2^7+3^5+6^3+9^2. But look at all that redundant code!!!!!(I've highlighted the redundant code in different colors.)On my next post I'll show you how to fix this using arrays.

No comments:

Post a Comment