Skip to main content

All Questions

Filter by
Sorted by
Tagged with
1 vote
1 answer
134 views

What is the reasoning behind this boilerplate start-up code?

Here's a snippet from disassembled output of a simple program with gcc on Linux: 400478: ff 15 6a 0b 20 00 callq *0x200b6a(%rip) # 600fe8 <__libc_start_main@GLIBC_2.2.5> ...
user129393192's user avatar
2 votes
0 answers
77 views

Load function written in amd64 assembly into memory and call it

I am trying to write a small jit compiler. For that, I need to somehow load new code into memory and then execute it. Given the output of the compiler for a function that simply adds the 2nd and 3rd ...
lorenzw's user avatar
  • 396
0 votes
0 answers
115 views

Why does accessing an initialised array cause a segfault?

I'm making a compiler for brainfuck and I've made the ELF header and 2 program headers, the relevant header is this: Program_Header dataHeader = { 1, ...
Been's user avatar
  • 9
0 votes
1 answer
326 views

ld warning from custom compiler: ld: warning: cannot find entry symbol _start; defaulting to 0000000000401000

When trying to actually use my custom compiler for a made up language I get the following warning from ld: "ld: warning: cannot find entry symbol _start; defaulting to 0000000000401000" it ...
user avatar
1 vote
0 answers
119 views

Why does the compiler need the intermediate representations for link time optimization?

My professor mentioned that gcc can be run with -flto. I am wondering why the intermediary (GIMPLE in GCC case) are needed. Why is the assembly not sufficient? He mentioned that this allows the ...
cspurposesonly's user avatar
0 votes
0 answers
26 views

How does (SIC) assembler print hash tables? [duplicate]

I am trying to make an assembler in C for the SIC architecture. And I saw that symbol table and object code table are usually made with hash tables. What I wonder is, how assemblers print these tables....
Dalim Oh's user avatar
1 vote
0 answers
724 views

Why does riscv32-gcc use LI and ADDI to put a 32-bit constant in a register, not LI with the full constant?

.... //--------------------------------- // Init State //--------------------------------- int32_t state[16]; state[0] = 0x61707865; ... || c -> asm(riscv32-gcc -S inputcode.c) || ...
김민재's user avatar
0 votes
0 answers
217 views

How does the C compiler know memory location even though the program gets loaded in memory after the compilation phase? [duplicate]

Generally, there are 2 phases of the program - compiling and running. Compile-time - compiler generates assembly of source program something like this - MOV R1 R2 LOAD R2 1000 Run Time - program gets ...
Vasu_BHATT's user avatar
1 vote
0 answers
842 views

Why does this assembly cause a segmentation fault? [duplicate]

I'm working on a hobby compiler project, and am getting frustrated because my generated assembly makes perfect sense to me but causes a segmentation fault on running. For the input printf("%d&...
Dovahkiin's user avatar
  • 1,076
1 vote
0 answers
192 views

Why "a==b" in C is compiled to "xor; j; sltu" in assembly? - Why instruction after unconditional jump? [duplicate]

I want to see how == is compiled in C. Thus I try a simple code: #include <stdio.h> int f(int a,int b) { return a==b; // NOTE THIS } int main(void) { int a,b,c; scanf("%d"...
ch271828n's user avatar
  • 17.7k
2 votes
2 answers
141 views

How does the compiler differentiate indentically-named items

In the following example: int main(void) { int a=7; { int a=8; } } The generated assembly would be something like this (from Compiler Explorer) without optimizations: main: ...
samuelbrody1249's user avatar
3 votes
1 answer
187 views

How do nested scopes affect stack depth?

I tried compiling the following c-code using MSVC into assembly both with (CL TestFile.c /Fa /Ot) and without optimizations (CL TestFile.c /Fa) and the result is they produce the same stack-depth. Why ...
Jasper Nielsen's user avatar
1 vote
2 answers
440 views

How does format specifiers works in compiler?

Take the C language as an example for this question. In the C language we can see many format specifiers, such as %i %d %c %s %f etc. In the compilation process, the C code is converted into an ...
Lasan Nishshanka's user avatar
1 vote
1 answer
1k views

Why does C compile to assembly instead of binary? [duplicate]

What is the advantage of C compiling to assembly instead of binary as all I can think of are disadvantages such as making compilation slower?
cprogrammer100's user avatar
2 votes
0 answers
240 views

reference to external function in disassembly code [duplicate]

I am trying to see everything in big picture regarding compilation and linking. I have below simple function implemented in add_caller.c : extern int add(int a, int b); int main(int argc, char **...
Abhishek Sagar's user avatar

15 30 50 per page
1
2 3 4 5