PDA

View Full Version : How to use __asm__ in fc6 g++



ashukla
27th February 2008, 07:47
Dear All,


#include <iostream>
using namespace std;
int main()
{
__asm__ int 5; // generate intertupt 5
return 0;
}

I have comiled this a.cpp file as follows;
g++ a.cpp
a.cpp: In function ‘int main()’:
a.cpp:5: error: expected `(' before ‘int’
a.cpp:5: error: expected unqualified-id before numeric constant
and found the above error
Can any one guide me where I am wrong;
How a way I use interrupts using __asm__ in g++.

wysota
27th February 2008, 08:54
Try embedding the assembly code in braces.

ashukla
27th February 2008, 09:25
Try embedding the assembly code in braces.
I have spoil whole day for that but nothing get. Is anyone have a link or code for g++4.0.1 compiler.

wysota
27th February 2008, 09:29
Try round brackets instead of braces as the compiler suggests.

ashukla
27th February 2008, 09:44
Try round brackets instead of braces as the compiler suggests.

#include <iostream>
using namespace std;
int main()
{
char * am="int 5";
(__asm__ int 5); // generate intertupt 5

return 0;
}
and getting
g++ a.c
a.c: In function ‘int main()’:
a.c:6: error: expected primary-expression before ‘asm’
a.c:6: error: expected `)' before ‘asm’

wysota
27th February 2008, 09:51
I meant:


__asm__ ( int 5 );
or

__asm__ { int 5 };

ashukla
27th February 2008, 10:16
I meant:


__asm__ ( int 5 );
or

__asm__ { int 5 };
getting the following error respectively

__asm__ ( int 5 );
g++ a.c
a.c: In function ‘int main()’:
a.c:7: error: expected string-literal before ‘int’

__asm__ { int 5 };
g++ a.c
a.c: In function ‘int main()’:
a.c:7: error: expected `(' before ‘{’ token
a.c:7: error: expected unqualified-id before numeric constant

wysota
27th February 2008, 10:25
How about this:

asm("int 5");

jpn
27th February 2008, 10:26
Here's an example from qatomic_i386.h:


inline int q_atomic_fetch_and_add_int(volatile int *ptr, int value)
{
asm volatile("lock\n"
"xaddl %0,%1"
: "=r" (value), "+m" (*ptr)
: "0" (value)
: "memory");
return value;
}

Searching Google for example "g++ inline asm" would have surely been also productive.

ashukla
27th February 2008, 10:29
How about this:

asm("int 5");

g++ a.c
/tmp/cc8Vc1Ze.s: Assembler messages:
/tmp/cc8Vc1Ze.s:23: Error: suffix or operands invalid for `int'
getting the above error....

wysota
27th February 2008, 10:36
This is an assembler error, your assembly code is invalid.

ashukla
27th February 2008, 10:52
This is an assembler error, your assembly code is invalid.
Probably, you are saying right!
This is one of my program which is runned successfully;

#include <iostream>
using namespace std;
int a, b;

void f1(void)
{
a = 5;
b = 30;

asm
(
/*"movl $12, %ebx;"
"movl %ebx, a;"
"movl %ebx, b;"*/
"movl %eax, a;"
);

// cout<<"";

std::cout<<a<<std::endl;
std::cout<<b<<std::endl;
}

int main(){f1();}
Thanks for your help & quick response.
But How a way I generate a interrupt no. 5 for print screen which doesn't take any input.

wysota
27th February 2008, 10:55
Are you sure the interrupt is handled by Fedora? I never heard of a "print screen" interrupt in Linux. And it is surely doubtful the kernel will let you run one in user mode. Linux uses syscalls and not direct interrupts.

ashukla
27th February 2008, 11:01
Are you sure the interrupt is handled by Fedora? I never heard of a "print screen" interrupt in Linux. And it is surely doubtful the kernel will let you run one in user mode. Linux uses syscalls and not direct interrupts.
I have depicted a few days ago that you can call any interrupt in any OS using the asm keyboard on internet by a researcher of MIT. But I have not gotted the code for that. But I am sure it is working on DOS and windows.

ashukla
27th February 2008, 11:04
I have depicted a few days ago that you can call any interrupt in any OS using the asm keyboard on internet by a researcher of MIT. But I have not gotted the code for that. But I am sure it is working on DOS and windows.
Can you give me a example as you say it is possible in Linux using with syscall. I have also a need of mouse and keyboard input access.

wysota
27th February 2008, 11:14
I have depicted a few days ago that you can call any interrupt in any OS using the asm keyboard on internet by a researcher of MIT.
Provided that a particular OS has this interrupt and allows calling them in user mode.


But I have not gotted the code for that. But I am sure it is working on DOS and windows.
So "any" or "DOS and windows"? DOS and Windows do use interrupts...


Can you give me a example as you say it is possible in Linux using with syscall. I have also a need of mouse and keyboard input access.

man syscall :)