My first compiler

12call_merge

Source Code

// MyCC code example
// Gabriel Capella
class Test {
    public void main() {
        sdas();
    }

    public void sortInternal(int p, int q) {
        print(48);
    }

    public void sdas() {
        sortInternal(0, 20);
    }
}

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

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

   ##MoMo %5 <- %-1
   movq   %rbp, %rbx
   ##MovL %6 <- 16
   movq   $16, %rax
   ##MoOp %7 <- %5,%6
   addq   %rbx, %rax
   ##MToR %8 <- #7
   movq   (%rax), %rcx
   ##MovL %9 <- 0
   movq   $0, %rax
   ##MoMo %10 <- %9
   movq   %rax, %rbx
   ##MovL %11 <- 20
   movq   $20, %rax
   ##MoMo %12 <- %11
   ##PuAl
   pushq  %rax                  ## prepare call
   pushq  %rbx                  ## prepare call
   pushq  %rcx                  ## prepare call
   ##Push %12
   pushq  %rax
   ##Push %10
   pushq  %rbx
   ##Push %8
   pushq  %rcx
   ##Call (#740882966)
   call   __LABEL1
   ##PopD
   add   $8, %rsp
   ##PopD
   add   $8, %rsp
   ##PopD
   add   $8, %rsp
   ##PoAl
   popq   %rcx
   popq   %rbx
   popq   %rax

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

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

   ##MovL %4 <- 48
   movq   $48, %rax
   ##Prin %4
   pushq  %rax                  ## prepare print call
   pushq  %rbx                  ## prepare print call
   pushq  %rcx                  ## prepare print call
   movq   %rax, %rdi            ## print
   callq   putchar@PLT
   popq   %rcx
   popq   %rbx
   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

   ##MoMo %0 <- %-1
   movq   %rbp, %rbx
   ##MovL %1 <- 16
   movq   $16, %rax
   ##MoOp %2 <- %0,%1
   addq   %rbx, %rax
   ##MToR %3 <- #2
   movq   (%rax), %rax
   ##PuAl
   pushq  %rax                  ## prepare call
   pushq  %rbx                  ## prepare call
   pushq  %rcx                  ## prepare call
   ##Push %3
   pushq  %rax
   ##Call (#0)
   call   __LABEL2
   ##PopD
   add   $8, %rsp
   ##PoAl
   popq   %rcx
   popq   %rbx
   popq   %rax

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

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