inline-assembly

What is the use of .byte assembler directive in gnu assembly?

可紊 提交于 2019-11-27 03:22:38
问题 While going through some C code having inline assembly I came across the .byte (with a Dot at the beginning) directive. On checking the assembly reference on web I found that it is used to reserve a byte in memory. But in the code there was no label before the statement. So I was wondering what is use of an unlabeled .byte directive or any other data storage directive for that matter. For e.g. if i code .byte 0x0a , how can i use it ? 回答1: There are a few possibilities... here are a couple I

Is it possible to write inline assembly in Swift?

非 Y 不嫁゛ 提交于 2019-11-27 03:09:27
问题 I was wondering if you can write inline assembly in Swift. I know that in Objective-C you could use something like this: inline void assemblyFunc() { __asm__(/*Assembly*/); } But in Swift it seems that you can't use __asm__(/*Assembly*/) . Does anyone know how to use __asm__() if its even possible. I haven't found anything about it, so I thought it would be a good question to ask. 回答1: To expand on what Robert Levy said, you can just use the Swift/Obj-C interop feature, and write an Obj-C

at&t asm inline c++ problem

♀尐吖头ヾ 提交于 2019-11-26 23:40:42
问题 My Code const int howmany = 5046; char buffer[howmany]; asm("lea buffer,%esi"); //Get the address of buffer asm("mov howmany,%ebx"); //Set the loop number asm("buf_loop:"); //Lable for beginning of loop asm("movb (%esi),%al"); //Copy buffer[x] to al asm("inc %esi"); //Increment buffer address asm("dec %ebx"); //Decrement loop count asm("jnz buf_loop"); //jump to buf_loop if(ebx>0) My Problem I am using the gcc compiler. For some reason my buffer/howmany variables are undefined in the eyes of

Is this assembly function call safe/complete?

淺唱寂寞╮ 提交于 2019-11-26 22:06:17
问题 I don't have experience in assembly, but this is what I've been working on. I would like input if I'm missing any fundamental aspects to passing parameters and calling a function via pointer in assembly. For instance I'm wondering if I supposed to restore ecx , edx , esi , edi . I read they are general purpose registers, but I couldn't find if they need to be restored? Is there any kind of cleanup I am supposed to do after a call? This is the code I have now, and it does work: #include "stdio

x86/x64 CPUID in C#

[亡魂溺海] 提交于 2019-11-26 21:35:42
Related to my other question , please help me debug "An unhandled exception of type 'System.AccessViolationException' occurred in Unknown Module. Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt." Stepping through the code, everything works up until the actual call to del() and fails in that line. This code is based on this article's sample and this python code which works in python. I can't get the code example as-is to work either (same exception), but I'm hopeful that it's just a little outdated or something. EDIT:

C/C++ function definitions without assembly

╄→尐↘猪︶ㄣ 提交于 2019-11-26 21:19:44
I always thought that functions like printf() are, in the last step, defined using inline assembly. That deep in the bowels of stdio.h is buried some asm code that actually tells CPU what to do. For example, in dos, I remember it was implemented by first mov ing the beginning of the string to some memory location or register and than calling an int terupt. However, since the x64 version of Visual Studio doesn't support inline assembler at all, it made me wonder how there could be no assembler-defined functions at all in C/C++. How does a library function like printf() get implemented in C/C++

Calling printf in extended inline ASM

☆樱花仙子☆ 提交于 2019-11-26 20:57:22
I'm trying to output the same string twice in extended inline ASM in GCC , on 64-bit Linux. int main() { const char* test = "test\n"; asm( "movq %[test], %%rdi\n" // Debugger shows rdi = *address of string* "movq $0, %%rax\n" "push %%rbp\n" "push %%rbx\n" "call printf\n" "pop %%rbx\n" "pop %%rbp\n" "movq %[test], %%rdi\n" // Debugger shows rdi = 0 "movq $0, %%rax\n" "push %%rbp\n" "push %%rbx\n" "call printf\n" "pop %%rbx\n" "pop %%rbp\n" : : [test] "g" (test) : "rax", "rbx","rcx", "rdx", "rdi", "rsi", "rsp" ); return 0; } Now, the string is outputted only once. I have tried many things, but I

Inline assembly that clobbers the red zone

三世轮回 提交于 2019-11-26 20:52:34
问题 I'm writing a cryptography program, and the core (a wide multiply routine) is written in x86-64 assembly, both for speed and because it extensively uses instructions like adc that are not easily accessible from C. I don't want to inline this function, because it's big and it's called several times in the inner loop. Ideally I would also like to define a custom calling convention for this function, because internally it uses all the registers (except rsp ), doesn't clobber its arguments, and

Labels in GCC inline assembly

可紊 提交于 2019-11-26 19:49:11
In my ongoing experimentation with GCC inline assembly, I've run into a new problem regarding labels and inlined code. Consider the following simple jump: __asm__ ( "jmp out;" "out:;" : : ); This does nothing except jump to the out label. As is, this code compiles fine. But if you place it inside a function, and then compile with optimization flags, the compiler complains: "Error: symbol 'out' is already defined". What seems to be happening is that the compiler is repeating this assembly code every time it inlines the function. This causes the label out to get duplicated, leading to multiple

Efficient integer compare function

余生长醉 提交于 2019-11-26 19:33:41
The compare function is a function that takes two arguments a and b and returns an integer describing their order. If a is smaller than b , the result is some negative integer. If a is bigger than b , the result is some positive integer. Otherwise, a and b are equal, and the result is zero. This function is often used to parametrize sorting and searching algorithms from standard libraries. Implementing the compare function for characters is quite easy; you simply subtract the arguments: int compare_char(char a, char b) { return a - b; } This works because the difference between two characters