When writing some x64 assembly, I stumbled upon something weird. A function call works fine when executed on a main thread, but causes a segmentation fault when executed as a pthread. At first I thought I was invalidating the stack, as it only segfaults on the second call, but this does not match with the fact that it works properly
Tag: assembly
Why doesn’t the ‘syscall’ instruction work under Linux?
I have a very basic assembly program that runs in Linux userland: However, this doesn’t work as it is, but only if I replace the syscalls with int 0x80. Don’t these do the same thing? I know that syscall was designed to be lower-latency, but other than that, I didn’t think there was a difference. Why doesn’t it work? Answer
How to write a swap function in assembly?
I’ve been trying to figure out how to write a x86 GAS swap function for my program. I know its easier to do xchg or just write it C, but I want to be able to write it out anyways. On my 1st midterm we were given this as as swap function: but I receive a segmentation fault when running
Why can’t stdout from calling c library printf in asm be piped to other programs?
I have written a simple NASM program: printtest.asm I am linking and creating an executable with the following commands: When linked and executed, this prints “val = 5” to the console no problem. As far as I’m aware, calling printf by default writes on stdout. So why when I try and pipe this to another program does the other program
How to not emit local symbols in NASM so that GDB disas won’t stop at them?
I’m trying to write some assembly programs using nasm on linux. Everything is good, but I make heavy use of local symbols (.loop, .else, etc.), which is a pain when debugging, because these symbols are emitted to the symbol table, e.g.: will produce a disassembly that looks like: which is a bit annoying just because gdb will think these are
mov edx overwrites cx register
I’m trying to print Hi 10 times. This is my code. gdb reports that mov edx, 3 overwrites the cx register to some crazy value and so the loop keeps going forever. What am i doing wrong? Is it because they are the same register? How does one program in assembly with so few registers? Compiling on centos with nasm
Function arguments in x86-64 asm
So I have to do this project for school that consists of reading a file in brainfuck and interpret it as assembly. The code works if I save the file path as a String inside the .data section, but what I want to have it so it gets the file path as an argument when starting the code in the
Convert from ascii to integer in AT&T Assembly
How can I convert from ascii to integer? The code is writing an ascii value, and I think that if I can add 48 to value. I can write, but I can’t print, a two-stage number “for example 53 or 156”. How can I print? Answer It’s usually best to think about a high level language version first. If the
How do you convert c code into assembly’s hex representation?
Edit: It appears I have a lot more reading to do… Also, for those telling me this is a bad idea, it’s for a buffer overflow exercise. I have a fairly simple C program: I want to turn it into hex assembly code. Think something like: I tried doing: And that gave me a nice long string of hex. But
How to understand the ARM registers dumped by kernel panic?
After Linux kernel oops on ARM platform, registers are dumped to console. But I got confused with analyzing these registers. For example, Questions: What does the 0xc0705970 stands for in SP: 0xc0705970:? Code address or data address? Where to find it? Why sp : c07059f0 is not at the beginning or end of SP register? How is the stack organized