| | |
C++ to ASM
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2005
Posts: 15
Reputation:
Solved Threads: 0
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..
And here is the ASM code I hope this is the right place where people know how to program in ASM??
C++ Syntax (Toggle Plain Text)
#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??
C++ Syntax (Toggle Plain Text)
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)
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...
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)
C++ Syntax (Toggle Plain Text)
mov eax, tmpA mov eax, CO[esi]
And I have no idea about the included functions, do they preserv all registers, what arguments do they take, and so on...
/pern.*/i
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. Albert Einstein
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. Albert Einstein
C++ Syntax (Toggle Plain Text)
int CO[0] = { 0 };
![]() |
Similar Threads
- intergrating ASM to C++ (C++)
- ASM Game Coding Problem/Question (Assembly)
- Starting ASM (Assembly)
- My Sample ASM Code (Assembly)
- asm in C (C++)
Other Threads in the C++ Forum
- Previous Thread: Easy Polymorphism Q Part 2 :)
- Next Thread: I guess it's a question about a loop
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library lines linker list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






