inline-assembly

Delphi assembler: understanding the Result register

人盡茶涼 提交于 2019-12-13 04:48:11
问题 I'm messing around with ASM in Delphi. From my understanding, EAX holds Result. In the following, I have to put RET at the end, otherwise Result is not correct (it is correct if the input is 0). What am I doing wrong, or should I say, what don't I understand about this? function MSb(const Val: Integer): Integer; label Go; asm CMP EAX, 0 JNZ Go MOV EAX, -1 RET Go: BSR EBX, EAX MOV EAX, EBX RET end; If I say the following: MOV Result, EBX Then I get the following compilation: MOV [EPB-$04], EBX

Memory offsets in inline assembly

橙三吉。 提交于 2019-12-12 21:15:13
问题 In A64 assembler, there are different ways to specify addresses. /* [base{,#0}] Simple register (exclusive) - Immediate Offset [base{,#imm}] Offset - Immediate Offset [base,Xm{,LSL #imm}] Offset - Register Offset [base,Wm,(S|U)XTW {#imm}] Offset - Extended Register Offset [base,#imm]! Pre-indexed - Immediate Offset [base],#imm Post-indexed - Immediate Offset label PC-relative (literal) load - Immediate Offset */ I would like to use "Offset - Immediate Offset" in inline assembler. __asm__("ldp

call asm sqrtsd under a c++

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 20:08:05
问题 Under visual 2012 how can I call the sqrtsd asm function in a c++ project I can't find it via google something like : double mySqrt(double val) { __asm { ... sqrstd... } } EDIT: in 32bit mode 回答1: I think doing this is a somewhat academic excercise, as it's unlikely to have any actual benefit, and quite likely a penalty. However: double mySqrt(double val) { double retu; __asm { sqrtsd xmm1, val movsd retu, xmm1 } return retu; } 回答2: Why not using sqrt function http://www.cplusplus.com

Rewriting GCC inline assembly to not require volatile or a memory clobber

别来无恙 提交于 2019-12-12 19:09:42
问题 Is it possible to rewrite or improve this function to not require volatile or a generic memory clobber in its inline assembly? // do stuff with the input Foo structure and write the result to the // output Bar structure. static inline void MemFrob(const struct Foo* input, struct Bar* output) { register const Foo* r0 asm("r0") = input; register Bar* r1 asm("r1") = output; __asm__ __volatile__( "svc #0x0f0000 \n\t" : "+r" (r0), "+r" (r1) : : "r2", "r3", "cc", "memory" ); } For this specific

C Inline assembly - Operand type mismatch for 'fst'

倾然丶 夕夏残阳落幕 提交于 2019-12-12 17:49:47
问题 Hey Im trying to learn how to write assembly code in my C programs. I understand integers in assembly but floats continue to trip me up. double asmSqrt(double x) { double o; __asm__ ("fld %1;" "fsqrt;" "fst %0;" : "=g" (o) : "g" (x) ); return o; } As you can see Im just trying to find the square root of x. But whenever I try to compile it I get an operand type mismatch error. I followed the same syntax used here: http://www.codeproject.com/KB/cpp/edujini_inline_asm.aspx?display=Print PS: Im

Access the flags without inline assembly?

ぃ、小莉子 提交于 2019-12-12 15:47:21
问题 I have the following method in C that takes two 16-bit short ints and: Adds the two integers If the carry flag is set, add 1 to the result Negate (NOT) all the bits in the final results Return the result: short __declspec(naked) getchecksum(short s1, short s2) { __asm { mov ax, word ptr [esp+4] mov bx, word ptr [esp+8] add ax, bx jnc skip_add add ax, 1 skip_add: not ax ret } } I had to write this in inline assembly because I do not know any way to test the carry flag without using assembler.

How to write a C function invoked from assembly code

旧巷老猫 提交于 2019-12-12 13:14:44
问题 I need to write a C function that will be invoked from assembly code in linux kernel. What special issues should be taken into account? I have some in mind, but can anybody provide more details: (1) Calling convention Make sure the caller in assembly and the callee in c shake hands well. But which calling convention should I use? How can I declare the c function and declare it in assembly code? (2) Protect registers Some registers should be saved in the assembly before the invoke. I roughly

Implementation of AES in assembly [closed]

感情迁移 提交于 2019-12-12 13:05:08
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 8 years ago . Hello Everyone I am trying to build a code to do demonstrate doing AES encryption in assembly. the latest Intel manual has AESENC xmm1,xmm2/m128 —Perform One Round of an AES Encryption Flow round key from the

How to read registers: RAX, RBX, RCX, RDX, RSP. RBP, RSI, RDI in C or C++? [duplicate]

☆樱花仙子☆ 提交于 2019-12-12 12:24:54
问题 This question already has an answer here : How can you pull a value from a register? (1 answer) Closed 5 years ago . Lets say I want to read values from those registers (and pretty all thats it) on dual core x64 CPU. How can I do this? Can I simply write something like: uint64_t rax = 0, rbx = 0; __asm__ __volatile__ ( /* read value from rbx into rbx */ "movq %%rdx, %0;\n" /* read value from rax into rax*/ "movq %%rax, %1;\n" /* output args */ : "=r" (rbx), "=r" (rax) : /* no input */ /*

invalid 'asm': nested assembly dialect alternatives

送分小仙女□ 提交于 2019-12-12 11:27:56
问题 I'm trying to write some inline assembly code with KNC instructions for Xeon Phi platform, using the k1om-mpss-linux-gcc compiler. I want to use a mask register into my code in order to vectorize my computation. Here it is my code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/time.h> #include <assert.h> #include <stdint.h> void* aligned_malloc(size_t size, size_t alignment) { uintptr_t r = (uintptr_t)malloc(size + --alignment + sizeof(uintptr_t)); uintptr_t t = r +