|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
I've been programming in assembler for about a year now, and am trying to incorporate it into my C++ code. Visual C++ refuses to cooperate, however. Here's the problematic code:
C++ Code:
The compiler gives me the following error for the marked lines: error C2415: improper operand type Can anyone help me please? Last edited by dargueta; 10-07-2007 at 05:53 PM. |
| Sponsored Links |
|
|
|
|||
|
It's easier that way, I guess. I want to create fast and tight code. Using WinAPI is annoying because my compiler chokes when I link to a library, DLL, or anything like that; besides, I can tailor the code to suit my own purposes and ignore unnecessary things such as stack frames for functions that don't have arguments, etc. Can you think of a better method of coding stuff like this?
I've never tried linking an ASM file--how exactly would I do that? I know I have to use MASM directives and stuff like that, which I really don't like. I tend to be a simplistic traditionalist, if that makes any sense. |
|
|||||
|
I've wrote an article on the subject on my website, some months ago. It shows how it works (which you probably knows. You seems experienced) and how you're linking with an external assembly-file (it's this part you might want to look into.)
|
|
|||
|
Thanks a lot; that really helped. I do have one question, however. I haven't really worked with functions that return values in assembler; if the return value is larger than 32 bits (say, a 16:32 pointer for example) where would it go? Pushing it onto the stack would cause a stack overflow error because esp < ebp.
Also, by any chance, do you know how to call interrupts in C without crashing? I've written functions in assembler for graphics operations, but they all crash with an access violation error when I call an interrupt. The only ones I've used so far are 10h (graphics), 16h (keyboard), and 21h (I/O). Last edited by dargueta; 10-08-2007 at 12:57 PM. |
| Sponsored Links |
|
|
|
|||||
|
I don't use Assembly inlined in C-code, and I've never had, so I can't really help you, sorry.
The external linking of Assembly will probably work-out, but you'll have to do a little extra work (when linking, as you saw in my article) F.ex. you could write some sub-procedures in your Assembly-file, and then use them externally. IMO, it makes the code prettier looking as well. I like to keep the different language alone, and not to use some features in one language to use another language. |
|
|||
|
About calling interrupts in C, it's not possible (at least in Windows) since the OS runs in protected mode, and the user programs don't have privilege to make those calls. To do it, you would need to compile the project as DOS project (but there are only a few compiler that will do that, and its not worth it because you lose all the benefits from the protected mode).
The other option is to do it as a driver project, where I think you can use the interruptions. Anyway, in these days it's probably you won't want to do that, because using old DOS-interrupts is really slow, and every card has its own quick-operation shortcuts. For graphics the best way to go is with DirectX or OpenGL (or any other software like these), since those companies have searched, buyed, and implement all those shortcuts (accelerated hardware)... So unless you have many men and time, or you are only learning the basics, you're best shot is to use DirectX (only for Windows) or OpenGL. PD: If you want to see the difference between Accelerated Hardware and DOS interrutpts, just look for a comparison between DirectX HAL and REF (for example, in the Direct3D SDK Samples) Last edited by davHunter; 10-14-2007 at 10:29 PM. |
|
|||
|
What libs and dlls would I need to use DX?
|
|
|||
|
You must download the DirectX SDK from Microsoft website.
Install it, and then add the paths to Visual Studio (or any other IDE / Compiler you use)... That's for using it in C (development). When playing the game, you need the runtime version of DX (almost every decent PC has DX). Last edited by davHunter; 10-15-2007 at 09:51 PM. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problems in GETMEM.INC with newer WinXP security updates. | dima_q | Pascal/Delphi | 0 | 06-04-2007 10:17 AM |
| Problems in compiling D-ITG | MietitoreDAnime | C and C++ | 2 | 02-15-2007 12:18 PM |
| Problems | dirkfirst | HTML Programming | 8 | 10-12-2006 09:00 PM |
| Problems with Google? | Void | Marketing | 4 | 07-23-2006 08:12 PM |
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |
Goal: 100,000 Posts
Complete: 100%