inline-assembly

Inline assembler call for subroutine

Hi, I have question about inline assembler. It's possible to call another assembler subroutine from inline assembler within the same function? For example: void FindValidPID(unsigned int &Pid) { __asm { sub esp, 20h mov eax, Pid add eax,eax call sub123 ; another assm subroutine mov Pid, ...

why does MS C++ add this code to assembly?

i have some code(inline assembly). void NativeLoop() { int m; __asm { PUSH ECX PUSH EDX MOV ECX, 100000000 NEXTLOOP: MOV EDX, ECX AND EDX, 0X7FFFFFFF MOV DWORD PTR m, EDX DEC ECX JNZ NEXTLOOP POP EDX POP ECX } } MS C++ Automagical...

why is this happening?

char* ReadNumericFormat = "%i"; int Read(void) { int Storage; __asm { LEA EAX, [Storage] PUSH EAX PUSH DWORD PTR [ReadNumericFormat] CALL DWORD PTR [scanf] ADD ESP, 8 MOV EAX, DWORD PTR [Storage] } } when the user enters "023919" the procedure returns 1...

How do you pass a string as an argument to the "call" instruction in inline assembly?

Essentially, I'd like to be able to do something like this: //assume myFunction is defined and takes one argument that is an int char * functionName = "myFunction"; int arg = 5; __asm{ push a call functionName } Basically I want to call a function whose name is stored in a string. What would be the proper syntax for doing thi...

In GCC-style extended inline asm, is it possible to output a "virtualized" boolean value, e.g. the carry flag?

If I have the following C++ code to compare two 128-bit unsigned integers, with inline amd-64 asm: struct uint128_t { uint64_t lo, hi; }; inline bool operator< (const uint128_t &a, const uint128_t &b) { uint64_t temp; bool result; __asm__( "cmpq %3, %2;" "sbbq %4, %1;" "setc %0;" : // outp...

How do I pass arguments to C++ functions when I call them from inline assembly.

So, I would like to be able to call functions from a c++ dll. For certain reasons, I would like to call them from an __asm block in my C++ code. My question is this: I know that before I call the function, I have to push its arguments on the stack in the order specified by the function's calling convention.However, can i simply do someth...

"Error: backward ref to unknown label..." in MinGW inline assembly

Once again, I play with MinGW inline assembly. #include <stdio.h> int foobar(int); int main(){ int n = 0; printf("Number: "); scanf("%d", &n); printf("\n%d",foobar(n)); return 0; } int foobar(int num){ int result = 0; asm(".intel_syntax noprefix\n"); asm("mov eax, num\n"); asm("add eax, 110b\n"); asm("sub eax, 2\n"); as...

What does '__asm__(".previous");' mean?

Hello everyone. While trying to compile my project, that uses some third party headers, with mingw 4.4, I encountered the following error: Assembler messages: Error: junk at end of line, first unrecognized character is '"' Error: unknown pseudo-op: '.previous' I found this code at the end of one of the included headers: __asm_...

C/C++ function definitions without assembly

Hi, I always thought that functions like printf() are in the last step defined using inline assembly. That deep into stdio.h is burried some asm code that actually tells CPU what to do. Something like in dos, first mov bagining of the string to some memory location or register and than call some int. But since x64 version of Visual Studi...

Calling assembly in GCC?

#include <stdlib.h> static inline uint xchg(volatile unsigned int *addr, unsigned int newval) { uint result; asm volatile("lock; xchgl %0, %1" : "+m" (*addr), "=a" (result) : "1" (newval) : "cc"); return result; } Can some one tell me what this code does exactly? I mean I have an idea or the parts of this command. "1" newva...

32bit to 64bit inline assembly porting

I have a piece of C++ code (compiled with g++ under a GNU/Linux environment) that load a function pointer (how it does that doesn't matter), pushes some arguments onto the stack with some inline assembly and then calls that function, the code is like : unsigned long stack[] = { 1, 23, 33, 43 }; /* save all the registers and the stack p...

How to determine values saved on the stack?

I'm doing some experimenting and would like to be able to see what is saved on the stack during a system call (the saved state of the user land process). According to http://lxr.linux.no/#linux+v2.6.30.1/arch/x86/kernel/entry_32.S it shows that the various values of registers are saved at those particular offsets to the stack pointer. He...

Converting to VFP assembler

Hi, i've had a go at converting this little bit of C code to ARM vfp assembler can anyone see any problems with it or possible improvements for(int j=0;j<count; j++) { output += array[j]*(*p++); } to this VFM assembly: for(int j=0;j<count;j++){ asm volatile( VFP_VECTOR_LENGTH(8) ...

is there any programming language that can bring together edit and compile / run ???

When I code, I always write little pieces of unit, and compile it often. This helps me to make sure that everything run correctly, but it's very time consumed. is there any programming language that can support us to do coding and running at the same time side by side ? i mean as soon as a key press leads to valid code, the effect of the...

Help in building an 16 bit os

I am trying to build an old 16 bit DOS like OS. My example kernel code: asm(".code16\n"); void putchar(char); int main() { putchar('A'); return 0; } void putchar(char val) { asm("movb %0, %%al\n" "movb $0x0E, %%ah\n" "int $0x10\n" : :"r"(val) ...

using in-line asm to write a for loop with 2 comparisons

I want to convert the for loop in the following code into assembly but i am not sure how to start. An explanation of how to do it and why it works would be appreciated. I am using VS2010, C++, writing for the x86. The code is as follows: for (n = 0; norm2 < 4.0 && n < N; ++n) { __asm{ ///a*a - b*b + x fld a // a ...

Creating a Hello World library function in assembly and calling it from C#

Let's say we use NASM as they do in this answer: how to write hellow world in assembly under windows. I got a couple of thoughts and questions regarding assembly combined with c# or any other .net languages for that matter. First of all I want to be able to create a library that has the following function HelloWorld that takes this par...

where did the _syscallN macros go in <linux/unistd.h>?

It used to be the case that if you needed to make a system call directly in linux without the use of an existing library, you could just include <linux/unistd.h> and it would define a macro similar to this: #define _syscall3(type,name,type1,arg1,type2,arg2,type3,arg3) \ type name(type1 arg1,type2 arg2,type3 arg3) \ { \ long __res; \ __a...

Intrinsics program (SSE) - g++ - help needed

Hi all, This is the first time I am posting a question on stackoverflow, so please try and overlook any errors I may have made in formatting my question/code. But please do point the same out to me so I may be more careful. I was trying to write some simple intrinsics routines for the addition of two 128-bit (containing 4 float variabl...

How do you call Win32 API functions from inline assembler?

Would somebody please tell me whats wrong with this code I am just calling a Sleep function from the kernel32.dll What's wrong? I am using Visual Studio 2008. Any help would be grateful. Thank you very much. __asm { mov eax, 77e2ef66h push 9999 call eax } ...