Assembly language programming vs Other programming languages

Click For Summary
SUMMARY

Assembly language programming offers significant performance advantages over higher-level languages such as C, C++, and Python due to its direct translation into machine code, which minimizes unnecessary compiler-generated overhead. While C can be efficient, its complexity in translation can lead to larger executable sizes, as evidenced by a "hello world" program in C being approximately 1,000 bytes compared to just 15 bytes in assembly. Inline assembly features in C compilers allow developers to optimize critical code sections, but assembly remains processor-specific, limiting its practicality for general application development. Ultimately, while assembly provides speed and efficiency, it is often considered overkill for most programming tasks today.

PREREQUISITES
  • Understanding of assembly language syntax and structure
  • Familiarity with C and C++ programming languages
  • Knowledge of compiler behavior and optimization techniques
  • Awareness of processor architecture and instruction sets
NEXT STEPS
  • Explore inline assembly features in GCC or MSVC compilers
  • Study compiler optimization techniques for C and C++
  • Learn about processor-specific assembly languages (e.g., x86, ARM)
  • Investigate performance profiling tools for C/C++ applications
USEFUL FOR

Software developers, systems programmers, and performance engineers looking to optimize application performance and gain a deeper understanding of low-level programming concepts.

  • #121
glappkaeft said:
Edit: Note that is is considered bad practice to initialize an int with a double value.
hmm yeh, I had started it double, but then it complained with the usage of << . I changed it to integer but I forgot to remove the .0 ...

Hm, so that means the assembler code would be something like:
movl $0x6e , -0x4 (%rbp)
(sum is registered in 0x4 and moves 110 in it)
without a for loop?
Does that happen because the compiler runs the code and gets the result before producing the output?
 
Technology news on Phys.org
  • #122
ChrisVer said:
without a for loop?
Does that happen because the compiler runs the code and gets the result before producing the output?
It doesn't really run the code, but it optimizes it.

int chrisver()
{
int sum = 0;
for(int i=1; i<=10; i++)
{
sum+= 2*i;​
}​
return sum;​
0FB94090 mov eax,6Eh
}​
0FB94095 ret
 
  • #123
ChrisVer said:
Does that happen because the compiler runs the code and gets the result before producing the output?

Since it doesn't really run the code it is usually said that the compiler evaluates the code at compile time. If you are interested in these things the compiler optimization section on wikipedia is a pretty good place to start. For instance constant folding is here: https://en.wikipedia.org/wiki/Constant_folding

Added: If you want to see what the compiler does with your code in a real world scenario you need to make sure the number of times the for-loop is repeated is not known at compile time, e.g. depends on user keyboard input, data from a file or similar.
 
Last edited:

Similar threads

Replies
6
Views
3K
  • · Replies 397 ·
14
Replies
397
Views
20K
Replies
6
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 29 ·
Replies
29
Views
3K
  • · Replies 4 ·
Replies
4
Views
15K
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
59
Views
8K