inline-assembly

gcc, inline assembly - pushad/popad missing?

試著忘記壹切 提交于 2019-12-02 07:27:45
问题 Any way to avoid having to copy-paste the pushad / popad instruction body into my code? Because gcc (current flags: -Wall -m32 ) complains that __asm__("pushad;"); Error: no such instruction: `pushad' __asm__("popad;"); Error: no such instruction: `popad' 回答1: GCC use AT/T assembly syntax, while pushad/popad are Intel convention, try this: __asm__("pushal;"); __asm__("popal;"); 来源: https://stackoverflow.com/questions/37157552/gcc-inline-assembly-pushad-popad-missing

How to write .syntax unified UAL ARMv7 inline assembly in GCC?

爱⌒轻易说出口 提交于 2019-12-02 07:22:01
I want to write unified assembly to get rid of pesky # in front of my literals as mentioned at: Is the hash required for immediate values in ARM assembly? This is a minimal non-unified code with # : #include <assert.h> #include <inttypes.h> int main(void) { uint32_t io = 0; __asm__ ( "add %0, %0, #1;" : "+r" (io) : : ); assert(io == 1); } which compiles and later runs fine under QEMU: arm-linux-gnueabihf-gcc -c -ggdb3 -march=armv7-a -pedantic -std=c99 -Wall -Wextra \ -fno-pie -no-pie -marm -o 'tmp.o' 'tmp.c' If I try to remove the # , then the code fails with: /tmp/user/20321/ccoBzpSK.s:

Cannot read back from MSR

久未见 提交于 2019-12-02 06:37:28
I am writing a kernel module and it is about reading and writing MSRs. I wrote a simple program for testing but it still fails. All it is doing is writing to MSR, then reading it back. Here is the code: static int __init test3_init(void) { uint32_t hi,lo; hi=0; lo=0xb; asm volatile("mov %0,%%eax"::"r"(lo)); asm volatile("mov %0,%%edx"::"r"(hi)); asm volatile("mov $0x38d,%ecx"); asm volatile("wrmsr"); printk("exit_write: hi=%08x lo=%08x\n",hi,lo); asm volatile("mov $0x38d,%ecx"); asm volatile("rdmsr":"=a"(lo),"=d"(hi)); printk("exit_write2: hi=%08x lo=%08x\n",hi,lo); return 0; } The output

(inline assembly in C) Assembler messages: Error: unknown pseudo-op:

谁说我不能喝 提交于 2019-12-02 05:55:21
问题 I have written a short C "wrapper" function for an asm inline assembly, as below. The assembly code consists of a while loop, computing several vector dot product using SSE2. I am using GCC 4.8.4 on Ubuntu 14.04 on an x86. The following code can be assembled "without problem" under gcc -fpic -O2 -msse2 -S foo.c But when I do gcc -c foo.s an error is triggered: foo.c: Assembler messages: foo.c:2: Error: unknown pseudo-op: `.while5' I checked the assembler ouput "foo.s" and found something

using inline assembly with GCC

夙愿已清 提交于 2019-12-02 05:34:25
I'm tring to convert a simple assembly code of MS to use with gcc, the MS assembly I try to convert is right below. I have two int variables, number and _return : mov eax, number neg eax return, eax and, I have tried this: asm("movl %eax, %0" :: "g" ( number)); asm("neg %eax"); asm("movl %0, %%eax" : "=g" ( return )); But, the compiler gives me this error: main.c:17:9: error: invalid 'asm': operand number missing after %-letter Where is the error, and, how I can fix this error? Thanks You can't do it like that because you're overwriting registers without telling the compiler about it. Also,

Convert inline Intel ASM to AT&T ASM with GCC Extended ASM

巧了我就是萌 提交于 2019-12-02 03:57:06
I've spent the last 2 days to study AT&T inline assembly, but I'm having some problems converting this one: static char vendername[50] = {0}; _asm { mov eax, 0 cpuid mov dword ptr [vendername], ebx mov dword ptr [vendername+4], edx mov dword ptr [vendername+8], ecx } Here is my try: static char vendername[50] = {0}; __asm__( "movl $0,%%eax \n" "cpuid \n" "movl %%ebx, %[vendername] \n" "movl %%edx, %[vendername+$4] \n" "movl %%ecx, %[vendername+$8] \n" :"=r"(vendername) //user vendername as output :[vendername]"m"(vendername) //use vendername as input :"eax","ebx","edx","ecx" // clobbers those

executing assembly within a function in c++

为君一笑 提交于 2019-12-02 03:37:57
long getesp() { __asm__("movl %esp,%eax"); } void main() { printf("%08X\n",getesp()+4); } why does esp points to value before the stack frame is setup and does it makes any difference between with the code below? void main() { __asm__("movl %esp,%eax"); } After i did a gcc -S file.c getesp: pushl %ebp movl %esp, %ebp subl $4, %esp #APP # 4 "xxt.c" 1 movl %esp,%eax # 0 "" 2 #NO_APP leave ret main: leal 4(%esp), %ecx andl $-16, %esp pushl -4(%ecx) pushl %ebp movl %esp, %ebp pushl %ecx subl $20, %esp call getesp addl $4, %eax movl %eax, 4(%esp) movl $.LC0, (%esp) call printf addl $20, %esp popl

Accessing C++ class member in inline assembly

拈花ヽ惹草 提交于 2019-12-02 03:18:06
Question: How can I access a member variable in assembly from within a non-POD class? Elaboration: I have written some inline assembly code for a class member function but what eludes me is how to access class member variables. I've tried the offsetof macro but this is a non-POD class. The current solution I'm using is to assign a pointer from global scope to the member variable but it's a messy solution and I was hoping there was something better that I dont know about. note: I'm using the G++ compiler. A solution with Intel syntax Asm would be nice but I'll take anything. example of what I

Implementing a matcher for the regex '[ab][^r]+r]' in assembly

无人久伴 提交于 2019-12-02 02:34:58
问题 I need help with my assembly code. I need to use write code, that will find range, that suit to my regex expression. My regex: [ab][^r]+r , so first i'm looking for if there is 'a' or 'b' and jump to 'Start' section. Now i have a problem how to save only first occurrence of this letter. Program should display: 5, 10 - it means, that matching string starts at 5 position and it has 10 length. Result of program i want to save in 'ecx' and 'edx' registries(or can i simplify it?) I would

Implementing a matcher for the regex '[ab][^r]+r]' in assembly

泄露秘密 提交于 2019-12-02 02:30:06
I need help with my assembly code. I need to use write code, that will find range, that suit to my regex expression. My regex: [ab][^r]+r , so first i'm looking for if there is 'a' or 'b' and jump to 'Start' section. Now i have a problem how to save only first occurrence of this letter. Program should display: 5, 10 - it means, that matching string starts at 5 position and it has 10 length. Result of program i want to save in 'ecx' and 'edx' registries(or can i simplify it?) I would appreciate all suggestions and help :) Here is a code: #include <stdio.h> int main(void) { char *s = "fqr b