I have a problem i have a fully operational C++ code that works but when i convert it to ASM (assembly) code it doesnt work I dont know where I am going wrong but here are both codes..

#include <iostream>
using namespace std;

int main()
{
       int n, tmpA, tmpB
       int CO[0] = { 0 };
cin >> n;
CO[0] = 1;

for( int = 2; i < (n + 3); i++)
{
     tmpB = CO[k] + CO[k + 1];
     CO[k] = tmpA;
     cout << " " << tmpA;
     tmpA = tmpB;
}
cout  << endl;
}
return 0;
}

And here is the ASM code I hope this is the right place where people know how to program in ASM??

TITLE Combinatorial Coefficents
INCLUDE Irvine32.inc

.data
CO DWORD 40 DUP(0)
mystr1 BYTE "Please enter a positive number from 1 to 40: ", 0

i DWORD ?
k DWORD ?
n DWORD ?
tmpA DWORD ?
tmpB DWORD ?
.code 
main PROC
mov edx, OFFSET mystr1
call WriteString
call CrLf

call ReadInt
mov n, eax
mov ebx, CO[0] 
mov ebx, 1

    
 
LL:  
    mov  edx, 2  ; i = 2
    add  n, 3  ; n + 3 
    cmp edx, n
    jae QX
          
    
    mov tmpA, 1 ; tmpA = 1
    
    
       
LX: 
     mov k, 0
                                    ;mov edx, i
    dec edx ; i - 1
    cmp k, edx
    jae QX
    
    mov esi, OFFSET CO
    shl esi, 2
    
    mov ebx, CO[esi]
    add ebx, CO[esi + 4]
    mov eax, tmpA
    mov eax, CO[esi]
                                     ;mov tmpA, eax
                                     ;mov eax, tmpA 
    call WriteDec
    call CrLf
    mov eax, ebx
                                     ; mov tmpA, eax
    inc k
    inc edx
    jmp LL
    


    
    
   
    



   
QX:

exit
main ENDP
END main

IANAAP (I Am Not An Assember Programmer) but, some thoughts:
Feels like there is as many ways to write assembler as there are assemblers thought... What is the problem ?

Argh, whats up with the k variable in the c++ example (not declared) ? and counting goes in different directions (down in asm, up in c++)
What you do seem to be doing is to set edx to 2 and count down to zero, that cant be right... (Edit seems you are counting both edx and k up at the end, first edx - 1 + 1 each round, and k = 0 + 1 each round... I got a head ache right now so now I'll stop reading this)
Even worse you loop through the loop initation all the time (LL)...
(this looks odd)

mov eax, tmpA
    mov eax, CO[esi]

And where did the swap/save between tmpA and tmpB go ?

And I have no idea about the included functions, do they preserv all registers, what arguments do they take, and so on...

int CO[0] = { 0 };

The above is not a valid array -- its an array of 0 elements. that means "CO[0] = 1;" will produce undefined behavior because CO[0] does not exist.

thanks for taking an intrest in the code, but i went to my teacher and i actually figured it out again thank you for taking an intrest

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.