What Is 0 ^ 0?

Quick questions:

What is 2 ^ 3? 8

What is 10 ^ 2? 100

What is 912873683428920348791239817231928370 ^ (200 – (40 * 5)) ? 1

Very good. It is an easy test, right? Yes indeed. OK let’s try another question: what is 0 ^ 0?

I repeat: what is 0 ^ 0?



Give up? OK. This time I’ll answer this question programmatically, not mathematically (there are several approach used to tackle this problems: limit, set theory, etc). Here’s the X86 assembly to outline the idea:

format PE console 4.0

include 'win32a.inc'

entry start

section '.data' readable executable
num1 dd 0
num2 dd 0
fmt db "%d",0

section '.code' code readable executable
mov ecx, [num1]
mov eax, [num2]
mov ebx, ecx

cmp eax, 1
jg multiply
je done

imul ecx, ebx
dec eax
jmp process

invoke printf, fmt, ecx
invoke ExitProcess, 0

section '.idata' import data readable writable
library kernel32,'kernel32.dll', msvcrt, 'msvcrt.dll'
import kernel32, ExitProcess, 'ExitProcess'
import msvcrt, printf, 'printf'

The output is, surprisingly (or not surprisingly) 0.

I expect careful readers to complain that I’m cheating, since the output of the code will always be 0.

No, I’m not cheating. May I suggest you to play with the code yourself? Probably you’ll be even more surprised :mrgreen: