inline-assembly

a Simple “Hello World” Inline Assembly language Program in C/C++

匆匆过客 提交于 2019-12-12 08:46:20
问题 i use devcpp and borland c compiler.... asm { mov ax,4 // (I/O Func.) mov bx,1 // (Output func) mov cx,&name // (address of the string) mov dx,6 // (length of the string) int 0x21 // system call } in the above code snippets i want to print a string with the help of assembly language... but how can i put the address of the string in register cx.... is there something wrong in code??? 回答1: I don't have the Borland compiler on hand, so I might be misremembering its syntax, but have you tried

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

谁说我不能喝 提交于 2019-12-12 08:33:46
问题 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 something like this: int a=5; double b = 5.0; __asm{ push b push a call functionAddress } What worries me is the fact that I seem to remember that the standard word

error: ‘asm’ undeclared (first use in this function)

放肆的年华 提交于 2019-12-12 08:26:47
问题 I am getting the following error during compilation: error: ‘asm’ undeclared (first use in this function) EXCHANGE( s, *(a) ); ^ in a header file where the macro is invoked as follows: EXCHANGE( s, *(a) ); and the actual defintion of the macro is as follows: #define EXCHANGE(R,M) asm volatile ( "xchg %1, %0" : "+m" (M), "+r" (R) ) Macro invocation and definition exists in same header file. What's going wrong? I am using CMAKE to build the project and CFLAGS are as follows: set(CMAKE_C_FLAGS "

confusing with JMP instruction

风流意气都作罢 提交于 2019-12-12 04:39:21
问题 I write an inline assembly program to unlink "grades.txt" in /home/httpd , here is the code: void main() { __asm__( "jmp L\n"\ "sub1:\n"\ "movl 0x4(%esp), %ebx\n"\ "movb $0xa, %al\n"\ "int $0x80\n"\ "L:\n"\ "call sub1\n"\ ".string \"//home//httpd//grades.txt\" " ); } I think the code shall do what I want, to unlink the grades.txt in "/home/httpd", yet when I execute it, there is a segment fault. And I use gdb to tackle this fault, I found that it can't execute the line "jmp L", the program

inline assembly not showing output

喜欢而已 提交于 2019-12-12 04:24:08
问题 i am compiling this program in cygwin 64 bit windows, no output, compiles correctly #include <unistd.h> int main(void) { const char hello[] = "Hello World!\n"; const size_t hello_size = sizeof(hello); ssize_t ret; asm volatile ( "movl $1, %%eax\n\t" "movl $1, %%edi\n\t" "movq %1, %%rsi\n\t" "movl %2, %%edx\n\t" "syscall" : "=a"(ret) : "g"(hello), "g"(hello_size) : "%rdi", "%rsi", "%rdx", "%rcx", "%r11" ); return 0; } 回答1: Michael's comment does correctly define the problem. But as an

Insert an undefined instruction in X86 code to be detected by Intel PIN

巧了我就是萌 提交于 2019-12-12 04:18:46
问题 I'm using a PIN based simulator to test some new architectural modifications. I need to test a "new" instruction with two operands (a register and a memory location) using my simulator. Since it's tedious to use GCC Machine description to add only one instructions it seemed logical to use NOPs or Undefined Instructions. PIN would easily be able to detect a NOP instruction using INS_IsNop , but it would interfere with NOPs added naturally to the code, It also has either no operands or a single

Sleep() inline assembly call works but generates runtime check-failure

强颜欢笑 提交于 2019-12-12 01:36:44
问题 As the title of my question says the sleep() function works properly (and every other function call in the C function, the problem is that after it's finished running I get an error that says: "Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention." I believe the way I'm handling the registers when I call

how to let Inline assembly pass -O1 optimization

拈花ヽ惹草 提交于 2019-12-12 01:14:25
问题 I have following dispatch code for my user level thread library. The code can pass GCC and runs correctly without optimization, but if I choose -O1 optimization (also higher levels), when run the code, program generates segmentation fault. Basically the function does save context and jump to next context. void __attribute__ ((noinline)) __lwt_dispatch(lwt_context *curr, lwt_context *next) { __asm__ __volatile ( "mov 0xc(%ebp),%eax\n\t" "mov 0x4(%eax),%ecx\n\t" "mov (%eax),%edx\n\t" "mov 0x8(

Converting lowercase character string to uppercase masm

耗尽温柔 提交于 2019-12-11 17:57:44
问题 there is a printf statement which tells the compiler to print outStr. outStr is originally set to equal emptybuf[1000] = "??? not translated yet ???";. I am supposed to move my answer into the outStr, which should update the outStr in the print statement. For some reason my inline assembly will not print out anything from the code shown below. I cannot understand what I am doing wrong. I am trying to convert lowercase letters to uppercase, and ignore any special characters. Any advice is much

PowerPC Inline Assembly: Load C Value into Register

大憨熊 提交于 2019-12-11 16:59:15
问题 Using GCC and inline assembly , I want to load an immediate into a specific register r0 . However, I'm not getting the right results. unsigned short value = 0x1337; asm volatile ( "li 0, %0\n\t" "sc\n\t" "blr" : /* Output registers */ :"r"(value) /* Input registers */ : /* No clobbered registers */ ); When compiled, this gives li r0, 9 sc blr Where does the 9 come from? I wanted the specified value 0x1337 instead. Here is a tutorial I looked at. 回答1: 9 is the register containing 0x1337 ,