On this post I'm going to show you how I refactored both the program from the previous post and the post before that one too. Refactoring is cleaning up and simplifying a program so that it's less headache to keep track of.
Here's the program from the previous post refactored:
extern "C" void doit();
void main()
{
doit();
}
.586
.model flat, c
.stack 100h
.data
myNumbers dword 7,3,8,2,2,9,8,5,7,4,8,3,8,1,8,7,4,8
.code
doit proc
xor eax,eax
mov ebx,myNumbers[eax]
again:
add eax,4
cmp myNumbers[eax],ebx
jge repeatIfNeccesary
mov ebx,myNumbers[eax]
repeatIfNeccesary:
cmp eax,68
jle again
ret
doit endp
end
The first thing I changed was that I got rid of ecx's involvement in the program,which seems kinda weird,but the reason I did it was because I realized I didn't need a register to represent myNumbers because myNumbers can represent itself. The second thing I changed was instead of jumping to switcheroo I put it in the loop and said jump greater than or equal to repeatIfNeccesary so instead of jumping to the part where we store the smallest number we jump past it if we currently don't need to do it.
Here's the program from the post before that one refactored:
extern "C" void doit();
void main()
{
doit();
}
.586
.model flat, c
.stack 100h
.data
myNumbers dword 7,3,8,2,2,9,8,5,7,4,8,3,8,13,8,7,4,8
.code
doit proc
xor eax,eax
xor ecx,ecx
again:
cmp myNumbers[eax],8
jne repeatIfNeccesary
add ecx,1
repeatIfNeccesary:
add eax,4
cmp eax,68
jle again
ret
doit endp
end
On this program I changed from jumping to CountingCounter to jumping past the instructions inside it if we currently don't need to use them just like in the other program.
WELL TTFN TA TA FOR NOW!!!!!!!
No comments:
Post a Comment