inline-assembly

Impossible constraint in 'asm': __asm__ __volatile__

心不动则不痛 提交于 2019-12-25 07:21:30
问题 I trying since a few days to write a very simple inline assembler code, but nothing worked. I have as IDE NetBeans and as compiler MinGW. My latest code is: uint16 readle_uint16(const uint8 * buffer, int offset) { unsigned char x, y, z; unsigned int PORTB; __asm__ __volatile__("\n" "addl r29,%0\n" "addl r30,%1\n" "addl r31,%2\n" "lpm\n" "out %3,r0\n" : "=I" (PORTB) : "r" (x), "r" (y), "r" (z) ); return value; } But I get everytime the same message "error: impossible constraint in 'asm'". I

Referencing memory operands in .intel_syntax GNU C inline assembly

与世无争的帅哥 提交于 2019-12-24 23:16:40
问题 I'm catching a link error when compiling and linking a source file with inline assembly. Here are the test files: via:$ cat test.cxx extern int libtest(); int main(int argc, char* argv[]) { return libtest(); } $ cat lib.cxx #include <stdint.h> int libtest() { uint32_t rnds_00_15; __asm__ __volatile__ ( ".intel_syntax noprefix ;\n\t" "mov DWORD PTR [rnds_00_15], 1 ;\n\t" "cmp DWORD PTR [rnds_00_15], 1 ;\n\t" "je done ;\n\t" "done: ;\n\t" ".att_syntax noprefix ;\n\t" : : [rnds_00_15] "m" (rnds

How to format an assembly code?

强颜欢笑 提交于 2019-12-24 20:32:40
问题 I have a rather long code written in assembly language and I want to use it inside a C program using asm() function, but every line in the code must be quoted and a new line character ('\n') must be inserted at the end of each line in order to make it usable. Is there any text editing tool that can do that or I have to do it manually? 回答1: I wrote a program that gets the assembly code from file a.s and saves the formatted text into file b.s . #include <stdio.h> #include <stdlib.h> int main ()

Sum 1 + 11 + 111… n terms in x86 Assembly

梦想与她 提交于 2019-12-24 19:24:21
问题 So I'm trying to sum 1 + 11 + 111 given a number, n, which determines how many values of the series I add together. i.e n = 2, I will add 1 + 11, or n = 3, I will add 1 + 11 + 111. I have written the function in C already, but I am trying to translate it into x86 assembly and I am having trouble. Here is the C function: int summation(int n) { int sum = 0, j = 1; for (int i = 1; i <= n; i++) { sum = sum + j; // Appending a 1 at the end j = (j * 10) + 1; } return sum; Here is my x86 assembly

Inline assembly in C program on x86_64 linux

家住魔仙堡 提交于 2019-12-24 18:09:49
问题 I've built a short program written on C and inline assembly on my linux x86_64. It is supposed to write a string to stdout. I found it in an article on the internet: int write_call( int fd, const char * str, int len ){ long __res; __asm__ volatile ( "int $0x80": "=a" (__res):"0"(__NR_write),"b"((long)(fd)),"c"((long)(str)),"d"((long)(len)) ); return (int) __res; } void do_write( void ){ char * str = "Paragon output string.\n"; int len = strlen( str ), n; printf( "string for write length = %d

substring — c inline assembly code

人盡茶涼 提交于 2019-12-24 17:18:30
问题 I write a code that get substring of a string with gcc inline assembly. but always get problem when I want to get the substring whose length is 8. here is the code static inline char * asm_sub_str(char *dest, char *src, int s_idx, int edix) { __asm__ __volatile__("cld\n\t" "rep\n\t" "movsb" : :"S"(src + s_idx), "D"(dest), "c"(edix - s_idx + 1) ); return dest; } int main(int argc, char *argv[]) { char my_string[STRINGSIZE] = "abc defghij"; char asm_my_sub_string[STRINGSIZE]; int sidx,eidx;

gcc inlined assembly jmp address; Naked functions

梦想的初衷 提交于 2019-12-24 12:22:01
问题 I can jmp to an address using Visual Studio 2012.. When it comes to gcc/mingw, I cannot tell if my jump is correct. How can I jump to an address in gcc? I tried: __declspec(naked) void DXHook_D3DPERF_BeginEvent() { #ifdef _MSC_VER //If using visual studio.. __asm{jmp[Addr]} //Jump to: Address stored in Addr. #else //else using gcc.. __asm("jmp *%0" : /*No Outputs*/ : "r" (Addr) : "%eax"); #endif } Is this correct? Also, is there a way to get gcc to stop bothering me about: warning: 'naked'

replace inline assembly tailcall function epilogue with Intrinsics for x86/x64 msvc

老子叫甜甜 提交于 2019-12-24 11:35:20
问题 I took an inactive project and already fixed a lot in it, but I don't get an Intrinsics replacement correctly to work for the used inline assembly, which is no longer supported in the x86/x64 msvc compilers. #define XCALL(uAddr) \ __asm { mov esp, ebp } \ __asm { pop ebp } \ __asm { mov eax, uAddr } \ __asm { jmp eax } Use cases: static oCMOB * CreateNewInstance() { XCALL(0x00718590); } int Copy(class zSTRING const &, enum zTSTR_KIND const &) { XCALL(0x0046C2D0); } void TrimLeft(char) { XCALL

GCC Inline Assembly to IAR Inline Assembly

纵然是瞬间 提交于 2019-12-24 07:46:37
问题 I am attempting to use BeRTOS for a Texas Instruments Stellaris Cortex-M3. My work environment is IAR. There were a lot of minor changes to accommodate IAR and the specific uC that I am using but I've got one that I can't seem to solve... and frankly it's a bit over my head. This bit of code: 1 void NAKED lm3s_busyWait(unsigned long iterations) 2 { 3 register uint32_t __n __asm("r0") = iterations; 4 5 __asm volatile ( 6 "1: subs r0, #1\n\t" 7 "bne 1b\n\t" 8 "bx lr\n\t" 9 : : "r"(__n) :

Can I use asm function with a c - string variable instead of a string literal as an argument?

人盡茶涼 提交于 2019-12-24 06:58:09
问题 I did something like this : char command [] = "Some assmebly code"; asm volatile(command); It didnt work. Specifically, I get the following error : Expected string literal before command. So, can I only use string literals with C inline assembly ? I really want to be able to use string variables like above. How can I achieve this effect ? 回答1: As far as I know asm code fragment are inlined during compilation phase, not run-time. Which means you can't do what you are doing. As pmg suggested,