c++ - Inline Assembler Question
- Ed Schroder (16/16) Nov 10 2003 I am looking for a way to use the "indirect jump" within a routine, actu...
- Gisle Vanem (23/37) Nov 10 2003 Labels cannot be used as addresses in an array or whatever.
- Ed Schroder (15/52) Nov 11 2003 Thanks Gisle for answer.
- Walter (7/70) Nov 11 2003 At the moment, you can't create a jump table with the inline assembler.
- Ed Schroder (6/84) Nov 12 2003 Thanks for clarification, so I can stop my odyssey looking for it :)
- Walter (4/9) Nov 12 2003 Probably the best solution is to write the switch statement in C, then w...
- Ed Schroder (7/18) Nov 14 2003 assembler.
- Keith Fuller (6/22) Nov 11 2003 Just by way of asking a dumb question,
I am looking for a way to use the "indirect jump" within a routine, actually how to create your own "switch case" using inline-assembly. Suppose I have this: switch(var) { case 0 : goto label_00; case 1 : goto label_01; case 2 : goto label_02; case 3 : goto label_03; case 4 : goto label_04; } Then how do I create the (jump) addresses for label_00, label_01 ........ label_04 ? I couldn't find the answer in the documentation. Thanks for answers. My best, Ed
Nov 10 2003
"Ed Schroder" <rebel777 home.nl> wrote:I am looking for a way to use the "indirect jump" within a routine, actually how to create your own "switch case" using inline-assembly. Suppose I have this: switch(var) { case 0 : goto label_00; case 1 : goto label_01; case 2 : goto label_02; case 3 : goto label_03; case 4 : goto label_04; } Then how do I create the (jump) addresses for label_00, label_01 ........ label_04 ?Labels cannot be used as addresses in an array or whatever. Only GNU C can do that AFAIK. You better use an array of functions and do an indirect call. Something like: void (*funcs[]) (void) = { func_00, func_01 }; int x = 0; __asm { lea eax, funcs mov ebx, x call [4*ebx+eax] } (depending on model of course). BTW. GNU C allows this dangerous trick: int main (void) { static void *label[] = { &&label_0, &&label_1 }; int x = 0; goto *label[1]; label_0: label_1: return (0); } --gv
Nov 10 2003
Thanks Gisle for answer. I am aware of the call-technique and practice it wherever it is useful. But in the end the "switch-case" command when it is compiled creates such a jump-table. Meaning, if the compiler can why shouldn't the user? When you watch the assembler output the indirect jump is present including a generated jump-table. I am sure there must be some tricky way to create the jump-table yourself. I just hope Walter is reading this :) My best, Ed ================== "Gisle Vanem" <giva users.sourceforge.net> wrote in message news:booinr$15um$1 digitaldaemon.com..."Ed Schroder" <rebel777 home.nl> wrote:actuallyI am looking for a way to use the "indirect jump" within a routine,havehow to create your own "switch case" using inline-assembly. Suppose I........this: switch(var) { case 0 : goto label_00; case 1 : goto label_01; case 2 : goto label_02; case 3 : goto label_03; case 4 : goto label_04; } Then how do I create the (jump) addresses for label_00, label_01label_04 ?Labels cannot be used as addresses in an array or whatever. Only GNU C can do that AFAIK. You better use an array of functions and do an indirect call. Something like: void (*funcs[]) (void) = { func_00, func_01 }; int x = 0; __asm { lea eax, funcs mov ebx, x call [4*ebx+eax] } (depending on model of course). BTW. GNU C allows this dangerous trick: int main (void) { static void *label[] = { &&label_0, &&label_1 }; int x = 0; goto *label[1]; label_0: label_1: return (0); } --gv
Nov 11 2003
At the moment, you can't create a jump table with the inline assembler. Sorry. "Ed Schroder" <rebel777 home.nl> wrote in message news:boqcn4$pk9$1 digitaldaemon.com...Thanks Gisle for answer. I am aware of the call-technique and practice it wherever it is useful.Butin the end the "switch-case" command when it is compiled creates such a jump-table. Meaning, if the compiler can why shouldn't the user? When you watch the assembler output the indirect jump is present includingagenerated jump-table. I am sure there must be some tricky way to createthejump-table yourself. I just hope Walter is reading this :) My best, Ed ================== "Gisle Vanem" <giva users.sourceforge.net> wrote in message news:booinr$15um$1 digitaldaemon.com..."Ed Schroder" <rebel777 home.nl> wrote:actuallyI am looking for a way to use the "indirect jump" within a routine,havehow to create your own "switch case" using inline-assembly. Suppose I........this: switch(var) { case 0 : goto label_00; case 1 : goto label_01; case 2 : goto label_02; case 3 : goto label_03; case 4 : goto label_04; } Then how do I create the (jump) addresses for label_00, label_01label_04 ?Labels cannot be used as addresses in an array or whatever. Only GNU C can do that AFAIK. You better use an array of functions and do an indirect call. Something like: void (*funcs[]) (void) = { func_00, func_01 }; int x = 0; __asm { lea eax, funcs mov ebx, x call [4*ebx+eax] } (depending on model of course). BTW. GNU C allows this dangerous trick: int main (void) { static void *label[] = { &&label_0, &&label_1 }; int x = 0; goto *label[1]; label_0: label_1: return (0); } --gv
Nov 11 2003
"Walter" <walter digitalmars.com> wrote in message news:bor6u2$211k$1 digitaldaemon.com...At the moment, you can't create a jump table with the inline assembler. Sorry.Thanks for clarification, so I can stop my odyssey looking for it :) Ed"Ed Schroder" <rebel777 home.nl> wrote in message news:boqcn4$pk9$1 digitaldaemon.com...includingThanks Gisle for answer. I am aware of the call-technique and practice it wherever it is useful.Butin the end the "switch-case" command when it is compiled creates such a jump-table. Meaning, if the compiler can why shouldn't the user? When you watch the assembler output the indirect jump is presentaIgenerated jump-table. I am sure there must be some tricky way to createthejump-table yourself. I just hope Walter is reading this :) My best, Ed ================== "Gisle Vanem" <giva users.sourceforge.net> wrote in message news:booinr$15um$1 digitaldaemon.com..."Ed Schroder" <rebel777 home.nl> wrote:actuallyI am looking for a way to use the "indirect jump" within a routine,how to create your own "switch case" using inline-assembly. Supposehave........this: switch(var) { case 0 : goto label_00; case 1 : goto label_01; case 2 : goto label_02; case 3 : goto label_03; case 4 : goto label_04; } Then how do I create the (jump) addresses for label_00, label_01label_04 ?Labels cannot be used as addresses in an array or whatever. Only GNU C can do that AFAIK. You better use an array of functions and do an indirect call. Something like: void (*funcs[]) (void) = { func_00, func_01 }; int x = 0; __asm { lea eax, funcs mov ebx, x call [4*ebx+eax] } (depending on model of course). BTW. GNU C allows this dangerous trick: int main (void) { static void *label[] = { &&label_0, &&label_1 }; int x = 0; goto *label[1]; label_0: label_1: return (0); } --gv
Nov 12 2003
"Ed Schroder" <rebel777 home.nl> wrote in message news:bost9i$1mjv$1 digitaldaemon.com..."Walter" <walter digitalmars.com> wrote in message news:bor6u2$211k$1 digitaldaemon.com...Probably the best solution is to write the switch statement in C, then write the statements following each case in inline assembly.At the moment, you can't create a jump table with the inline assembler. Sorry.Thanks for clarification, so I can stop my odyssey looking for it :)
Nov 12 2003
"Walter" <walter digitalmars.com> wrote in message news:bot23j$1tmm$1 digitaldaemon.com..."Ed Schroder" <rebel777 home.nl> wrote in message news:bost9i$1mjv$1 digitaldaemon.com...assembler."Walter" <walter digitalmars.com> wrote in message news:bor6u2$211k$1 digitaldaemon.com...At the moment, you can't create a jump table with the inlinewriteProbably the best solution is to write the switch statement in C, thenSorry.Thanks for clarification, so I can stop my odyssey looking for it :)the statements following each case in inline assembly.That was my solution too. Thanks Walter for support and keep up the good work. Ed
Nov 14 2003
Just by way of asking a dumb question, you can't have the switch statement in C and have it jump to some inline assembler code? Keith Fuller keithfx H*tmail.com In article <boofcq$10sl$1 digitaldaemon.com>, Ed Schroder says...I am looking for a way to use the "indirect jump" within a routine, actually how to create your own "switch case" using inline-assembly. Suppose I have this: switch(var) { case 0 : goto label_00; case 1 : goto label_01; case 2 : goto label_02; case 3 : goto label_03; case 4 : goto label_04; } Then how do I create the (jump) addresses for label_00, label_01 ........ label_04 ? I couldn't find the answer in the documentation. Thanks for answers. My best, Ed
Nov 11 2003