this code will not compile in sdcc so you can only insert global variables, but I need a local variable
Then first make it into something that does compile and inspect the generated asm. You'll find that the local variable is stored with a name that has both the function name (which you did not show) and the variable name.
Also note that uint8 is not a standard type, so I can only assume that you gave it the typedef that I would expect.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, I actually thought about this option, but it’s just a very inconvenient option, just if I compile code for where the sixth register is used and I write an assembly insert for it, and then during the next compilation the compiler will replace this register with the fifth or another and I’ll have to keep an eye on this
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Is it possible in the new version of the compiler to insert local variable names into assembly code?
Last edit: Maarten Brock 2024-05-09
Yes, start by looking at the generated asm to find the name of the variable.
But I strongly suggest to mark this variable as volatile.
this code will not compile in sdcc so you can only insert global variables, but I need a local variable
Then first make it into something that does compile and inspect the generated asm. You'll find that the local variable is stored with a name that has both the function name (which you did not show) and the variable name.
Also note that uint8 is not a standard type, so I can only assume that you gave it the typedef that I would expect.
Yes, I actually thought about this option, but it’s just a very inconvenient option, just if I compile code for where the sixth register is used and I write an assembly insert for it, and then during the next compilation the compiler will replace this register with the fifth or another and I’ll have to keep an eye on this
Did you mark that variable volatile as I suggested?
If I mark this variable as volatile, then the register number will not change during compilation?
the only thing I can do is write the entire function in assembler, but this is not convenient, I only need a small insert in assembler
For Z80 I hoped I could use an inline function to solve "I need a small piece of asm", but:
https://sourceforge.net/p/sdcc/discussion/1864/thread/37a100f200/
Z80 is totally different from MCS51 in this regard unless the OP is using --stack-auto which he certainly did not mention.