Need help creating a multiplier using a method in iJVM

1k views Asked by At

I'm trying to create a program in iJVM using a .jas file with a MIC-1 ASSEMBLER to input two numbers by keyboard and multiply them together to get an out put EX: 2*2=4

In the code below I just bipushed random numbers because when i used 'in' to get input it wasn't giving me an input

When I bipush 7 and bipush 2 just in main without a method the output is: EX: Input x: 20 Input y: 2

I get the ascii digit so Im assuming its taking hex 0x20 and 0x02 and multiplying that to get 0x40 and outputting the ascii character

.main
.var
x
y
sum
.end-var
    BIPUSH  7
    ISTORE  x
    BIPUSH  5
    ISTORE  y
    BIPUSH  0x40
    INVOKEVIRTUAL   imul
    out


.end-main

.method imul(x,y)
.var
x
y
temp
sum
.end-var    
    BIPUSH  2
    ISTORE  x
    BIPUSH  20
    ISTORE  y
L1: 
    BIPUSH  0
    ISTORE  sum
    GOTO    L2

L2: ILOAD   y
    IFEQ    exit

    POP
    ILOAD   x
    DUP
    IADD
    ISTORE  temp
    GOTO    L3

L3: ILOAD   y
    BIPUSH  2
    ISUB
    ISTORE  y
    GOTO    L4

L4: ILOAD   temp
    ILOAD   sum
    IADD
    ISTORE  sum
    GOTO    L2

exit:   ILOAD   sum
    IRETURN

.end-method
0

There are 0 answers