I have the following code in .s file: Its object file has the following: After linking, it becomes: How does the argument 0x0 to pushq at byte 20 of the object file gets converted to 0x400578 in the final executable? Which section of the object file contains this information? Answer You answered your own question: After linking…. Here is a
Tag: x86
Generate raw binary from C code in Linux
I have been implementing just for fun a simple operating system for x86 architecture from scratch. I implemented the assembly code for the bootloader that loads the kernel from disk and enters in 32-bit mode. The kernel code that is loaded is written in C, so in order to be executed the idea is to generate the raw binary from
Cannot Make Code Segment Execute-Only (Not Readable)
I’m trying to make the Code Segment Execute-Only (Not Readable). But I FAILED after I tried everything the Manual told me to. Here is what I did to make the code segment unreadable. First, I’ve found this in “Intel(R)64 and IA-32 Architectures Software Developer’s Manual(Combined Volumes 1,2A,2B,2C,2D,3A,3B,3C and 3D)”: Set read-enable bit to enable read and Segment Types.(Sorry, I’m still
Responsibility of stack alignment in 32-bit x86 assembly
I am trying to get a clear picture of who (caller or callee) is reponsible of stack alignment. The case for 64-bit assembly is rather clear, that it is by caller. Referring to System V AMD64 ABI, section 3.2.2 The Stack Frame: The end of the input argument area shall be aligned on a 16 (32, if __m256 is passed
What parts of this HelloWorld assembly code are essential if I were to write the program in assembly?
I have this short hello world program: I compiled it into the following assembly code with gcc: My question is: are all parts of this code essential if I were to write this program in assembly (instead of writing it in C and then compiling to assembly)? I understand the assembly instructions but there are certain pieces I don’t understand.
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
About the memory layout of programs in Linux
I have some questions about the memory layout of a program in Linux. I know from various sources (I’m reading “Programming from the Ground Up”) that each section is loaded into it’s own region of memory. The text section loads first at virtual address 0x8048000, the data section is loaded immediately after that, next is the bss section, followed by
basic linux x86 assembly minimum number returns incorrectly
I wrote this basic linux x86 assembly app. I expect it to return 3 when I do echo $? however the status is always 0. What am I doing wrong? Note: %ebx always contains the status code, and it should contain the min value by exit time. Fixed: Answer The issue is that the terminating zero also participates in the
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
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