# objects.ic # global declarations .globl __ic_main # data section .data .align 4 _A_DV: .long _A_m _B_DV: .long _B_m _C_DV: .long _C_main .long 10 str1: .ascii "A fields: " .long 10 str2: .ascii "B fields: " .long 2 str3: .ascii ", " .long 0 str4: .ascii "" .long 23 strNPC: .ascii "Null pointer violation." .long 23 strABC: .ascii "Array bounds violation." # text (code) section .text #---------------------------------------------------- .align 4 _A_m: push %ebp # prologue mov %esp,%ebp mov 8(%ebp), %eax # itos(a) push 4(%eax) call __LIB_itos add $4, %esp push %eax # stringCat push $str1 call __LIB_stringCat add $8, %esp push %eax # println call __LIB_println add $4, %esp _epilogue_A_m: mov %ebp,%esp # epilogue pop %ebp ret .align 4 _B_m: push %ebp # prologue mov %esp,%ebp push %ebx push $str2 # print("B fields: ") call __LIB_print add $4, %esp mov 8(%ebp), %eax # printi(a) push 4(%eax) call __LIB_printi add $4, %esp push $str3 # print(", ") call __LIB_print add $4, %esp mov 8(%ebp), %eax # printb(b) push 8(%eax) call __LIB_printb add $4, %esp push $str4 # println("") call __LIB_println add $4, %esp _epilogue_B_m: pop %ebx # epilogue mov %ebp,%esp pop %ebp ret #---------------------------------------------------- .align 4 _C_main: push %ebp # prologue mov %esp, %ebp sub $8, %esp push %ebx push $8 # oa = new A call __LIB_allocateObject add $4, %esp movl $_A_DV, (%eax) mov %eax, -4(%ebp) push $12 # ob = new B call __LIB_allocateObject add $4, %esp movl $_B_DV, (%eax) mov %eax, -8(%ebp) mov 12(%ebp), %eax # eax = args cmp $0, %eax # null pointer check je labelNPC mov -4(%eax), %eax # if (args.length != 0) cmp $0, %eax je L1 mov -8(%ebp), %eax # oa = ob mov %eax, -4(%ebp) L1: mov -4(%ebp), %eax # oa.a = 412 cmp $0, %eax je labelNPC movl $412, 4(%eax) mov -8(%ebp), %eax # ob.a = 413 cmp $0, %eax je labelNPC movl $413, 4(%eax) mov -8(%ebp), %eax # ob.b = true cmp $0, %eax je labelNPC movl $1, 8(%eax) mov -4(%ebp), %eax # oa.m() cmp $0, %eax je labelNPC push %eax mov (%eax), %eax call *(%eax) add $4, %esp mov -8(%ebp), %eax # ob.m() cmp $0, %eax je labelNPC push %eax mov (%eax), %eax call *(%eax) add $4, %esp _epilogue_C_main: pop %ebx # epilogue mov %ebp,%esp pop %ebp ret #---------------------------------------------------- .align 4 __ic_main: push %ebp # prologue mov %esp,%ebp push $4 # o = new C call __LIB_allocateObject add $4, %esp movl $_C_DV, (%eax) push 8(%ebp) # o.main(args) push %eax mov (%eax), %eax call *(%eax) add $8, %esp mov $0, %eax # return 0 _epilogue_ic_main: mov %ebp,%esp # epilogue pop %ebp ret #---------------------------------------------------- .align 4 labelNPC: push $strNPC call __LIB_println push $1 call __LIB_exit .align 4 labelABC: push $strABC call __LIB_println push $1 call __LIB_exit