I like little challenges like these on occasion. I took this particular occasion to translate your C example into NASM-X. I've obtained the expected results: length=119 and 97 is the number that generates it.
I've provided the outline and assembler logic to implement the algorithm in 32-bit mode. It should be easy for you at this point to convert it into pure 16-bit nasm. I've placed the C code in comments next to the assembly code which should make it easy for you to understand. I would expect a C compiler to generate something "almost" similar if optimizations not enabled. Take it and run with it!
%include 'nasmx.inc'
IMPORT printf
[section .text]
ENTRY my_main
PROC my_main, dword argc, ptrdiff_t cmdline ; int main(int argc, char *argv[])
; {
LOCALS ; int l = 1, lTemp = 1, GdNbre = 0;
LOCAL l, dword, 1
LOCAL lTemp, dword, 1
LOCAL GdNbre, dword, 1
ENDLOCALS
mov eax, 1
mov dword [var(.l)], eax
mov dword [var(.lTemp)], eax
xor eax, eax
mov dword [var(.GdNbre)], eax
INVOKE printf, announce_msg ; cout << "Conjoncture d'Ulam" << endl;
mov ecx, 2
WHILE ecx,<=,100 ; for (int i(2); i <=100; i++)
; {
push ecx ;
mov eax, ecx ; int N = i;
WHILE eax,!=,1 ; while (N != 1)
; {
mov edx, eax
and eax, 1
jnz .isodd ; if (N%2 == 0)
mov eax, edx
shr eax, 1 ; N /= 2;
jmp .increment
.isodd: ; else
mov eax, edx ; N = (3*N)+1;
mov ecx, 3
mul ecx
inc eax
.increment:
mov edx, dword [var(.l)] ; l++;
inc edx
mov dword [var(.l)], edx
ENDWHILE ; }
pop ecx
mov edx,dword [var(.lTemp)]
mov eax,dword [var(.l)]
IF edx,<,eax ; if ( lTemp < l )
; {
mov dword [var(.lTemp)], eax ; lTemp = l;
mov dword [var(.GdNbre)], ecx ; GdNbre = i;
ENDIF ; }
mov dword [var(.l)], 1 ; l = 1;
inc ecx
ENDWHILE ; }
; cout << "Longueur: " << lTemp << endl;
INVOKE printf, longuer_msg, dword [var(.lTemp)]
; cout << "Et le nombre qui le génère est: " << GdNbre << endl;
INVOKE printf, genere_msg, dword [var(.GdNbre)]
; return 0;
ENDPROC ; }
[section .data]
announce_msg: db 'Conjoncture d Ulam',0xa,0
longuer_msg: db 'Longueur: %d',0xa,0
genere_msg: db 'Et le nombre qui le génère est: %d',0xa,0