inline int Exponent(int n, int exp) 'an inlined C++ function called Exponent with two 32 bit integer arguments n and exp.
__asm { 'asm code starts here.
mov eax, n 'Stores n (32 bit integer) in eax (32 bit register). Similar to eax = n if done in VB.
mov ebx, n 'Stores n (32 bit integer) in ebx (32 bit register). Similar to ebx = n if done in VB.
'And the reason why we are storing n again is because later we are gonna want to multiply
'n = n * n in a loop so we can get an exponent going.
mov ecx, exp 'Stores exp in ecx. Similar to ecx = exp. This will be used as a counter.
'This is like an if statement. cmp stands for compare, and je stand for jump if the cmp
'statement equals. If the data in the ecx register equals 0 then jump to the retOne sub.
cmp ecx, 0
je retOne
'Similar to above only it checks if it's equal to 1 and jumps to retVal.
cmp ecx, 1
je retVal
'Here comes the loopstart sub
loopstart:
imul eax, ebx 'Multiplys the contents of eax and ebx. imul only multiplies integers. Similar to eax = eax * ebx.
dec ecx 'decrements the contents of ecx. Similar to ecx = ecx - 1. This is counting down.
'Another if statement, only this time jg stands for jump if greater than. If ecx > 1 then jump to the loopstart sub.
cmp ecx, 1
jg loopstart
'Of course if the if statement ends up false, it will skip the jg command and go on to the next line, which is this:
jmp retVal 'An unconditional jump. Similar to the Goto statement in VB and C++.
'This is the retOne sub.
retOne:
mov eax, 1 'Puts the value 1 in the eax register. Similar to eax = 1.
'This is the retVal sub. Used to help skip the above sub routine.
retVal:
}'asm code ends here
} 'And the function written in C++ automatically returns the value of eax.