Board index » cppbuilder » puttin one or more assembler routines in code

puttin one or more assembler routines in code


2004-12-03 10:55:27 PM
cppbuilder3
Can I add a few simply assembler instructions in my code ?
How can I do this ?
 
 

Re:puttin one or more assembler routines in code

"Peter" < XXXX@XXXXX.COM >wrote:
Quote
Can I add a few simply assembler instructions in my code ?
Yes.
Quote
How can I do this ?
By using the reserved word asm:
asm
{
mov EAX, Startcolor
cmp EAX, EndColor
je @@exit
}
~ JD
 

Re:puttin one or more assembler routines in code

Hi,
I tried to put this in the code :
asm {
mov ax, 0x0e07
xor bx, bx
int 0x10 // makes the system beep
}
(example from help file)
but then the code doesn't compile.
[Tasm Fatal Error] Out of hash space
Is there something more I need to do then just add the asm code ?
"JD" < XXXX@XXXXX.COM >wrote in message
Quote

"Peter" < XXXX@XXXXX.COM >wrote:
>Can I add a few simply assembler instructions in my code ?

Yes.

>How can I do this ?

By using the reserved word asm:

asm
{
mov EAX, Startcolor
cmp EAX, EndColor
je @@exit
}

~ JD

 

{smallsort}

Re:puttin one or more assembler routines in code

The IDE Project|Options menu has a TASM tab in which you
can adjust the hash space.
C++ Builder is for 32 bit Windows. The assembly language
you show is 16 bit DOS code. It is not compatible with
Windows.
. Ed
Quote
Peter wrote in message
news:41b0dbf1$ XXXX@XXXXX.COM ...

I tried to put this in the code :

asm {
mov ax, 0x0e07
xor bx, bx
int 0x10 // makes the system beep
}

(example from help file)

but then the code doesn't compile.
[Tasm Fatal Error] Out of hash space

Is there something more I need to do then just add
the asm code ?
 

Re:puttin one or more assembler routines in code

Can somebody give an example then to simply do NOP once ?
asm {
nop
}
seems to trigger the same problems ?
"Ed Mulroy [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote
The IDE Project|Options menu has a TASM tab in which you
can adjust the hash space.

C++ Builder is for 32 bit Windows. The assembly language
you show is 16 bit DOS code. It is not compatible with
Windows.

. Ed

>Peter wrote in message
>news:41b0dbf1$ XXXX@XXXXX.COM ...
>
>I tried to put this in the code :
>
>asm {
>mov ax, 0x0e07
>xor bx, bx
>int 0x10 // makes the system beep
>}
>
>(example from help file)
>
>but then the code doesn't compile.
>[Tasm Fatal Error] Out of hash space
>
>Is there something more I need to do then just add
>the asm code ?



 

Re:puttin one or more assembler routines in code

I don't know what you want. There is no problem with that
code as you can see below.
---------------
F:\Projects\lookat\q411>type ques411.cpp
#include <windows.h>
#pragma inline
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
__asm {
nop
}
return 0;
}
F:\Projects\lookat\q411>bcc32 -W ques411
Borland C++ 5.4 for Win32 Copyright (c) 1993, 1999 Inprise
Corporation
QUES411.cpp:
Turbo Assembler Version 5.2 Copyright (c) 1988, 1999 Inprise
Corporation
Assembling file: QUES411.ASM
Error messages: None
Warning messages: None
Passes: 1
Turbo Incremental Link 4.00 Copyright (c) 1997, 1999 Inprise
Corporation
F:\Projects\lookat\q411>ques411
F:\Projects\lookat\q411>
---------------
. Ed
Quote
Peter wrote in message
news:41b87d98$ XXXX@XXXXX.COM ...

Can somebody give an example then to simply do NOP once ?

asm {
nop
}

seems to trigger the same problems ?
 

Re:puttin one or more assembler routines in code

Is it actually possible to simply add
asm { nop }
between other lines of c++ code, inside a routine, e.g. an event callback in
a Borland c++ Builder 5 project ?
I know nop will do nothing, I just like to start small and simple ;-)
"Ed Mulroy [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote
I don't know what you want. There is no problem with that
code as you can see below.

---------------
F:\Projects\lookat\q411>type ques411.cpp
#include <windows.h>

#pragma inline

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
__asm {
nop
}

return 0;
}

F:\Projects\lookat\q411>bcc32 -W ques411
Borland C++ 5.4 for Win32 Copyright (c) 1993, 1999 Inprise
Corporation
QUES411.cpp:
Turbo Assembler Version 5.2 Copyright (c) 1988, 1999 Inprise
Corporation

Assembling file: QUES411.ASM
Error messages: None
Warning messages: None
Passes: 1

Turbo Incremental Link 4.00 Copyright (c) 1997, 1999 Inprise
Corporation

F:\Projects\lookat\q411>ques411

F:\Projects\lookat\q411>
---------------

. Ed

>Peter wrote in message
>news:41b87d98$ XXXX@XXXXX.COM ...
>
>Can somebody give an example then to simply do NOP once ?
>
>asm {
>nop
>}
>
>seems to trigger the same problems ?



 

Re:puttin one or more assembler routines in code

Yes, it is safe to put a NOP in between instructions.
It does not matter if the function is a class member
or not.
I can't show the windows from a GUI project in a
newsgroup message but I can show something that
generates console output.
Try this:
Select File|New|Other
Double click the Console Wizard icon
Make sure GUI and VCL are not selected
(can't remember which check boxes were
in version 5, if a a Console box is shown,
check it).
Use this as your source code:
---------------
#pragma inline
#include <cstdio>
using namespace std;
void ShowNums(int num1, int num2)
{
printf("%10u %10u\n", num1, num2);
}
int main()
{
int i;
int val = 0;
int asmval = 0;
for (i = 0; i < 12; ++i)
{
__asm {
mov eax,[asmval]
add eax,[i]
mov [asmval],eax
}
val = val + i;
ShowNums(val, asmval);
}
return 0;
}
---------------
When you run the program you will see that the 'asmval'
variable which is calculated in inline assembly exactly
equals the 'val' variable which is calculated in C++.
---------------
0 0
1 1
3 3
6 6
10 10
15 15
21 21
28 28
36 36
45 45
55 55
66 66
---------------
After that go to the command line and create an assembly
language file like this (assumes the file is TRY.CPP)
bcc32 -WCR -S try
That will create TRY.ASM
You can then look at the assembly language file in an
editor. Slog through the segment declarations, debug
stuff and other extraneous material to where the function
main is found.
Notice how each C++ source code line is included as a
comment (a semicolon at the left is an assembly file
comment) and the assembly code it was translated to
follows that comment.
. Ed
Quote
Peter wrote in message
news: XXXX@XXXXX.COM ...
Is it actually possible to simply add

asm { nop }

between other lines of c++ code, inside a routine, e.g.
an event callback in a Borland c++ Builder 5 project ?

I know nop will do nothing, I just like to start small and
simple ;-)