how to write __asm__ goto inline assembly
up vote
1
down vote
favorite
I m using a GCC compiler. I want to insert some inline instructions into C. Non-branching instructions are inserted successfully using __asm__ directive, as follows:
__asm__ volatile (
"add %[my_out], %[my_op1], %[my_op2]n"
: [my_out] "=&r" (array[3])
: [my_op1] "r" (array[0]),[my_op2] "r" (array[1])
);
But i cant inset a branch/jump instruction. Compilation gives the following error:
../test.c:5: error: expected '(' before 'goto'
../test.c:5: error: expected identifier or '*' before 'volatile'
I tried the following code:
unsigned int array[10] = { 0x22, 0x12,0,0,0,0,0,0,0};
int main() {
__asm__ goto volatile (
"jp %l[label]n"
: /*no output*/
: [my_op1] "r" (array[0]),[my_op2] "r" (array[1])
: /*no cobblers*/
: label
);
return 0;
label:
__asm__ volatile (
"add %[my_out], %[my_op1], %[my_op2]n"
: [my_out] "=&r" (array[3])
: [my_op1] "r" (array[0]),[my_op2] "r" (array[1])
);
return 0;
}
can you please help in correcting this code?
Regards
gcc inline-assembly
|
show 6 more comments
up vote
1
down vote
favorite
I m using a GCC compiler. I want to insert some inline instructions into C. Non-branching instructions are inserted successfully using __asm__ directive, as follows:
__asm__ volatile (
"add %[my_out], %[my_op1], %[my_op2]n"
: [my_out] "=&r" (array[3])
: [my_op1] "r" (array[0]),[my_op2] "r" (array[1])
);
But i cant inset a branch/jump instruction. Compilation gives the following error:
../test.c:5: error: expected '(' before 'goto'
../test.c:5: error: expected identifier or '*' before 'volatile'
I tried the following code:
unsigned int array[10] = { 0x22, 0x12,0,0,0,0,0,0,0};
int main() {
__asm__ goto volatile (
"jp %l[label]n"
: /*no output*/
: [my_op1] "r" (array[0]),[my_op2] "r" (array[1])
: /*no cobblers*/
: label
);
return 0;
label:
__asm__ volatile (
"add %[my_out], %[my_op1], %[my_op2]n"
: [my_out] "=&r" (array[3])
: [my_op1] "r" (array[0]),[my_op2] "r" (array[1])
);
return 0;
}
can you please help in correcting this code?
Regards
gcc inline-assembly
1
placevolatile
keyword beforegoto
rather than after.In your case you can remove thevolatile
in your first statement given that you have no output (or input/output) constraints. When you have none of thoseasm
is has an implicit volatile. Your secondasm
would still have to be marked volatile
– Michael Petch
Nov 21 at 9:02
1
To add to what Michael said, since asm goto cannot have outputs, and since asm statements without outputs are implicitly volatile, all asm goto statements are implicitly volatile. You might also want to check out the docs which would have shown you the order for the qualifiers.
– David Wohlferd
Nov 21 at 9:22
1
That should have worked. What's your target hw/os? And what version of gcc are you using?
– David Wohlferd
Nov 21 at 10:32
1
What version of GCC are you using? You can usegcc -v
to find out. When you made the fix suggested did the error change?
– Michael Petch
Nov 21 at 10:53
2
asm goto
wasn't available until GCC 4.5
– Michael Petch
Nov 21 at 12:53
|
show 6 more comments
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I m using a GCC compiler. I want to insert some inline instructions into C. Non-branching instructions are inserted successfully using __asm__ directive, as follows:
__asm__ volatile (
"add %[my_out], %[my_op1], %[my_op2]n"
: [my_out] "=&r" (array[3])
: [my_op1] "r" (array[0]),[my_op2] "r" (array[1])
);
But i cant inset a branch/jump instruction. Compilation gives the following error:
../test.c:5: error: expected '(' before 'goto'
../test.c:5: error: expected identifier or '*' before 'volatile'
I tried the following code:
unsigned int array[10] = { 0x22, 0x12,0,0,0,0,0,0,0};
int main() {
__asm__ goto volatile (
"jp %l[label]n"
: /*no output*/
: [my_op1] "r" (array[0]),[my_op2] "r" (array[1])
: /*no cobblers*/
: label
);
return 0;
label:
__asm__ volatile (
"add %[my_out], %[my_op1], %[my_op2]n"
: [my_out] "=&r" (array[3])
: [my_op1] "r" (array[0]),[my_op2] "r" (array[1])
);
return 0;
}
can you please help in correcting this code?
Regards
gcc inline-assembly
I m using a GCC compiler. I want to insert some inline instructions into C. Non-branching instructions are inserted successfully using __asm__ directive, as follows:
__asm__ volatile (
"add %[my_out], %[my_op1], %[my_op2]n"
: [my_out] "=&r" (array[3])
: [my_op1] "r" (array[0]),[my_op2] "r" (array[1])
);
But i cant inset a branch/jump instruction. Compilation gives the following error:
../test.c:5: error: expected '(' before 'goto'
../test.c:5: error: expected identifier or '*' before 'volatile'
I tried the following code:
unsigned int array[10] = { 0x22, 0x12,0,0,0,0,0,0,0};
int main() {
__asm__ goto volatile (
"jp %l[label]n"
: /*no output*/
: [my_op1] "r" (array[0]),[my_op2] "r" (array[1])
: /*no cobblers*/
: label
);
return 0;
label:
__asm__ volatile (
"add %[my_out], %[my_op1], %[my_op2]n"
: [my_out] "=&r" (array[3])
: [my_op1] "r" (array[0]),[my_op2] "r" (array[1])
);
return 0;
}
can you please help in correcting this code?
Regards
gcc inline-assembly
gcc inline-assembly
asked Nov 21 at 8:19
Sajjad
276
276
1
placevolatile
keyword beforegoto
rather than after.In your case you can remove thevolatile
in your first statement given that you have no output (or input/output) constraints. When you have none of thoseasm
is has an implicit volatile. Your secondasm
would still have to be marked volatile
– Michael Petch
Nov 21 at 9:02
1
To add to what Michael said, since asm goto cannot have outputs, and since asm statements without outputs are implicitly volatile, all asm goto statements are implicitly volatile. You might also want to check out the docs which would have shown you the order for the qualifiers.
– David Wohlferd
Nov 21 at 9:22
1
That should have worked. What's your target hw/os? And what version of gcc are you using?
– David Wohlferd
Nov 21 at 10:32
1
What version of GCC are you using? You can usegcc -v
to find out. When you made the fix suggested did the error change?
– Michael Petch
Nov 21 at 10:53
2
asm goto
wasn't available until GCC 4.5
– Michael Petch
Nov 21 at 12:53
|
show 6 more comments
1
placevolatile
keyword beforegoto
rather than after.In your case you can remove thevolatile
in your first statement given that you have no output (or input/output) constraints. When you have none of thoseasm
is has an implicit volatile. Your secondasm
would still have to be marked volatile
– Michael Petch
Nov 21 at 9:02
1
To add to what Michael said, since asm goto cannot have outputs, and since asm statements without outputs are implicitly volatile, all asm goto statements are implicitly volatile. You might also want to check out the docs which would have shown you the order for the qualifiers.
– David Wohlferd
Nov 21 at 9:22
1
That should have worked. What's your target hw/os? And what version of gcc are you using?
– David Wohlferd
Nov 21 at 10:32
1
What version of GCC are you using? You can usegcc -v
to find out. When you made the fix suggested did the error change?
– Michael Petch
Nov 21 at 10:53
2
asm goto
wasn't available until GCC 4.5
– Michael Petch
Nov 21 at 12:53
1
1
place
volatile
keyword before goto
rather than after.In your case you can remove the volatile
in your first statement given that you have no output (or input/output) constraints. When you have none of those asm
is has an implicit volatile. Your second asm
would still have to be marked volatile– Michael Petch
Nov 21 at 9:02
place
volatile
keyword before goto
rather than after.In your case you can remove the volatile
in your first statement given that you have no output (or input/output) constraints. When you have none of those asm
is has an implicit volatile. Your second asm
would still have to be marked volatile– Michael Petch
Nov 21 at 9:02
1
1
To add to what Michael said, since asm goto cannot have outputs, and since asm statements without outputs are implicitly volatile, all asm goto statements are implicitly volatile. You might also want to check out the docs which would have shown you the order for the qualifiers.
– David Wohlferd
Nov 21 at 9:22
To add to what Michael said, since asm goto cannot have outputs, and since asm statements without outputs are implicitly volatile, all asm goto statements are implicitly volatile. You might also want to check out the docs which would have shown you the order for the qualifiers.
– David Wohlferd
Nov 21 at 9:22
1
1
That should have worked. What's your target hw/os? And what version of gcc are you using?
– David Wohlferd
Nov 21 at 10:32
That should have worked. What's your target hw/os? And what version of gcc are you using?
– David Wohlferd
Nov 21 at 10:32
1
1
What version of GCC are you using? You can use
gcc -v
to find out. When you made the fix suggested did the error change?– Michael Petch
Nov 21 at 10:53
What version of GCC are you using? You can use
gcc -v
to find out. When you made the fix suggested did the error change?– Michael Petch
Nov 21 at 10:53
2
2
asm goto
wasn't available until GCC 4.5– Michael Petch
Nov 21 at 12:53
asm goto
wasn't available until GCC 4.5– Michael Petch
Nov 21 at 12:53
|
show 6 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407795%2fhow-to-write-asm-goto-inline-assembly%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
place
volatile
keyword beforegoto
rather than after.In your case you can remove thevolatile
in your first statement given that you have no output (or input/output) constraints. When you have none of thoseasm
is has an implicit volatile. Your secondasm
would still have to be marked volatile– Michael Petch
Nov 21 at 9:02
1
To add to what Michael said, since asm goto cannot have outputs, and since asm statements without outputs are implicitly volatile, all asm goto statements are implicitly volatile. You might also want to check out the docs which would have shown you the order for the qualifiers.
– David Wohlferd
Nov 21 at 9:22
1
That should have worked. What's your target hw/os? And what version of gcc are you using?
– David Wohlferd
Nov 21 at 10:32
1
What version of GCC are you using? You can use
gcc -v
to find out. When you made the fix suggested did the error change?– Michael Petch
Nov 21 at 10:53
2
asm goto
wasn't available until GCC 4.5– Michael Petch
Nov 21 at 12:53