Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Paul Lefebvre
Paul Lefebvre

Posted on • Edited on

     

Compilers 108 – Code Generation

Code generation is one of the last steps of the compiler. This is where the compiler emits actual machine code for the IR that was previously created.

The Compiler series:

This is the simple code we started with in theCompilers 101 blog post:

sum = 3.14 + 2 * 4 // calculation
Enter fullscreen modeExit fullscreen mode

It results in a constant value of 11. After the IR is generated and optimized, it can boil down to just a single line of machine code, which will vary by processor and architecture. Machine code is just binary and not readable, so below is what the Assembly code might look like.

This is the Assembly code for 32-bit ARM:

movs r0, #11
Enter fullscreen modeExit fullscreen mode

This is the Assembly code for ARM64:

movz w0, #11
Enter fullscreen modeExit fullscreen mode

x86 and x86-64 use this Assembly code:

movl $11, %eax
Enter fullscreen modeExit fullscreen mode

Obviously this is the tricky part of making a multi-platform compiler since Assembly code is different between processors and architectures.

Once you have machine code that the computer can run, the last step is to link all the pieces together so that you have an app that the OS can run.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Play: I am a father, husband and retro computing enthusiast.Work: Xojo Software Engineer.
  • Location
    USA
  • Work
    Software Engineer at Xojo
  • Joined

More fromPaul Lefebvre

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp