I am trying to program a small ELF program with a custom ELF header but have a segmentation fault whenever i am writing to memory. Why would that code trigger a segmentation fault ? %assign LOAD_ADDRESS 0x08048000 BITS 32 org LOAD_ADDRESS ; load address ehdr: ; Elf32_Ehdr db 0x7F, “ELF”, 1, 1, 1 ; e_ident times 9 db 0 ;
Tag: nasm
Pass values from C program to Assembly language
I would like to pass values from C program to Assembly using the linked assembly method instead of inline assembly method in C. Below is the Assembly program(GCD) which is am working on. And this is the C program from with I am trying to pass the values to assembly program When I compile using the below method and run
Why does my shellcode segfault when executed from C, but not as a stand-alone executable?
I’m trying to execute a shell with shellcode. I’ve made this code in a 64-bits machine: After using nasm and linking with ld if i execute the file this works fine. The problem is if i get the shellcode from this and tried to execute it with this program: It gives me a segmentation fault error. I can’t see what’s
NASM division using variables instead of actual values
I’m learning some basic arithmetic using NASM on Linux. I need to divide two numbers using variables NUMBER1 and NUMBER2. My code works if I type in actual value instead of variables. For example if I type in ‘6’ instead of NUMBER2 and ‘2’ instead of NUMBER1, the program does division and gives me answer of 3. Running code with
Why do write syscalls print `%` at end on linux x86_64 (nasm)?
The following hello-world program displays a % sign at the end of the printed string. Why is this and how can I remove it? Here is my program: And here is the output when I run the executable: hello, world!% Thanks in advance. Edit: It seems to be caused by zsh (not reproducible in bash). The question is why this
Reading user input as an integer
I wrote an Assembly program (x86_64 Linux NASM) that prints an integer to console, based in the algorithm suggested my the comments in this post, which is basically this: All works just fine under the following script: After compiling it, the number 567 gets printed on the screen (console). But if I try to do the same but allowing the
Assembly NASM x86 – Simple Stack Project
I’m writing a subroutine to simply reprint decimal numbers as strings using the stack, but not getting the values I expected. When I run it through the debugger I see that I can’t get the value from esi into al. I suspect that I’m not allowed to use esi in the manner that I am, but I’m not sure on
How is the $ token treated when used under a label vs in a single line?
The NASM manual includes the following on the $ token in section 3.5: $ evaluates to the assembly position at the beginning of the line containing the expression and earlier in section 3.1 there is a note about source lines: NASM uses backslash () as the line continuation character; if a line ends with backslash, the next line is considered
Converting User Input Hexadecimal to Decimal in Assembly
I am trying to create an assembly program that takes a user input hexadecimal number no greater than 4 digits and outputs the same number in base 10. This is being done using NASM on a Linux install. Using some tutorials I’ve found and my very limited understanding of this language, I have come up with this. It should be
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