inline-assembly

“rdtsc”: “=a” (a0), “=d” (d0) what does this do? [duplicate]

℡╲_俬逩灬. 提交于 2020-01-04 02:03:09
问题 This question already has answers here : How to get the CPU cycle count in x86_64 from C++? (4 answers) Closed 6 months ago . I'm new to C++ and benchmarking I don't understand what the this part of the code does? So I found something about the edx, eax registers, but I don't fully understand how that plays into the code. So I understand this code essentially returns the current tick of the cpu cycle. So, does it store the current tick into the registers, one part in the hi and the other part

How do I ask the assembler to “give me a full size register”?

筅森魡賤 提交于 2020-01-02 07:55:11
问题 I'm trying to allow the assembler to give me a register it chooses, and then use that register with inline assembly. I'm working with the program below, and its seg faulting. The program was compiled with g++ -O1 -g2 -m64 wipe.cpp -o wipe.exe . When I look at the crash under lldb, I believe I'm getting a 32-bit register rather than a 64-bit register. I'm trying to compute an address (base + offset) using lea , and store the result in a register the assembler chooses: "lea (%0, %1), %2\n"

Keyboard interrupt handler for own kernel (C)

流过昼夜 提交于 2020-01-01 16:07:30
问题 I am writing a tiny OS as part of an assigment for school,but I got stuck when it comes to get keyboard input (press a key -> display it on screen). I am using the Bare Bones tutorial from osdev.org (gcc cross-compiler, GRUB bootloader, ld linker) and since I am in protected mode I can not use BIOS interrupts for input, that's why I have to write my own interrupt handler (?) but I'm not sure how to do that even after I read some osdev articles and forum discussions. Very similar problem (http

Keyboard interrupt handler for own kernel (C)

泪湿孤枕 提交于 2020-01-01 16:06:55
问题 I am writing a tiny OS as part of an assigment for school,but I got stuck when it comes to get keyboard input (press a key -> display it on screen). I am using the Bare Bones tutorial from osdev.org (gcc cross-compiler, GRUB bootloader, ld linker) and since I am in protected mode I can not use BIOS interrupts for input, that's why I have to write my own interrupt handler (?) but I'm not sure how to do that even after I read some osdev articles and forum discussions. Very similar problem (http

How to make a C program that can run x86 hex codes

独自空忆成欢 提交于 2020-01-01 03:16:08
问题 I have an array of hex codes that translate into assembly instructions and I want to create program in C that can execute these. unsigned char rawData[5356] = { 0x4C, 0x01, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x0C, 0x00, 0x00, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x2E, 0x74, 0x65, 0x78, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB4, 0x05, 0x00, 0x00, 0xA4, 0x01, 0x00, 0x00, 0x68, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x61, 0x00, 0x00, 0x00,

What is the difference between the encodings for the call instruction in x86 asm?

陌路散爱 提交于 2019-12-31 06:17:45
问题 For reference: an HTML extract of Intel's documentation for the call instruction. I am aware that section 3.1.1.3 explains this but I am having trouble understanding the manual, probably because it is too technical. What is the /2 and /3 inside FF /2 and FF /3 ? What is the difference between r/m32 and m16:32 ? r/m32 covers both 32-bit registers and memory operands so wouldn't that make m16:32 redundant? According to the manual call ptr16:32 is a "Call far, absolute, address given in operand"

using inline assembly with GCC

牧云@^-^@ 提交于 2019-12-31 03:59:08
问题 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 回答1:

How do I access local C variable in arm inline assembly?

北城以北 提交于 2019-12-30 09:53:31
问题 I want to access local variable declared in C in inline arm Assembly. How do I do that? Global variables can be accessed like this, int temp = 0; Function(){ __asm( ".global temp\n\t" "LDR R2, =temp\n\t" "LDR R2, [R2, #0]\n\t" ); } But how do I access local variables? I tried changing ".global" to ".local" for local variables, but it generated error (undefined reference to `temp'). The IDE I am using is KEIL. Any thoughts? Thanks in Advance. 回答1: According to GCC docs: 6.45.2.3 Output

How do I access local C variable in arm inline assembly?

与世无争的帅哥 提交于 2019-12-30 09:53:03
问题 I want to access local variable declared in C in inline arm Assembly. How do I do that? Global variables can be accessed like this, int temp = 0; Function(){ __asm( ".global temp\n\t" "LDR R2, =temp\n\t" "LDR R2, [R2, #0]\n\t" ); } But how do I access local variables? I tried changing ".global" to ".local" for local variables, but it generated error (undefined reference to `temp'). The IDE I am using is KEIL. Any thoughts? Thanks in Advance. 回答1: According to GCC docs: 6.45.2.3 Output

Not getting expected output using cmpxchg8b for unsigned long

笑着哭i 提交于 2019-12-29 10:07:52
问题 I am trying to write a simple compare and swap inline assembly code. Here is my code #include <stdio.h> #include <stdlib.h> #include <stdint.h> static inline unsigned long cas(volatile unsigned long* ptr, unsigned long old, unsigned long _new) { unsigned long prev=0; asm volatile("lock cmpxchg8b %0;" : "=m"(prev) : "m"(*ptr),"a"(old),"c"(_new) ); return prev; } int main() { unsigned long *a; unsigned long b=5,c; a=&b; c=cas(a,b,6); printf("%lu\n",c); return 0; } This code should ideally print