I'm programming STM8 micro controller in STVD. I happen to use an assembly instruction in the middle of code. As shown here
I used a instruction as below
asm("MOV $00500A,#$3");
But I'm facing with following error
#error cpstm8 ..\app\sched.c:183(5) missing prototype
Can anyone help me in fixing this?
For STM8 assembly instruction, you need to use _ before the instruction as shown below
_asm("MOV $00500A,#$3");
Related
I use KEIL to compile a program.
The program uses the code
asm("NOP");
Unfortunately KEIL compiler does not accept the statement.
The idea is to introduce a delay by using NOP (no operation) assembly code.
What is the actual equivalent of this in C ? Does this vary with the embedded controller that I use?
There's an intrinsic nop in most compilers, Keil should have this as well - try __nop()
See - https://www.keil.com/support/man/docs/armcc/armcc_chr1359124998347.htm
Intrinsic functions are usually safer than directly adding assembly code for compatibility reasons.
Does this vary with the embedded controller that I use?
Yes. Inline assembly is not part of the C standard (yet), it varies from compiler to compiler and sometimes even between different target architectures of the same compiler. See Is inline asm part of the ANSI C standard? for more information.
For example, for the C51 Keil compiler, the syntax for inline assembly is
...
#pragma asm
NOP
#pragma endasm
...
while for ARM, the syntax is something like
...
__asm {
NOP
}
...
You will need to check the manual for the actual compiler you are using.
For some of the more common opcodes, some compilers provide so-called intrinsics - these can be called like a C function but essentially insert assembly code, like _nop_ ().
If you are using Keil for ARM Cortex target (e.g. stm32), you are most probably also using CMSIS library. It has portable macros and inline functions for all assembly instructions written like this: __NOP().
I am familiar with the instruction int on x86.
Is it possible to inline assembly int my_unique_number and use
requst_irq(my_unique_number , function); with a function to be
called when the instruction is executed?
What about ARM is there any similar way to use SWI immed_8 instruction or SVC?
Can I do the same trick?
In the Linux kernel it's much simpler to simply implement your own system call in the kernel and use the syscall(your_number) function to call it rather than doing the assembly code yourself.
Doing so is very easy http://www.linuxjournal.com/article/3326 here's a link to an article that describes how to do so in much less words than I would have used.
I am trying to understand the keil startup assembly code because it initializes the minimal hardware to work with C language. I am stuck at this line:
IF PLL_SETUP <> 0
What is the meaning of the above line? Specifically, the <> symbol? Please somebody help me figure out this assembly instruction.
This line is not assembly per se but a control directive. <> means "not equal". So, if the preprocessor symbol PLL_SETUP is not 0, the following block (until ELSE or ENDIF) is passed to the assembler, otherwise it's skipped.
Silly question, but I just can not find the necessary flag in gcc. Basically, I have in my C program the following inline assembler code
__asm__ __volatile__ ("lea ebx, [timings] \n\t");
When compiling, I get an errormessage which says: Error: invalid char '[' beginning operand 2[timings]'`
Now I remember that a long time ago I used some kind of flag that told the compiler that it is x86 inline assembly. But cant find it online, could maybe someone please tell me which flag i have to use?
Thank you so much!
You can't specify variables that way with GCC. See this document for a detailed description of how to use inline assembler. Also, keep in mind that GCC uses AT&T syntax, not Intel syntax, so you have to put your destinations on the right.
Try using __asm__ instead. Look here for more.
Also, try removing the \n\t from inside the assembly code.
i am designing a compiler in c . but for certain problems like big integers i have to code in assembly code . so how can i integrate assembly code in c?
i am wrting my code in dev cpp.. which i suppose uses gcc ... in windows..!!..
pls give me instructions for linux too
using asm
Good article : GCC-Inline-Assembly-HOWTO
Use the 'asm' instruction, e.g.
asm("movl %ecx %eax"); /* moves the contents of ecx to eax */
Don't you compile the runtime with your own compiler?
Note that another option is to use an external assembler (like AS). Less optimal, but the principle is portable. (though assembler syntaxes vary wildly)
Our own little compiler (which is GCC linking compatible) used AS for most of its assembler, and only acquired an own internal assembler after 8 year or so.
P.s. if you implement an internal assembler, have a look at NASM, their tables of assembler instructions and their addressing are really clean and can be often get converted (and used for regular updates for new instructions)