inline-assembly

How to load a avx-512 zmm register from a ioremap() address?

跟風遠走 提交于 2020-04-16 02:58:10
问题 My goal is to create a PCIe transaction with more than 64b payload. For that I need to read an ioremap() address. For 128b and 256b I can use xmm and ymm registers respectively and that works as expected. Now, I'd like to do the same for 512b zmm registers (memory-like storage?!) A code under license I'm not allowed to show here, uses assembly code for 256b: void __iomem *addr; uint8_t datareg[32]; [...] // Read memory address to ymm (to have 256b at once): asm volatile("vmovdqa %0,%%ymm1" :

Adding values in C using inline assembly

拟墨画扇 提交于 2020-03-14 18:29:22
问题 Im trying to get a grasp on the basics of inline assembly in C (ATT assembly), so Im practicing by adding 2 variables. Ok so this works as intended; the src variable gets copied to the dst variable and then the dst variable gets added by 5. The values of src and dst are 1 and 6 respectively. int src = 1; int dst = 0; asm ("mov %[SRC], %[DEST]\n\t" "add $5, %0" : [DEST] "=r" (dst)); : [SRC] "r" (src)); But when I try this out, the values of src and dst are still 1 and 6. I was expecting src to

segmentation fault(core dumped) error while using inline assembly

馋奶兔 提交于 2020-03-14 05:36:31
问题 I'm using inline assembly in GCC. I want to rotate a variable content 2 bits to the left (I moved the variable to the rax register and then rotate it 2 times). I wrote the code below but I faced segmentation fault(core dumped) error. I would be grateful if you could help me. uint64_t X = 13835058055282163712U; asm volatile( "movq %0 , %%rax\n" "rol %%rax\n" "rol %%rax\n" :"=r"(X) :"r"(X) ); printf("%" PRIu64 "\n" , X); 回答1: The key to understanding inline asm is to understand that each asm

Need Help Manipulating Registers in Inline Assembly (STM32F103 “BluePill”)

时间秒杀一切 提交于 2020-03-03 12:21:18
问题 I have some simple code I want to get working. What I'm trying to do is to switch Pin PA8 ON and OFF as fast as possible on the STM32F103 "BluePill" using Assembly. I'm having trouble with the correct syntax. __asm__ volatile ( "ldr r2, = (1<<8) \n\t" "str r2, = [odr] \n\t" "ldr r2, = ~(1<<8) \n\t" "str r2, = [odr] \n\t" : [odr] "=r" (GPIOA->regs->ODR) ); The compiler throws this error: Compiling .pio/build/genericSTM32F103C8/src/main.ino.cpp.o /tmp/ccLofo6i.s: Assembler messages: /tmp

Why can't local variable be used in GNU C basic inline asm statements?

柔情痞子 提交于 2020-02-28 09:46:20
问题 Why cannot I use local variables from main to be used in basic asm inline? It is only allowed in extended asm, but why so? (I know local variables are on the stack after return address (and therefore cannot be used once the function return), but that should not be the reason to not use them) And example of basic asm: int a = 10; //global a int b = 20; //global b int result; int main() { asm ( "pusha\n\t" "movl a, %eax\n\t" "movl b, %ebx\n\t" "imull %ebx, %eax\n\t" "movl %eax, result\n\t"

manipulating c variable via inline assembly [duplicate]

自作多情 提交于 2020-02-14 06:51:32
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to access c variable for inline assembly manipulation Given this code: #include <stdio.h> int main(int argc, char **argv) { int x = 1; printf("Hello x = %d\n", x); } I'd like to access and manipulate the variable x in inline assembly. Ideally, I want to change its value using inline assembly. GNU assembler, and using the AT&T syntax. Suppose I want to change the value of x to 11, right after the printf

Force GCC to pass arguments in registers

落花浮王杯 提交于 2020-02-06 03:46:38
问题 I'm starting to try to mess around with inlining ASM in C++, so I wrote up this little snippet: #include <iostream> int foo(int, int, int); int main(void) { return foo(1,2,3); } int foo(int a, int b, int c) { asm volatile("add %1, %0\n\t" "add %2, %0\n\t" "add $0x01, %0":"+r"(a):"r"(b), "r"(c):"cc"); } Which outputs the following assembly code: main: .LFB969: subq $40, %rsp .seh_stackalloc 40 .seh_endprologue call __main movl $3, %r8d movl $2, %edx movl $1, %ecx call _Z3fooiii ... stuff not

Error C2432 illegal reference to 16-bit data in 'second operand' of __asm

两盒软妹~` 提交于 2020-01-30 13:11:50
问题 In Visual Studio, I get this error when I compile my __asm in C. Does anybody know what is wrong with this code? I tried everything, but nothing works. I am trying to implement the bubble sort in assembly. unsigned short i = 0; unsigned short j = 0; unsigned short max = short(N-2); unsigned short tab[5]; tab[0] = 54; tab[1] = 123; tab[2] = 342; tab[3] = 5436; tab[4] = 1234; unsigned short a = 0; __asm { loop1: inc i mov j, 0 mov si, tab loop2: mov ax, [si] // <- Error C2432 on this line mov a

syscall from within GCC inline assembly [duplicate]

ⅰ亾dé卋堺 提交于 2020-01-28 01:24:12
问题 This question already has answers here : How to invoke a system call via sysenter in inline assembly? (2 answers) Closed 11 months ago . is it possible to write a single character using a syscall from within an inline assembly block? if so, how? it should look "something" like this: __asm__ __volatile__ ( " movl $1, %%edx \n\t" " movl $80, %%ecx \n\t" " movl $0, %%ebx \n\t" " movl $4, %%eax \n\t" " int $0x80 \n\t" ::: "%eax", "%ebx", "%ecx", "%edx" ); $80 is 'P' in ascii, but that returns

Access array defined in inline assembler from C

时光毁灭记忆、已成空白 提交于 2020-01-24 17:09:52
问题 I have an integer declared in Assembler, and I use it in C in the following way: asm( "number: \n" ".long 0xFFFFFFFF \n ); extern int number; int main(){ //do something with number } Now I want to declare a 32 byte array in Assembler. I tried the following: asm( "number: \n" ".long 0xFFFFFFFF \n" ".long 0xFFFFFFFF \n" ".long 0xFFFFFFFF \n" ".long 0xFFFFFFFF \n" ".long 0xFFFFFFFF \n" ".long 0xFFFFFFFF \n" ".long 0xFFFFFFFF \n" ".long 0xFFFFFFFF \n" ); extern unsigned char* number; int main() {