inline-assembly

GCC Inline Assembler “memory” Clobber don't prevent from re-arrange the code in ARM

时光总嘲笑我的痴心妄想 提交于 2021-02-10 06:14:04
问题 I read article about GCC Inline Assembler (http://www.ethernut.de/en/documents/arm-inline-asm.html). In this article, "memory" Clobber forces the compiler to store all cached values before and reload them after executing the assembler instructions. And it must retain the sequence. this is the example. The following code intends to multiply c with b, of which one or both may be modified by an interrupt routine. Disabling interrupts before accessing the variables and re-enable them afterwards

pcmpestri character units and countdown - x86-64 asm

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-08 11:12:14
问题 I’m trying to write a minimal loop around pcmpestri in x86-64 asm (actually in-line asm embedded in Dlang using the GDC compiler). There are a couple of things that I don’t understand I you are using pcmpestri with two pointers to strings, are the lengths of the strings in rax and rdx ? If so, what are the units? count in bytes always, or count in chars where 1 count = 2 bytes for uwords ? Does pcmpestri check for short strings? ie len str1 or str2 < 16 bytes or 8 uwords if uwords Does

Linux getting terminal arguments from _start not working with inline assembly in C

爷,独闯天下 提交于 2021-02-08 08:57:14
问题 I am trying to write my own _start function using inline assembly. But when I try to read argc and argv from stack (%rsp and %rsp + 8) I get wrong values. I don't know what I am doing wrong. #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <syscall.h> int main(int argc, char *argv[]) { printf("%d\n", argc); printf("%s\n", argv[0]); printf("got here\n"); return 0; } void _start() { __asm__( "xor %rbp, %rbp;" "movl (%rsp), %edi;" "lea 8(%rsp), %rsi;" "xor %rax, %rax;" "call

Linux getting terminal arguments from _start not working with inline assembly in C

非 Y 不嫁゛ 提交于 2021-02-08 08:57:03
问题 I am trying to write my own _start function using inline assembly. But when I try to read argc and argv from stack (%rsp and %rsp + 8) I get wrong values. I don't know what I am doing wrong. #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <syscall.h> int main(int argc, char *argv[]) { printf("%d\n", argc); printf("%s\n", argv[0]); printf("got here\n"); return 0; } void _start() { __asm__( "xor %rbp, %rbp;" "movl (%rsp), %edi;" "lea 8(%rsp), %rsi;" "xor %rax, %rax;" "call

Why does issuing empty asm commands swap variables?

北战南征 提交于 2021-02-07 17:34:30
问题 So I was messing around with inline assembly and compiled this using GCC 9 . The result was that the two variables a and b were swapped without actually issuing any direct commands. #include<cstdio> int main(){ int a(1),b(2),c(3); asm ("": "=r"(c):"r"(a)); asm ("": "=r"(a):"r"(b)); asm ("": "=r"(b):"r"(c)); printf("%d %d %d", a,b,c); } Can somebody explain what is going on here? 回答1: Basically random chance of variable allocation. (Or actually GCC's internal machinery's first choices). You

Why does issuing empty asm commands swap variables?

牧云@^-^@ 提交于 2021-02-07 17:34:22
问题 So I was messing around with inline assembly and compiled this using GCC 9 . The result was that the two variables a and b were swapped without actually issuing any direct commands. #include<cstdio> int main(){ int a(1),b(2),c(3); asm ("": "=r"(c):"r"(a)); asm ("": "=r"(a):"r"(b)); asm ("": "=r"(b):"r"(c)); printf("%d %d %d", a,b,c); } Can somebody explain what is going on here? 回答1: Basically random chance of variable allocation. (Or actually GCC's internal machinery's first choices). You

Use both SSE2 intrinsics and gcc inline assembler

北城以北 提交于 2021-02-07 02:49:32
问题 I have tried to mix SSE2 intrinsics and inline assembler in gcc. But if I specify a variable as xmm0/register as input then in some cases I get a compiler error. Example: #include <emmintrin.h> int main() { __m128i test = _mm_setzero_si128(); asm ("pxor %%xmm0, %%xmm0" : : "xmm0" (test) : ); } When compiled with gcc version 4.6.1 I get: >gcc asm_xmm.c asm_xmm.c: In function ‘main’: asm_xmm.c:10:3: error: matching constraint references invalid operand number asm_xmm.c:7:5: error: matching

Android Studio 64 bit inline ARM assembly

自作多情 提交于 2021-01-29 20:00:54
问题 I am trying to run some inline assembly code for aarch64 from Android Studio 3.4.2 and I got a compilation error error: Don't know how to handle indirect register inputs yet for constraint 'r' . My code snippet as follows std::string system_file = "/system/bin/sh"; std::int64_t file_descriptor = -1; #ifdef __aarch64__ __asm__ volatile("mov x8, #180\n\t" "mov x0, %1\n\t" "mov x1, #0\n\t" "svc #1\n\t" "mov %0, x0\n\t" :"=r"(file_descriptor) :"r"(system_file) :"x0","x1","x8" ); #endif ARM64

Getting INT 16h key scancode instead of character

▼魔方 西西 提交于 2021-01-28 09:26:14
问题 I'm writing a simple bootloader, and I have a getch function. char getch() { uint16_t inchar; __asm__ __volatile__ ("int $0x16\n\t" : "=a"(inchar) : "0"(0x0)); return (char)inchar; } I tried the first obvious solution, which is remove the casting to char of the inchar variable, but when I print it still returning a char instead of code. My println implementation: void println(char *str) { while (*str) { // AH=0x0e, AL=char to print, BH=page, BL=fg color __asm__ __volatile__ ("int $0x10" : :

Getting INT 16h key scancode instead of character

冷暖自知 提交于 2021-01-28 09:26:00
问题 I'm writing a simple bootloader, and I have a getch function. char getch() { uint16_t inchar; __asm__ __volatile__ ("int $0x16\n\t" : "=a"(inchar) : "0"(0x0)); return (char)inchar; } I tried the first obvious solution, which is remove the casting to char of the inchar variable, but when I print it still returning a char instead of code. My println implementation: void println(char *str) { while (*str) { // AH=0x0e, AL=char to print, BH=page, BL=fg color __asm__ __volatile__ ("int $0x10" : :