Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. [SOLVED] Inline assembly syntax error..

[SOLVED] Inline assembly syntax error..

Scheduled Pinned Locked Moved C / C++ / MFC
helpvisual-studio
16 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C CodingLover

    Thanks for the comment. I tried a same example code segment from that page.

    void toggleLed(unsigned char ledMask)
    {
    __asm {
    mov al, 2
    mov dx, 0xD007
    out dx, al
    }
    }

    Once I compile the code it gives the following error. It wired to me from what the documentations explain (the link you gave, book I refer, etc..)

    Error [192] D:\Profiles\PC\WorkOnProjects\PIC\Demo\led_blink.c; 39.1 undefined identifier "__asm"
    Error [312] D:\Profiles\PC\WorkOnProjects\PIC\Demo\led_blink.c; 39.7 ";" expected
    Error [285] D:\Profiles\PC\WorkOnProjects\PIC\Demo\led_blink.c; 44.1 no identifier in declaration
    Warning [374] D:\Profiles\PC\WorkOnProjects\PIC\Demo\led_blink.c; 44.1 missing basic type; int assumed
    Error [314] D:\Profiles\OC\WorkOnProjects\PIC\Demo\led_blink.c; 44.1 ";" expected

    I appreciate your help all the time... CodingLover :)

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #7

    I reread your original message and it seems you are using MPLAB to build this code. I suggest you check the documentation for your compiler to find out exactly why it complains about this. Are you sure this compiler supports the __asm or asm keywords? You may also be better using the MPLAB forum to get an answer to your question.

    Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

    C 1 Reply Last reply
    0
    • E enhzflep

      I just tried a search for P2LTCH with google, finding the following block of code here.

      /**********************************************************************
      *
      * Function: toggleLed()
      *
      * Description: Toggle the state of one or both LED's.
      *
      * Notes: This function is specific to Arcom's Target188EB board.
      *
      * Returns: None defined.
      *
      **********************************************************************/
      void
      toggleLed(unsigned char ledMask)
      {
      #define P2LTCH 0xFF5E /* The address of the I/O register. */

      asm {   
          mov dx, P2LTCH          /\* Load the address of the register.  \*/   
          in  al, dx              /\* Read the contents of the register. \*/   
      
          mov ah, ledMask         /\* Move the ledMask into a register.  \*/   
          xor al, ah              /\* Toggle the requested bits.         \*/   
      
          out dx, al              /\* Write the new register contents.   \*/   
      };   
      

      } /* toggleLed() */

      Reading through this, I thought of your asm statement - In the code you showed using round braces, you used the asm keyword. Later you showed some code with curly braces, however I see that in the seconds code snippet you have used the __asm keyword, instead. If you haven't already, I'd try the syntax used in the above snippet. I've a very hazy memory that somewhere I read that the __asm keyword is a MS thing. Dunno, too lazy to check. :D Though I do note that in Code::Blocks, asm gets syntax-highlighted, while __asm doesn't..

      C Offline
      C Offline
      CodingLover
      wrote on last edited by
      #8

      Actually that is the same I am referring, O'Reillys' book. But it doesn't work for me. Seems to me that my compiler is not support this.

      I appreciate your help all the time... CodingLover :)

      E 1 Reply Last reply
      0
      • L Lost User

        I reread your original message and it seems you are using MPLAB to build this code. I suggest you check the documentation for your compiler to find out exactly why it complains about this. Are you sure this compiler supports the __asm or asm keywords? You may also be better using the MPLAB forum to get an answer to your question.

        Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

        C Offline
        C Offline
        CodingLover
        wrote on last edited by
        #9

        Yeah, seems to me that the compiler I am using with the MPLAB is not supporting the syntax. I am searching on the documentation at the min.

        I appreciate your help all the time... CodingLover :)

        1 Reply Last reply
        0
        • C CodingLover

          Thanks for the comment. I tried a same example code segment from that page.

          void toggleLed(unsigned char ledMask)
          {
          __asm {
          mov al, 2
          mov dx, 0xD007
          out dx, al
          }
          }

          Once I compile the code it gives the following error. It wired to me from what the documentations explain (the link you gave, book I refer, etc..)

          Error [192] D:\Profiles\PC\WorkOnProjects\PIC\Demo\led_blink.c; 39.1 undefined identifier "__asm"
          Error [312] D:\Profiles\PC\WorkOnProjects\PIC\Demo\led_blink.c; 39.7 ";" expected
          Error [285] D:\Profiles\PC\WorkOnProjects\PIC\Demo\led_blink.c; 44.1 no identifier in declaration
          Warning [374] D:\Profiles\PC\WorkOnProjects\PIC\Demo\led_blink.c; 44.1 missing basic type; int assumed
          Error [314] D:\Profiles\OC\WorkOnProjects\PIC\Demo\led_blink.c; 44.1 ";" expected

          I appreciate your help all the time... CodingLover :)

          S Offline
          S Offline
          Snorri Kristjansson
          wrote on last edited by
          #10

          You need to terminate the __asm block with a ';' e.g. __asm { mov eax,0 mov ebx,10 }; Also note that you MUST preserve (push/pop) any registers you use within an __asm block. Another thing to note when using 'out' instruction - you may trigger an exception because the Windows OS allows only a few 'out' addresses accesses directly like that from user mode programs (ring 3). If I remember correctly only tho old LPT ports are accessible.

          C 1 Reply Last reply
          0
          • S Snorri Kristjansson

            You need to terminate the __asm block with a ';' e.g. __asm { mov eax,0 mov ebx,10 }; Also note that you MUST preserve (push/pop) any registers you use within an __asm block. Another thing to note when using 'out' instruction - you may trigger an exception because the Windows OS allows only a few 'out' addresses accesses directly like that from user mode programs (ring 3). If I remember correctly only tho old LPT ports are accessible.

            C Offline
            C Offline
            CodingLover
            wrote on last edited by
            #11

            I tried the same too, but no luck.

            Snorri wrote:

            Another thing to note when using 'out' instruction - you may trigger an exception because the Windows OS allows only a few 'out' addresses accesses directly like that from user mode programs (ring 3).

            I don't have a big picture about this in my mind, since I am new to embedded systems yet. However, that information could be a value added. Thanks a lot.

            I appreciate your help all the time... CodingLover :)

            1 Reply Last reply
            0
            • C CodingLover

              Actually that is the same I am referring, O'Reillys' book. But it doesn't work for me. Seems to me that my compiler is not support this.

              I appreciate your help all the time... CodingLover :)

              E Offline
              E Offline
              enhzflep
              wrote on last edited by
              #12

              Woooooah! Hold on just a minute. Did you say you're trying this code in mplab? That code is obviously x86 inline assembly, yet I though MPLab was for embedded devices - i.e mainly PICs. Looking at your compile log, it seems remarkably similar to the exerpt I just gotfor the HiTech C compiler, as shown below: Executing: "C:\Program Files (x86)\HI-TECH Software\PICC\9.80\bin\picc.exe" --pass1 C:\Users\enhzflep\Documents\mplab\proj1\..\main.c -q --chip=16F84A -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s" Error [317] C:\Users\enhzflep\Documents\mplab\proj1\..\main.c; 5.5 "(" expected Error [318] C:\Users\enhzflep\Documents\mplab\proj1\..\main.c; 5.5 string expected Error [194] C:\Users\enhzflep\Documents\mplab\proj1\..\main.c; 5.5 ")" expected Error [312] C:\Users\enhzflep\Documents\mplab\proj1\..\main.c; 5.5 ";" expected Error [285] C:\Users\enhzflep\Documents\mplab\proj1\..\main.c; 15.1 no identifier in declaration Warning [374] C:\Users\enhzflep\Documents\mplab\proj1\..\main.c; 15.1 missing basic type; int assumed Error [314] C:\Users\enhzflep\Documents\mplab\proj1\..\main.c; 15.1 ";" expected ********** Build failed! ********** In that case, I think the problem is something else - i.e No, this compiler (a) won't accept the asm keyword (but you can easily make functions in asm files then link them together into your program) and more importantly (just now) (b) won't build programs that you can run on your PC - I'd have expected to see the code snippet in concern built using VS or GCC. Though, perhaps I'm just missing something?

              1 Reply Last reply
              0
              • E enhzflep

                I just tried a search for P2LTCH with google, finding the following block of code here.

                /**********************************************************************
                *
                * Function: toggleLed()
                *
                * Description: Toggle the state of one or both LED's.
                *
                * Notes: This function is specific to Arcom's Target188EB board.
                *
                * Returns: None defined.
                *
                **********************************************************************/
                void
                toggleLed(unsigned char ledMask)
                {
                #define P2LTCH 0xFF5E /* The address of the I/O register. */

                asm {   
                    mov dx, P2LTCH          /\* Load the address of the register.  \*/   
                    in  al, dx              /\* Read the contents of the register. \*/   
                
                    mov ah, ledMask         /\* Move the ledMask into a register.  \*/   
                    xor al, ah              /\* Toggle the requested bits.         \*/   
                
                    out dx, al              /\* Write the new register contents.   \*/   
                };   
                

                } /* toggleLed() */

                Reading through this, I thought of your asm statement - In the code you showed using round braces, you used the asm keyword. Later you showed some code with curly braces, however I see that in the seconds code snippet you have used the __asm keyword, instead. If you haven't already, I'd try the syntax used in the above snippet. I've a very hazy memory that somewhere I read that the __asm keyword is a MS thing. Dunno, too lazy to check. :D Though I do note that in Code::Blocks, asm gets syntax-highlighted, while __asm doesn't..

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #13

                enhzflep wrote:

                I've a very hazy memory that somewhere I read that the __asm keyword is a MS thing.

                This is true (about the double underscore, not your memory). ;)

                "One man's wage rise is another man's price increase." - Harold Wilson

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

                E 1 Reply Last reply
                0
                • D David Crow

                  enhzflep wrote:

                  I've a very hazy memory that somewhere I read that the __asm keyword is a MS thing.

                  This is true (about the double underscore, not your memory). ;)

                  "One man's wage rise is another man's price increase." - Harold Wilson

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

                  E Offline
                  E Offline
                  enhzflep
                  wrote on last edited by
                  #14

                  Touchè!:thumbsup:

                  1 Reply Last reply
                  0
                  • C CodingLover

                    Hi all, I start to do a simple application to control the P2LTCH(to blink a LED). So the toggle function as follow,

                    void toggleLed(unsigned char ledMask)
                    {
                    asm
                    (
                    mov dx, P2LTCH /* Load the address of the register. */
                    //in al, dx /* Read the contents of the register. */
                    //mov ah, ledMask /* Move the ledMask into a register. */
                    //xor al, ah /* Toggle the requested bits. */
                    //out dx, al /* Write the new register contents. */
                    );
                    }

                    However, it returns the following error.

                    Error [318] D:\Profiles\PC\WorkOnProjects\PIC\Demo\led_blink.c; 41.1 string expected
                    Error [194] D:\Profiles\PC\WorkOnProjects\PIC\Demo\led_blink.c; 41.1 ")" expected
                    Error [312] D:\Profiles\PC\WorkOnProjects\PIC\Demo\led_blink.c; 41.1 ";" expected

                    I do the coding on MPLAB IDE. Any comments really appreciate.

                    I appreciate your help all the time... CodingLover :)

                    C Offline
                    C Offline
                    CodingLover
                    wrote on last edited by
                    #15

                    I found the solution my self by referring the MPLAB documentation. Inline assembly need to be wrapped as follows.

                    #asm
                    // assembly code goes here
                    #endasm

                    I appreciate your help all the time... CodingLover :)

                    D 1 Reply Last reply
                    0
                    • C CodingLover

                      I found the solution my self by referring the MPLAB documentation. Inline assembly need to be wrapped as follows.

                      #asm
                      // assembly code goes here
                      #endasm

                      I appreciate your help all the time... CodingLover :)

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #16

                      CodingLover wrote:

                      ...by referring the MPLAB documentation.

                      Keep that under your hat. ;)

                      "One man's wage rise is another man's price increase." - Harold Wilson

                      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                      "Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups