Menu

Intel MCS51 assembler code

Help
2024-03-27
2024-05-14
  • ivan23654623

    ivan23654623 - 2024-03-27

    Is it possible in the new version of the compiler to insert local variable names into assembly code?

    while(1)
    {
       uint8  x=5;
       __asm
          mov a,x
       __endasm;
    }
    
     

    Last edit: Maarten Brock 2024-05-09
  • Maarten Brock

    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.

     
    • ivan23654623

      ivan23654623 - 2024-05-11

      this code will not compile in sdcc so you can only insert global variables, but I need a local variable

       
      • Maarten Brock

        Maarten Brock - 2024-05-12

        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.

         
        • ivan23654623

          ivan23654623 - 2024-05-12

          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

           
          • Maarten Brock

            Maarten Brock - 2024-05-14

            Did you mark that variable volatile as I suggested?

             
            • ivan23654623

              ivan23654623 - 2024-05-14

              If I mark this variable as volatile, then the register number will not change during compilation?

               
    • ivan23654623

      ivan23654623 - 2024-05-11

      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

       
      • Janko Stamenović

        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/

         
        • Maarten Brock

          Maarten Brock - 2024-05-12

          Z80 is totally different from MCS51 in this regard unless the OP is using --stack-auto which he certainly did not mention.

           
          👍
          1

Log in to post a comment.