TEXT ·asmfunc(SB),7,$0
MOVQ $42, AX
// TODO: find jump target, move it to BX
// TODO: jump to address specified in BX
lab1:
MOVQ $43, AX
JMP funcend
lab2:
MOVQ $44, AX
JMP funcend
funcend:
MOVQ AX, r+0(FP)
RET
func asmfunc() uint64
There is no way to emit a data reference to a specific instruction within a function.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
opdec := s6502tab[I]if opdec.Handler != nil {opdec.Handler(s, opdec.AddMode, I)return}
Labels as Values================You can get the address of a label defined in the current function(or a containing function) with the unary operator `&&'. The value hastype `void *'. This value is a constant and can be used wherever aconstant of that type is valid. For example:void *ptr;...ptr = &&foo;To use these values, you need to be able to jump to one. This isdone with the computed goto statement(1), `goto *EXP;'. For example,goto *ptr;Any expression of type `void *' is allowed.One way of using these constants is in initializing a static arraythat will serve as a jump table:static void *array[] = { &&foo, &&bar, &&hack };Then you can select a label with indexing, like this:goto *array[i];
Note that this does not check whether the subscript is in bounds--arrayindexing in C never does that.Such an array of label values serves a purpose much like that of the`switch' statement. The `switch' statement is cleaner, so use thatrather than an array unless the problem does not fit a `switch'statement very well.Another use of label values is in an interpreter for threaded code.The labels within the interpreter function can be stored in thethreaded code for super-fast dispatching.You may not use this mechanism to jump to code in a differentfunction. If you do that, totally unpredictable things will happen.The best way to avoid this is to store the label address only inautomatic variables and never pass it as an argument.An alternate way to write the above example isstatic const int array[] = { &&foo - &&foo, &&bar - &&foo,&&hack - &&foo };goto *(&&foo + array[i]);This is more friendly to code living in shared libraries, as it reducesthe number of dynamic relocations that are needed, and by consequence,allows the data to be read-only.---------- Footnotes ----------
(1) The analogous feature in Fortran is called an assigned goto, butthat name seems inappropriate in C, where one can do more than simplystore label addresses in label variables.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.