void return_input (void) { char array[30]; gets (array); printf(“%sn”, array); } After compiling it in gcc, this function is converted to the following Assembly code: push %ebp mov %esp,%ebp sub $0x28,%esp mov %gs:0x14,%eax mov %eax,-0x4(%ebp) xor %eax,%eax lea -0x22(%ebp),%eax mov %eax,(%esp) call 0x8048374 lea -0x22(%ebp),%eax mov %eax,(%esp) call 0x80483a4 mov -0x4(%ebp),%eax xor %gs:0x14,%eax je 0x80484ac call 0x8048394 leave ret I
Tag: x86
Getting cpu cycles using RDTSC – why does the value of RDTSC always increase?
I want to get the CPU cycles at a specific point. I use this function at that point: (editor’s note: “=A” is wrong for x86-64; it picks either RDX or RAX. Only in 32-bit mode will it pick the EDX:EAX output you want. See How to get the CPU cycle count in x86_64 from C++?.) The problem is that it
Is malloc deterministic?
Is malloc deterministic? Say If I have a forked process, that is, a replica of another process, and at some point both of them call the malloc function. Would the address allocated be the same in both processes? Assuming that other parts of execution are also deterministic. Note: Here, I’m only talking about virtual memory, not physical one. Answer There
Why makecontext does not work with pthreads
From makecontext() manual… Due to limitations in the current pthread implementation, makecontext should not be used in programs which link against the pthread(3) library (whether threads are used or not). Now my question is, why it doesn’t work and what are the alternative methods. Actually I’m interested in switching stacks in a user-level thread at some points, but I’m seeing
undefined reference to sync_fetch_and_add_4
Whenever I try to use __sync_fetch_and_add with -m32 on a 64 bit machine, I get the following error, while it compiles fine with normal 64 bit. I am using gcc compiler 4.1.2. What can be the problem here and what is the solution? Answer Using -march=i486 flag did the trick for me.
Self modifying code always segmentation faults on Linux
i found an article about self modifying code and tried to do some examples, but i get always segmentation faults. As fas as i can understand, there is a violation in memory permissions. The code segment is (r)ead/e(x)ecute and so the attempt of writting results to this fault. Is there a way to test the program either by changing the
Setting GDB hardware watchpoint/how to set software watchpoint
An earlier question explained that on x86 the size of objects being watched is limited by debug registers. As expected, I can “watch” a double variable. But I can’t watch a double datamember, for example, produces But when you try to continue execution, it says Could not insert hardware breakpoints: You may have requested too many hardware breakpoints/watchpoints. even though
Compile/run assembler in Linux?
I’m fairly new to Linux (Ubuntu 10.04) and a total novice to assembler. I was following some tutorials and I couldn’t find anything specific to Linux. So, my question is, what is a good package to compile/run assembler and what are the command line commands to compile/run for that package? Answer The GNU assembler (gas) and NASM are both good
Trying to understand gcc’s complicated stack-alignment at the top of main that copies the return address
hi I have disassembled some programs (linux) I wrote to understand better how it works, and I noticed that the main function always begins with: so my question is: why all this work is done ?? I only understand the use of: the rest seems useless to me… Answer I’ve had a go at it: