inline-assembly

Using condition flags as GNU C inline asm outputs

╄→гoц情女王★ 提交于 2019-12-01 02:33:00
问题 I'm working on some code where it would be highly desirable to take condition-flags output from an inline asm block and use that as a condition to branch on in the calling C code. I don't want to store the flags (that would be useless and inefficient; there are already more efficient ways to achieve the result) but use the flags directly. Is there any way to achieve this with GNU C inline asm constraints? I'm interested in approaches that would work for multiple instruction set architectures,

What does %c mean in GCC inline assembly code?

心已入冬 提交于 2019-12-01 02:12:28
问题 I am trying to understand this inline assembly code which comes from _hypercall0 here. asm volatile ("call hypercall_page+%c[offset]" \ : "=r" (__res) \ : [offset] "i" (__HYPERVISOR_##name * sizeof(hypercall_page[0])) \ : "memory", "edi", "esi", "edx", "ecx", "ebx", "eax") I am having trouble finding information on what %c in the first line means. I did not find any information in the most obvious section of the GCC manual, which explains %[name] , but not %c[name] . Is there any other place

Constraining r10 register in gcc inline x86_64 assembly

末鹿安然 提交于 2019-12-01 00:51:53
问题 I'm having a go at writing a very light weight libc replacement library so that I can better understand the kernel - application interface. The first task is clearly getting some system call wrappers in place. I've successfully got 1 to 3 argument wrappers working but I'm struggling with a 4 argument varient. Here's my starting point: long _syscall4(long type, long a1, long a2, long a3, long a4) { long ret; asm ( "syscall" : "=a"(ret) : "a"(type), "D"(a1), "S"(a2), "d"(a3), "r10"(a4) : "c",

How to write multiline inline assembly code in GCC C++?

送分小仙女□ 提交于 2019-12-01 00:42:59
问题 This does not look too friendly: __asm("command 1" "command 2" "command 3"); Do I really have to put a doublequote around every line? Also... since multiline string literals do not work in GCC, I could not cheat with that either. 回答1: I always find some examples on Internet that the guy manually insert a tab and new-line instead of \t and \n, however it doesn't work for me. Not very sure if your example even compile.. but this is how I do: VERY ugly way: asm("xor %eax,%eax"); asm("mov

Edit Memory Address via c#

荒凉一梦 提交于 2019-11-30 22:33:37
i want to edit an active app (edit a memory address), on address 00498D45 i want to edit its value currect value : MOV BYTE PTR SS:[EBP-423],7 to updated value: MOV BYTE PTR SS:[EBP-423],8 what i got till now is this (searched about it on the net and this how far i got): thanks in advance! using System.Runtime.InteropServices; [Flags] public enum ProcessAccessFlags : uint { All = 0x001F0FFF, Terminate = 0x00000001, CreateThread = 0x00000002, VMOperation = 0x00000008, VMRead = 0x00000010, VMWrite = 0x00000020, DupHandle = 0x00000040, SetInformation = 0x00000200, QueryInformation = 0x00000400,

Scan from stdin and print to stdout using inline assembly in gcc

末鹿安然 提交于 2019-11-30 21:08:53
问题 How to read from stdin and write to stdout in inline assembly gcc, just like we do it in NASM: _start: mov ecx, buffer ;buffer is a data word initialised 0h in section .data mov edx, 03 mov eax, 03 ;read mov ebx, 00 ;stdin int 0x80 ;Output the number entered mov eax, 04 ;write mov ebx, 01 ;stdout int 0x80 I tried reading from stdin in inline assembly and then assign the input to x: #include<stdio.h> int x; int main() { asm(" movl $5, %%edx \n\t" " movl $0, %%ebx \n\t" " movl $3, %%eax \n\t" "

Force GCC to push arguments on the stack before calling function (using PUSH instruction)

主宰稳场 提交于 2019-11-30 21:06:43
问题 I have started developing a small 16-bit OS under GCC/G++. I am using a GCC cross-compiler, which I compiled under Cygwin, I am putting asm(".code16gcc\n") as the first line of each .CPP file, using Intel ASM syntax and the command lines for compiling and linking a .CPP file look like this: G++: i586-elf-g++ -c $(CPP_FILE) -o $(OBJECT_OUTPUT) -nostdinc -ffreestanding -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fpermissive -masm=intel LD: i586-elf-ld -T $(LD_SCRIPT) $(OBJECT_OUTPUT) -o $

How to use a global variable in gcc inline assembly

99封情书 提交于 2019-11-30 19:19:30
I am trying to use inline assembly like this, for a global variable, but the compiler gives an error by saying undefined reference to saved_sp . __asm__ __volatile__ ( "movq saved_sp, %rsp\n\t" ); saved_sp is declared as static long saved_sp globally (for a file that is). What mistake am I doing here? If it fails with "undefined reference to `saved_sp' " (which is really a linker error, not a compiler error) when saved_sp is static , but works when it is not, then it seems likely that the compiler has decided that saved_sp is not used in your source file, and has therefore decided to omit it

Edit Memory Address via c#

南笙酒味 提交于 2019-11-30 17:53:33
问题 i want to edit an active app (edit a memory address), on address 00498D45 i want to edit its value currect value : MOV BYTE PTR SS:[EBP-423],7 to updated value: MOV BYTE PTR SS:[EBP-423],8 what i got till now is this (searched about it on the net and this how far i got): thanks in advance! using System.Runtime.InteropServices; [Flags] public enum ProcessAccessFlags : uint { All = 0x001F0FFF, Terminate = 0x00000001, CreateThread = 0x00000002, VMOperation = 0x00000008, VMRead = 0x00000010,

How to: Inline assembler in C++ (under Visual Studio 2010)

北战南征 提交于 2019-11-30 15:45:57
问题 I'm writing a performance-critical, number-crunching C++ project where 70% of the time is used by the 200 line core module. I'd like to optimize the core using inline assembly, but I'm completely new to this. I do, however, know some x86 assembly languages including the one used by GCC and NASM. All I know: I have to put the assembler instructions in _asm{} where I want them to be. Problem: I have no clue where to start. What is in which register at the moment my inline assembly comes into