|
Well, doing the looping in assembler isn't that hard, and here's a tip: to see how to do new things in assembler, just write what you want in C++, run it in the debugger with a breakpoint on the first line, right-click and select "View Disassembly". Then you can see what the compiler does. But anyways, here's how to do a basic loop in inline assembler (x86):
int main( int argc, char * argv[] )
{
int i = 0;
int j = 1;
__asm
{
mov i, 0
loopstart:
cmp i, 5
jge loopend
mov eax, [dword ptr j]
imul eax, 2
mov [dword ptr j], eax
inc i
jmp loopstart
loopend:
}
return 0;
}
Anyways, the other guys are probably right. Don't try to optimize what you don't need to, but if you are just curious about assmebly, then by all means keep learning. I just wanted to actually answer your question.
Chris Richardson
|
|
|
|
|
Thankyou very much, I wanted to see which one would be faster just for fun since I never got to learning assembler and would just see if I would have missed anything but I guess not, I just wanted to see for real if assembler was as fast as it was supposed to, thankyou for taking the time to answer the question. :p
Old United Airlines Brochure:
If you cannot read this please ask a superintendent to help you... LOL, for real!!!
|
|
|
|
|
Snyp wrote:
I just wanted to see for real if assembler was as fast as it was supposed to, thankyou for taking the time to answer the question
The endl is certainly the problem, as has been said. I just wanted to add that ALL code is assembler, it just gets generated by the compiler. So it's only faster when a human can write assembler better than the compiler can.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
How can you make a start up program?? I just don't know where to start...
Old United Airlines Brochure:
If you cannot read this please ask a superintendent to help you... LOL, for real!!!
|
|
|
|
|
Hmm..
I can't really understand what you mean. If you want to create a program that runs automatically at start-up, you just build the program and add it's shorcut to the 'Startup' folder of your Start->Programs.
Alternatively you can write a registry entry to HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run. See the example entries in that key and create a new key for your program.
If you are planning to create a Win32 service, which starts on an NT/2k/XP (or networked 98/Me) machine before the user logs in, then I can point you to a starting location. The easiest way is to follow the guidelines of Xiangyang Liu's article Start Your Windows Programs From An NT Service[^]
Otherwise, you might want to look up other articles in the MFC/C++->System->Services section of CodeProject.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
No I'm trying to make a startup manager program. You know a program to manage which program starts up and which doesn't, I know you do this through the registry though and the startup folder in the main menu.
Old United Airlines Brochure:
If you cannot read this please ask a superintendent to help you... LOL, for real!!!
|
|
|
|
|
Ahh, ok..
Following the same ideology: create a program that accesses the registry, reads and alters the values of the key mentioned in my previous post.
To utilize the registry, you can either use Platform SDK's registry functions (Search 'Registry Functions' from MSDN), or alternatively, use ATL and it's CRegKey class.
You don't need to fiddle with the StartUp folder if you use the registry entries. Remember that doing this may cause your program to function funnily, so always take a backup of your registry before using the registry functions
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
i wanna get the first sector of hard disk ? which function can i use to appoarch this.
thanks.
|
|
|
|
|
Check out CPhysicalDiskFile, part of the Win32 Foundation Class (WFC). See links below.
www.samblackburn.com/wfc/CPhysicalDiskFile.htm
www.samblackburn.com/wfc/
Mike
|
|
|
|
|
i wanna create 100 buttons in dialog with code and when clicking one button, it will display a message with the content is the id of the button.
help me please
|
|
|
|
|
can you please explain a bit furthur...
Old United Airlines Brochure:
If you cannot read this please ask a superintendent to help you... LOL, for real!!!
|
|
|
|
|
Creating code-wise buttons requires several steps:
1. Add CButton (or derived) member variables to the dialog class's header file. You can use an array here if you want.
2. For each member variable/array member, call it's Create member method. See MSDN and CButton for parameters of this function.
3. When all buttons are created, you need to show them by using ShowWindow method.
4. Either add a message-map entry to your application for every button ID (ON_BN_CLICKED) or overwrite the window procedure of the application. Now display a message box using AfxMessageBox global method. If you want to map all control IDs to a single handler, you need to use a ON_CONTROL_RANGE message map entry. See MSDN for more details.
To customize the message of the message box, create a CString object and call it's 'Format' to do printf-style formatting for the string. You need to get the ID from the message. Buttons, when clicked, send BN_CLICKED message to the parent. In this message, the control ID is in the low-order word of wParam. See MSDN for more details.
I hope this'll help you get started
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
How do I copy/convert a character array to a std::string?
Thanks for any insight.
William
Fortes in fide et opere!
|
|
|
|
|
1. Create a string object
2. Use it's member method 'operator +=' to append characters to string, specifying the start of the array as the parameter.
Example:
#include <string>
using namespace std;
<DIV>
... Later in the code...
<DIV>
<DIV>
string myString;
<DIV>
myString += &charArray[0];
<DIV>
Not completely sure if this will work, haven't tested it. But according to the Standard C++ Library Reference, it should go like this
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Thanks for replying.
I had tried the same technique you offered (plus about maybe 20 others) before posting the question, and nothing has worked!
Short of writing a routine to specifically transfer one character at a time from the array to the string, I thought the resiliency of string might have something that would do the job for me. No luck so far.
William
Fortes in fide et opere!
|
|
|
|
|
|
Thanks for replying.
While it is true the program compiles and links without any error, I believe the reason why I am NOT getting the desired behavior is due to a known bug a fix from MS doesn't seem to have corrected.
William
Fortes in fide et opere!
|
|
|
|
|
UNICODE issues?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.santacruznetworks.com">Santa Cruz Networks</A>
|
|
|
|
|
try using wstring.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I am right now in the process of trying to make the computer search for a certain string. I am looking in text files, also I'm using console(don't ask)
<marquee>Universal Project... Soon to be a .net
|
|
|
|
|
Read in all data from your file into a CString, and search for a pattern with CString::Find.
CString sString;
CFile file("c:\\pathtoyourfile.dat",CFile::modeRead);
file.Read(sString.GetBuffer(file.GetLength()),file.GetLength());
sString.ReleaseBuffer(file.GetLength());
sString.Find("Your pattern",0);
Take a look in MSDN at CFile, and CString.
Peter Molnar
|
|
|
|
|
Very well, but how can you do this in the console c++?
Old United Airlines Brochure:
If you cannot read this please ask a superintendent to help you... LOL, for real!!!
|
|
|
|
|
Use a FILE structure in combination with 'fopen', 'fclose' and 'fread' functions. Read the entire file to a LARGE char array (say 'char myArray[8000]'). Then use stricmp function to compare the file with your match string.
Of course, if your file is larger, you should use the heap memory instead of stack. Just create a 'char* ptrArray = new char[80000]' and read it there. Remember to delete it when finished.
See Run-Time Library Reference for more details on file handling.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Yes, I will allocate some memory since the file will be in constant change and allocation is a very good memory manager.
Old United Airlines Brochure:
If you cannot read this please ask a superintendent to help you... LOL, for real!!!
|
|
|
|
|
Create a console application with MFC support, and use the above code.
If you don't use MFC: The CString is part of the Win32 library in VS 7.0 and upwards, so you only have to change the file read in operation (see CreateFile,ReadFile Win32 functions).
Peter Molnar
|
|
|
|