.constant OBJREF 0x40 endline 0x3b .end-constant .main .var x y a .end-var LDC_W OBJREF INVOKEVIRTUAL input ISTORE x LDC_W OBJREF INVOKEVIRTUAL input ISTORE y LDC_W OBJREF ILOAD x LDC_W OBJREF ILOAD y INVOKEVIRTUAL fun1 IADD INVOKEVIRTUAL fun1 ISTORE a LDC_W OBJREF ILOAD a INVOKEVIRTUAL fun2 LDC_W OBJREF ILOAD x INVOKEVIRTUAL fun1 IADD LDC_W OBJREF SWAP INVOKEVIRTUAL print HALT .end-main .method fun1(y) .var cont i .end-var BIPUSH 0 ISTORE cont ILOAD y DUP IADD ISTORE i for: ILOAD i BIPUSH 10 ISUB DUP IFLT end_for IFEQ end_for LDC_W OBJREF ILOAD i BIPUSH 2 INVOKEVIRTUAL mod IFEQ then ILOAD cont ILOAD i ISUB ISTORE cont GOTO end_if then: ILOAD i ILOAD CONT IADD IStORE CONT end_if: IINC i 0x-1 GOTO for end_for: IINC cont 0x1 ILOAD cont IRETURN .end-method .method fun2(x) .var i .end-var BIPUSH 0 ISTORE i while1: ILOAD x ILOAD i ISUB DUP IFLT end_while1 IFEQ end_while1 while2: ILOAD x BIPUSH 10 ISUB DUP IFLT end_while2 IFEQ end_while2 IINC x 0x-1 GOTO while2 end_while2: IINC i 0x1 GOTO while1 end_while1: ILOAD i IRETURN .end-method .method mul(i, j) ILOAD j IFEQ zero IINC j -1 ILOAD i IFEQ zero LDC_W OBJREF ILOAD i ILOAD j INVOKEVIRTUAL mul ILOAD i IADD GOTO fine zero: BIPUSH 0x0 fine: IRETURN .end-method .method mod (a, b) ILOAD a IFEQ stop ILOAD a ILOAD b ISUB IFLT stop LDC_W OBJREF ILOAD a ILOAD b ISUB ILOAD b INVOKEVIRTUAL mod GOTO fine stop: ILOAD a fine: IRETURN .end-method .method div (a, b) ILOAD a ILOAD b ISUB IFLT stop LDC_W OBJREF ILOAD a ILOAD b ISUB ILOAD b INVOKEVIRTUAL div BIPUSH 1 IADD GOTO fine stop: BIPUSH 0x0 fine: IRETURN .end-method .method input() .var num .end-var BIPUSH 0x0 ISTORE num loop: IN DUP LDC_W ENDLINE ISUB IFEQ stop BIPUSH 0x30 ISUB LDC_W OBJREF ILOAD num BIPUSH 10 INVOKEVIRTUAL mul IADD ISTORE num GOTO loop stop: ILOAD num IRETURN .end-method .method print(x) ILOAD x IFEQ printz LDC_W OBJREF ILOAD x INVOKEVIRTUAL print_digits GOTO end printz: BIPUSH 0x30 OUT end: BIPUSH 0 IRETURN .end-method .method print_digits(x) .var char .end-var ILOAD x IFEQ end LDC_W OBJREF ILOAD x BIPUSH 10 INVOKEVIRTUAL mod BIPUSH 0x30 IADD ISTORE char LDC_W OBJREF ILOAD x BIPUSH 10 INVOKEVIRTUAL div LDC_W OBJREF SWAP INVOKEVIRTUAL print_digits ILOAD char OUT end: BIPUSH 0 IRETURN .end-method