Embedded build in C with Turbo C 3.0 - how to get tag address

I am trying to get the label address - here is a sample code:

int main() { asm { mov ax,1 mov bx,ax } _labelname: asm { mov ax, OFFSET _labelname } return 0; } 

Compiling this code returns this error: "Undefined symbol _labelname" If I define a label in the asm block, I can't even use jmp _labelname

I found this one and it doesn’t work, for this , no way really. It says that this is just a leap, not a conversion. And that does not help at all. Any suggestions?

+4
source share
2 answers

I found a way, but you cannot use the C label, it must be an asm label:

 int main(void) { asm { mov ax,1 mov bx,ax } asm { _labelname: } asm { mov ax, OFFSET _labelname jmp cs:_labelname } return 0; } 
0
source

The route is usually in any language, but you need to worry for a day or two, because these things are not always documented

Declare a global memory space at your taste HLL. DIM LABELNAME1(0)

Then find the asm syntax that puts the address in eax

 mov eax, ^LABELNAME(0) mov eax, dword [_lablename] mov eax, ^_lablename etc etc etc 

then put it in asm

You will not find pop [^ anywhere google, but it is one that works in certain HLL

 push eax pop [^LABELNAME1(0)] 

Now your HLL and asm can communicate with each other when you like

So it's worth a look


 Undefined symbol _labelname 

Probability should be announced at the very beginning of the program.

 ._labelname mov dword [_lablename], 0 

and used later by asm as a label

As I said, you have to get confused and talk about your particular taste for HLL, and it seems that globals work best

You also need to figure out how to declare separate memory zones for storing dynamic asm variables and executing opcodes, or you will get cache overwrites that will distort the benefits of ASM

The small program that I wrote without dividing these areas took 20 hours. Split took 1 hour


 mov ax, OFFSET _labelname 

This is 16-bit stuff (DOS, etc., with the correct memory rules), you are not doing 32-bit stuff with HLL ???

If this does not happen in one segment, you will need a double-memory operand to find _labelname , dx:ax , etc., and as mentioned earlier, you are 20 years late.

 jmp cs:_labelname 

It works in the same segment, but for a larger program, the cs part should be tied to a specific segment and down-jump / return

In addition, if your asm dynamic variables are embedded in your asm code segment, then the basic rule for maximizing asm speed has been violated

0
source

Source: https://habr.com/ru/post/1384582/


All Articles