Here's a simple example I wrote using inline assembly in C, I've tested it in Visual Studio which uses Intel notation. I'm going to count in eax, which is the register used for function return values, all iterations of the loops (i.e. 100). ebx holds the i counter and ecx holds the j counter.
Be careful when you use these if you use them inline, ecx is used for the this reference inside objects and it's also used by mul and div. You can use whatever register you like or even the stack. I use xor to reset the counters since the xor operation is cheaper than a mov eax,0 operation.
#include <stdio.h>
int countLoops()
{
_asm
{
xor eax,eax
xor ebx,ebx
xor ecx,ecx
outer_loop :
cmp ebx,10
je final
add ebx,1
inner_loop:
cmp ecx,10
je reset_inner_loop
add ecx,1
add eax,1
jmp inner_loop
reset_inner_loop:
xor ecx,ecx
jmp outer_loop
final:
};
}
int main(void )
{
int numOfLoops = countLoops();
printf("%d\n", numOfLoops);
return 0;
}
This question has also been answered before here.