the question is to write assembly program to calculate n!. n is in rdi, the result should be in rdx:rax. If the result can not be written in rdx:rax, the maximal number that fit in rdx:rax should be returned. In the link below is the correct answer. I only have a small question: why "ja 3f" and not simply "ja 3" in line 3, and why "ja 1b" in line 17 ? What is the meaning of "f" and "b" here?
factorial:
cmp rdi, 34
ja 3f
xor edx, edx // Result stored in rdx:rax
mov eax, 1
cmp edi, 1
jbe 2f
1: // Compute rdx:rax = rdx:rax * rdi
// New rdx: rdx*rdi + (rax*rdi >> 64)
// New rax: rax*rdi
mov rcx, rdi
imul rcx, rdx // First part of new rdx
mul rdi // New rax + second part of new rdx
sub edi, 1
add rdx, rcx // New rdx
cmp edi, 1
ja 1b // Break loop if edi <= 1
2: ret
3: mov rax, -1
mov rdx, -1
ret