My first compiler

2op_times

Source Code

// MyCC code example
// Gabriel Capella
class Factorial {
    public void main() {
        int x;
        x = 24;
        x = x * 2;
        x = x + 1;
        print(x);
    }
}

preview


preview
preview
preview
preview
preview
preview
preview

Results

Assembly

.globl main

main:
   pushq  %rbp                # Save old EBP
   movq    %rsp, %rbp         # Save old ESP

   movq    $0, %rax
   movq    %rax, %rdi
   callq   malloc@PLT
   testq   %rax, %rax
   jz      fail_exit
   pushq   %rax

   callq   __LABEL0
   popq   %rax

   movq %rbp, %rsp            # Restore ESP
   popq %rbp                  # Restore EBP
   retq

__LABEL0:
   pushq  %rbp                # Save old EBP
   movq    %rsp, %rbp         # Save old ESP
   addq    $-8, %rsp

   ##MovL %0 <- 24
   movq   $24, %rax
   ##MoMo %1 <- %0
   ##MoMo %2 <- %1
   movq   %rax, %rbx
   ##MovL %3 <- 2
   movq   $2, %rax
   ##MoOp %4 <- %2,%3
   imul   %rbx, %rax
   ##MoMo %1 <- %4
   ##MoMo %5 <- %1
   movq   %rax, %rbx
   ##MovL %6 <- 1
   movq   $1, %rax
   ##MoOp %7 <- %5,%6
   addq   %rbx, %rax
   ##MoMo %1 <- %7
   ##MoMo %8 <- %1
   ##Prin %8
   pushq  %rax                  ## prepare print call
   pushq  %rbx                  ## prepare print call
   movq   %rax, %rdi            ## print
   callq   putchar@PLT
   popq   %rbx
   popq   %rax

   movq    %rbp, %rsp            # Restore ESP
   popq    %rbp                  # Restore EBP
   retq

fail_exit:
   movl   $1, %eax
   popq   %rbp
   retq
Expected
1
Got
1