The simplest working compiler!

比较弱智,呵呵。
源程序如下:

class Program {
static int i;
static int j;
static boolean b;

static void Main() {
i = 3 * 5;
j = i + 10;
func();
print(j);
}
static void func() {
print(i);
}
}

翻译成汇编码:

.section    .rodata
format:
.string    "%dn"
.text
.globl main
.type    main, @function
main:
pushl    %ebp
movl    %esp, %ebp
subl    $8, %esp
movl    $3, %eax
movl    %eax, %ebx
movl    $5, %eax
imull    %ebx, %eax
movl    %eax, i
movl    i, %eax
movl    %eax, %ebx
movl    $10, %eax
addl    %ebx, %eax
movl    %eax, j
call    func
movl    j, %eax
movl    %eax, 4(%esp)
movl    $format, (%esp)
call    printf
leave
ret
.globl func
.type    func, @function
func:
pushl    %ebp
movl    %esp, %ebp
subl    $8, %esp
movl    i, %eax
movl    %eax, 4(%esp)
movl    $format, (%esp)
call    printf
leave
ret
.local    i
.comm    i, 4, 4
.local    j
.comm    j, 4, 4
.local    b
.comm    b, 4, 4

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.