diff --git a/sources/zweic/Generator.scala b/sources/zweic/Generator.scala index 9643026..3787729 100644 --- a/sources/zweic/Generator.scala +++ b/sources/zweic/Generator.scala @@ -351,6 +351,7 @@ } } + //load method address code.emit(LDW, targetReg, targetReg, method.sym.offset); // check receiver.method() != null @@ -360,9 +361,13 @@ code.emit(SYSCALL, targetReg, ZERO, SYS_EXIT); code.anchorLabel(okLabel2); + //set return address + code.emit(SUBI, LNK, SP, 4, "store return address"); + + //call function code.emit(RET, targetReg); - + //store return value code.emit(ADD, targetReg, ZERO, RES); code.decFrameSize(args.length*4+4); // fs = oldframesize - params - this diff --git a/theirasm/Factorial.asm b/theirasm/Factorial.asm new file mode 100644 index 0000000..ab076aa --- /dev/null +++ b/theirasm/Factorial.asm @@ -0,0 +1,190 @@ +/* 0000 */ beq 0 168 +/* 0004 */ add 0 0 0 /* Factorial::factorial1 */ +/* 0008 */ add 0 0 0 /* Factorial::factorial2_aux */ +/* 0012 */ add 0 0 0 /* Factorial::factorial2 */ +/* 0016 */ add 0 0 0 /* Factorial::factorial3 */ +/* 0020 */ add 0 0 0 /* Example::main */ +/* 0024 */ psh 31 30 4 /* def Factorial::factorial1 */ +/* 0028 */ ldw 1 30 4 /* x */ +/* 0032 */ oriu 2 0 0 +/* 0036 */ cmp 1 1 2 +/* 0040 */ bne 1 3 +/* 0044 */ oriu 1 0 1 +/* 0048 */ beq 0 19 +/* 0052 */ ldw 1 30 4 /* x */ +/* 0056 */ psh 1 30 4 +/* 0060 */ ldw 2 30 12 /* this */ +/* 0064 */ bne 2 3 +/* 0068 */ oriu 2 0 1 +/* 0072 */ syscall 2 0 19 /* SYS_EXIT */ +/* 0076 */ psh 2 30 4 +/* 0080 */ ldw 2 2 0 +/* 0084 */ ldw 1 2 0 +/* 0088 */ ldw 2 30 12 /* x */ +/* 0092 */ oriu 3 0 1 +/* 0096 */ sub 2 2 3 +/* 0100 */ psh 2 30 4 +/* 0104 */ oriu 31 0 112 +/* 0108 */ ret 1 +/* 0112 */ addi 2 1 0 +/* 0116 */ pop 1 30 4 +/* 0120 */ mul 1 1 2 +/* 0124 */ pop 31 30 12 +/* 0128 */ ret 31 +/* 0132 */ psh 31 30 4 /* def Factorial::factorial2_aux */ +/* 0136 */ ldw 1 30 8 /* x */ +/* 0140 */ oriu 2 0 0 +/* 0144 */ cmp 1 1 2 +/* 0148 */ bne 1 3 +/* 0152 */ ldw 1 30 4 /* acc */ +/* 0156 */ beq 0 18 +/* 0160 */ ldw 2 30 12 /* this */ +/* 0164 */ bne 2 3 +/* 0168 */ oriu 2 0 1 +/* 0172 */ syscall 2 0 19 /* SYS_EXIT */ +/* 0176 */ psh 2 30 4 +/* 0180 */ ldw 2 2 0 +/* 0184 */ ldw 1 2 4 +/* 0188 */ ldw 2 30 12 /* x */ +/* 0192 */ oriu 3 0 1 +/* 0196 */ sub 2 2 3 +/* 0200 */ psh 2 30 4 +/* 0204 */ ldw 2 30 12 /* acc */ +/* 0208 */ ldw 3 30 16 /* x */ +/* 0212 */ mul 2 2 3 +/* 0216 */ psh 2 30 4 +/* 0220 */ oriu 31 0 228 +/* 0224 */ ret 1 +/* 0228 */ pop 31 30 16 +/* 0232 */ ret 31 +/* 0236 */ psh 31 30 4 /* def Factorial::factorial2 */ +/* 0240 */ ldw 2 30 8 /* this */ +/* 0244 */ bne 2 3 +/* 0248 */ oriu 2 0 1 +/* 0252 */ syscall 2 0 19 /* SYS_EXIT */ +/* 0256 */ psh 2 30 4 +/* 0260 */ ldw 2 2 0 +/* 0264 */ ldw 1 2 4 +/* 0268 */ ldw 2 30 8 /* x */ +/* 0272 */ psh 2 30 4 +/* 0276 */ oriu 2 0 1 +/* 0280 */ psh 2 30 4 +/* 0284 */ oriu 31 0 292 +/* 0288 */ ret 1 +/* 0292 */ pop 31 30 12 +/* 0296 */ ret 31 +/* 0300 */ psh 31 30 4 /* def Factorial::factorial3 */ +/* 0304 */ oriu 1 0 1 +/* 0308 */ psh 1 30 4 /* var p */ +/* 0312 */ ldw 1 30 8 /* x */ +/* 0316 */ oriu 2 0 0 +/* 0320 */ cmp 1 1 2 +/* 0324 */ ble 1 10 +/* 0328 */ ldw 1 30 0 /* p */ +/* 0332 */ ldw 2 30 8 /* x */ +/* 0336 */ mul 1 1 2 +/* 0340 */ stw 1 30 0 +/* 0344 */ ldw 1 30 8 /* x */ +/* 0348 */ oriu 2 0 1 +/* 0352 */ sub 1 1 2 +/* 0356 */ stw 1 30 8 +/* 0360 */ beq 0 -12 +/* 0364 */ ldw 1 30 0 /* p */ +/* 0368 */ addi 30 30 4 +/* 0372 */ pop 31 30 12 +/* 0376 */ ret 31 +/* 0380 */ psh 31 30 4 /* def Example::main */ +/* 0384 */ oriu 1 0 4 +/* 0388 */ syscall 1 1 12 /* new Factorial */ +/* 0392 */ oriu 2 0 4 +/* 0396 */ stw 2 1 0 +/* 0400 */ psh 1 30 4 /* var fac */ +/* 0404 */ oriu 1 0 5 +/* 0408 */ psh 1 30 4 /* var x */ +/* 0412 */ ldw 2 30 4 /* fac */ +/* 0416 */ bne 2 3 +/* 0420 */ oriu 2 0 1 +/* 0424 */ syscall 2 0 19 /* SYS_EXIT */ +/* 0428 */ psh 2 30 4 +/* 0432 */ ldw 2 2 0 +/* 0436 */ ldw 1 2 0 +/* 0440 */ ldw 2 30 4 /* x */ +/* 0444 */ psh 2 30 4 +/* 0448 */ oriu 31 0 456 +/* 0452 */ ret 1 +/* 0456 */ syscall 1 0 7 /* printInt */ +/* 0460 */ syscall 0 0 15 /* flush */ +/* 0464 */ oriu 1 0 10 +/* 0468 */ syscall 1 0 6 /* printChar */ +/* 0472 */ syscall 0 0 15 /* flush */ +/* 0476 */ ldw 2 30 4 /* fac */ +/* 0480 */ bne 2 3 +/* 0484 */ oriu 2 0 1 +/* 0488 */ syscall 2 0 19 /* SYS_EXIT */ +/* 0492 */ psh 2 30 4 +/* 0496 */ ldw 2 2 0 +/* 0500 */ ldw 1 2 8 +/* 0504 */ ldw 2 30 4 /* x */ +/* 0508 */ psh 2 30 4 +/* 0512 */ oriu 31 0 520 +/* 0516 */ ret 1 +/* 0520 */ syscall 1 0 7 /* printInt */ +/* 0524 */ syscall 0 0 15 /* flush */ +/* 0528 */ oriu 1 0 10 +/* 0532 */ syscall 1 0 6 /* printChar */ +/* 0536 */ syscall 0 0 15 /* flush */ +/* 0540 */ ldw 2 30 4 /* fac */ +/* 0544 */ bne 2 3 +/* 0548 */ oriu 2 0 1 +/* 0552 */ syscall 2 0 19 /* SYS_EXIT */ +/* 0556 */ psh 2 30 4 +/* 0560 */ ldw 2 2 0 +/* 0564 */ ldw 1 2 12 +/* 0568 */ ldw 2 30 4 /* x */ +/* 0572 */ psh 2 30 4 +/* 0576 */ oriu 31 0 584 +/* 0580 */ ret 1 +/* 0584 */ syscall 1 0 7 /* printInt */ +/* 0588 */ syscall 0 0 15 /* flush */ +/* 0592 */ oriu 1 0 10 +/* 0596 */ syscall 1 0 6 /* printChar */ +/* 0600 */ syscall 0 0 15 /* flush */ +/* 0604 */ oriu 1 0 0 /* null */ +/* 0608 */ addi 30 30 8 +/* 0612 */ pop 31 30 8 +/* 0616 */ ret 31 +/* 0620 */ oriu 2 0 4 +/* 0624 */ syscall 2 2 12 /* new Example */ +/* 0628 */ oriu 3 0 20 +/* 0632 */ stw 3 2 0 +/* 0636 */ bne 2 3 +/* 0640 */ oriu 2 0 1 +/* 0644 */ syscall 2 0 19 /* SYS_EXIT */ +/* 0648 */ psh 2 30 4 +/* 0652 */ ldw 2 2 0 +/* 0656 */ ldw 1 2 0 +/* 0660 */ oriu 31 0 668 +/* 0664 */ ret 1 +/* 0668 */ ret 0 +/* 0672 */ syscall 30 0 13 /* SYS_GET_TOTAL_MEM_SIZE */ +/* 0676 */ oriu 1 0 672 +/* 0680 */ sub 2 30 1 +/* 0684 */ diviu 2 2 12 +/* 0688 */ lshi 2 2 1 +/* 0692 */ oriu 3 0 -4096 +/* 0696 */ lshi 3 3 16 +/* 0700 */ add 2 2 3 +/* 0704 */ syscall 1 2 11 /* SYS_GC_INIT */ +/* 0708 */ oriu 1 0 4 +/* 0712 */ oriu 31 0 24 +/* 0716 */ stw 31 1 0 /* Factorial::factorial1 */ +/* 0720 */ oriu 31 0 132 +/* 0724 */ stw 31 1 4 /* Factorial::factorial2_aux */ +/* 0728 */ oriu 31 0 236 +/* 0732 */ stw 31 1 8 /* Factorial::factorial2 */ +/* 0736 */ oriu 31 0 300 +/* 0740 */ stw 31 1 12 /* Factorial::factorial3 */ +/* 0744 */ oriu 1 0 20 +/* 0748 */ oriu 31 0 380 +/* 0752 */ stw 31 1 0 /* Example::main */ +/* 0756 */ beq 0 -34