inline-assembly

Using inline assembly with serialization instructions

冷暖自知 提交于 2019-12-11 06:09:11
问题 We consider that we are using GCC (or GCC -compatible) compiler on a X86_64 architecture, and that eax , ebx , ecx , edx and level are variables ( unsigned int or unsigned int* ) for input and output of the instruction (like here). asm("CPUID":::); asm volatile("CPUID":::); asm volatile("CPUID":::"memory"); asm volatile("CPUID":"=a"(eax),"=b"(ebx),"=c"(ecx),"=d"(edx)::"memory"); asm volatile("CPUID":"=a"(eax):"0"(level):"memory"); asm volatile("CPUID"::"a"(level):"memory"); // Not sure of

ICC inline assembler doesn`t like push/pop

北战南征 提交于 2019-12-11 05:16:48
问题 I try to excute assembler inline with icc in msasm: int main (void) { __asm{ mov eax, 5h; //works push eax; // after shell command /opt/intel/bin/icc -use_msasm asm.c: // asm.c(7): (col. 5) error: Unsupported instruction form in asm // instruction push. //pop ebp; // the same }; printf("success!\n"); return 1; } Does anybody know why icc doesn`t accept push and pop? Thanks in advance! 回答1: You should use x64 version of registers instead. So the correct version should like this: __asm{ mov rax

Why does my program run on Ubuntu gcc but not OSX gcc?

我的梦境 提交于 2019-12-11 05:04:12
问题 So my homework, I ran it in Ubuntu, and it compiles fine and runs like the way it should. But when I run this in Mac OSX, it gets a bus error. Why is that? I'm compiling with gcc -m32 source.c -o test Here's the Mac OSX version (added prefixed underscores): #include <stdlib.h> #include <stdio.h> #include <string.h> char phrase[] = "slow but sure"; int sz; int phrasesz; char *arg; char *result; // Add any extra variables you may need here. int main(int argc, char* argv[]) { if (argc != 2) {

D Inline Assembler: error with function call

这一生的挚爱 提交于 2019-12-11 04:54:51
问题 I got a very special problem. For a VM I need to copy code from the instruction functions to a ubyte array and then execute this array (the technic is similiar to the inline macro vm in gcc), basically it works like this: __gshared void * sp = null, sb = null; //stack pointer and stack base __gshared void add() //the function is just there to access the instruction code { asm{db "INSTRUCTIONCODESTART";} //this is a key to know where the instruction code starts //instruction code here (sample

Access violation on 'ret' instruction

强颜欢笑 提交于 2019-12-11 04:44:33
问题 I've got this function, which consists mostly of inline asm. long *toarrayl(int members, ...){ __asm{ push esp mov eax, members imul eax, 4 push eax call malloc mov edx, eax mov edi, eax xor ecx, ecx xor esi, esi loopx: cmp ecx, members je done mov esi, 4 imul esi, ecx add esi, ebp mov eax, [esi+0xC] mov [edi], eax inc ecx add edi, 4 jmp loopx done: mov eax, edx pop esp ret } } And upon running, I get an access violation on the return instruction. I'm using VC++ 6, and it can sometimes mean

Error: invalid use of vector register at operand 1

给你一囗甜甜゛ 提交于 2019-12-11 04:32:46
问题 I'm learning GCC inline assembler under under ARM on a 64-bit Aarch64 device. I'm seeing an error message I don't quite understand. The error message in from GCC's inline assembler: $ gcc -DNDEBUG -g3 -O1 -march=armv8-a+crc+crypto test.cc -o test.exe /tmp/ccCHOWrn.s: Assembler messages: /tmp/ccCHOWrn.s:19: Error: invalid use of vector register at operand 1 -- `pmull v0,v0,v0' The sample program simply tries to exercise the polynomial multiply: $ cat test.cc #include <arm_neon.h> int main(int

can't find a register in class 'CREG' while reloading 'asm' - memcpy inline asm

自古美人都是妖i 提交于 2019-12-11 04:17:42
问题 I am trying to make an earlier verion Linux got compiled, you can download the source code from git://github.com/azru0512/linux-0.12.git. While compiling ''kernel/blk_drv/ramdisk.c'', I got error message below, ramdisk.c:36:10: error: can't find a register in class 'CREG' while reloading 'asm' ramdisk.c:40:10: error: can't find a register in class 'CREG' while reloading 'asm' ramdisk.c:36:10: error: 'asm' operand has impossible constraints ramdisk.c:40:10: error: 'asm' operand has impossible

Is it possible to call a built in function from assembly in C++

放肆的年华 提交于 2019-12-11 03:36:46
问题 Considering the following assembly code loop: #include <iostream> #define ADD_LOOP(i, n, v) \ asm volatile ( \ "movw %1, %%cx ;" \ "movq %2, %%rax ;" \ "movq $0, %%rbx ;" \ "for: ;" \ "addq %%rax, %%rbx ;" \ "decw %%cx ;" \ "jnz for ;" \ "movq %%rbx, %0 ;" \ : "=x"(v) \ : "n"(i), "x"(n) \ : "%cx", "%rax", "%rbx" \ ); int main() { uint16_t iter(10000); uint64_t num(5); uint64_t val; ADD_LOOP(iter, num, val) std::cout << val << std::endl; return 0; } Is possible to call a C function (or it's

C Inline Assembly label issue

丶灬走出姿态 提交于 2019-12-11 01:27:36
问题 I'm currently a total beginner with assembly and am learning how to use assembly inline with C for a class. That being said, I'm having a hard time with this particular error when I'm compiling my file: /tmp/cckHnU89.s: Assembler messages: /tmp/cckHnU89.s:550: Error: symbol `.L16' is already defined /tmp/cckHnU89.s:571: Error: symbol `.L18' is already defined /tmp/cckHnU89.s:576: Error: symbol `.L17' is already defined I tried replacing the names of the labels with other names since I noticed

Multi line inline assembly macro with strings

让人想犯罪 __ 提交于 2019-12-11 01:26:19
问题 I'm trying to implement a macro ( "MY_MACRO" ), which stores a string preceded by a 32 bit integer number in a certain section ("my_section") . Example: MY_MACRO(200, "my first string %u %x") ; Here are the options I tried and the problems I'm facing with. I would appreciate any help. ( gcc 4.7.3. MIPS cpu ) Option A: #define MY_MACRO(_num, _string)\ asm volatile(".pushsection .my_section");\ asm volatile(".byte %0, %1, %2, %3" : : "i"((_num >> 24) & 0xFF), "i"((_num >> 16) & 0xFF), "i"((_num