Source Code
// MyCC code example
// Gabriel Capella
class Test {
int f;
int h;
public void main() {
int x;
int y;
x = 48;
y = 49;
print(y);
print(x);
}
}
Results
Assembly
.globl main
main:
pushq %rbp # Save old EBP
movq %rsp, %rbp # Save old ESP
movq $16, %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 <- 48
movq $48, %rax
##MoMo %1 <- %0
##MovL %2 <- 49
movq $49, %rbx
##MoMo %3 <- %2
##MoMo %4 <- %3
##Prin %4
pushq %rax ## prepare print call
pushq %rbx ## prepare print call
pushq %rbx ## print
movq $1,%rax ## sys_write
movq $1,%rdi ## fd stdout
movq %rsp,%rsi ## string pointer
movq $1,%rdx ## size
syscall ## syscall
popq %rsi ##
popq %rbx
popq %rax
##MoMo %5 <- %1
##Prin %5
pushq %rax ## prepare print call
pushq %rbx ## prepare print call
pushq %rax ## print
movq $1,%rax ## sys_write
movq $1,%rdi ## fd stdout
movq %rsp,%rsi ## string pointer
movq $1,%rdx ## size
syscall ## syscall
popq %rsi ##
popq %rbx
popq %rax
movq %rbp, %rsp # Restore ESP
popq %rbp # Restore EBP
retq
fail_exit:
movl $1, %eax
popq %rbp
retq
Expected
10
Got
10