All Questions
19 questions
3
votes
1
answer
780
views
Bad Instruction - Inline Assembly Language in C Code
I'm trying to exit a program with assembly instructions, but when I compile with gcc it says that mov is a bad instruction, even when I use movl which I don't even know what it is. Is it even possible ...
1
vote
1
answer
58
views
Start gas x86 n get segfault?
Help I can't understand why get segfault.
void *cp1(void *a, const void *b, size_t c){
c=0;
asm volatile(
"movl $0x1,0x10(%%ebp)\n\t"
:::);
printf("n %zu\n",c);
...
0
votes
0
answers
735
views
How to access array elements in GCC inline assembly? [duplicate]
I want to calculate a sum of elements of an array using GCC inline assembly as an exercise. I need to access the elements. I tried this code:
#include <stdio.h>
#include <stdlib.h>
int ...
3
votes
1
answer
445
views
About Variable-Size Stack Frames, about the alignment of stack frame,an example from CSAPP
C code:
long vframe(long n, long idx, long *q) {
long i;
long *p[n];
p[0] = &i;
for (i = 1; i < n; i++)
p[i] = q;
return *p[idx];
}
Portions of generated assembly ...
3
votes
2
answers
3k
views
c inline assembly getting "operand size mismatch" when using cmpxchg
I'm trying to use cmpxchg with inline assembly through c. This is my code:
static inline int
cas(volatile void* addr, int expected, int newval) {
int ret;
asm volatile("movl %2 , %%eax\n\t"
...
0
votes
2
answers
1k
views
Assembly Language to C issue with registers
I am trying to write C code that will have an effect equivalent to the following assembly code:
addq %rsi, %rdi
imulq %rdx, %rdi
movq %rdi, %rax
sarq $15, %rax
salq $31, %rax
andq %rdi, %rax
ret
With ...
2
votes
1
answer
2k
views
Push address of stack location instead of the value at the address
I'm working on a small compiler project, and I can't seem to figure out how to push the address of a stack location instead of the value at that stack location. My goal is to push a stack location ...
-1
votes
1
answer
359
views
Why does GCC generate a "mov 0x8,%edx" instruction that causes a crash?
I have a function which is declared like this:
void
tesysLog(W16 uid, char *file, int line, int level,
W16 state, W16 event, int error, char *format, ...)
There is another func which will ...
1
vote
1
answer
618
views
builtin pcmpistri not working in gcc
I'm trying to write a strcmp version that takes advantage of SSE4.2 new instructions leveraging GCC intrinsics.
This is the code I have so far:
#include <stdio.h>
#include <smmintrin.h>
...
5
votes
1
answer
2k
views
How do I pass inputs into extended asm?
Consider this code, from my earlier question.
int main(){
asm("movq $100000000, %rcx;"
"startofloop: ; "
"sub $0x1, %rcx; "
"jne startofloop; ");
}
I would ...
0
votes
2
answers
1k
views
Accessing address of a string in inline assembly in gcc
I have written the below assembly code to convert a string from lower case to uppercase, It's not completely working because i'm not able to access the address of a string that i'm converting. this ...
3
votes
1
answer
5k
views
GCC inline - push address, not its value to stack
I'm experimenting with GCC's inline assembler (I use MinGW, my OS is Win7).
Right now I'm only getting some basic C stdlib functions to work. I'm generally familiar with the Intel syntax, but new to ...
1
vote
1
answer
3k
views
assembly, two functions in 1 file, getting Error: junk `(%ebp)' after expression
The assembly functions with commented c version:
/*
int f (int x)
{
return x+2;
}
void map2 (int* one, int * another, int n)
{
int i;
for (i=0; i<n; i++)
*(another+i) = f(*(...
0
votes
0
answers
1k
views
rounding with frndint in Assembly
I am trying to pass a float n into ebx (or if I can, just use n) and round it, then pass it back into n and return the value to main, this block of code runs 4 times, each time it is being passed a ...
0
votes
1
answer
936
views
Program received signal SIGSEGV, Segmentation fault using SHRD in ASM
I'm trying to shift eax right by 2, currently it is 0x037f and I want to get it to 0x0003.
I'm using Cygwin, it compiles fine but when I open it with gdb, once I get to line 7 I get the title error.
...