Ciao a tutti! devo realizzare un programma IJVM che prenda in input un numero decimale da tastiera e ne calcoli il fattoriale...Ho scritto questo codice ma non funziona perchè c'è qualcosa di sbagliato nel prendere in input da tastiera i valori. Infatti dandogli in input un valore tramite la BIPUSH funge! Qualcuno sa aiutarmi a risolverlo? Grazie mille in anticipo!


.constant
OBJREF 0X40
.end-constant

.main
.var
fattoriale//variabile che conterrà il risultato, ovvero il fattoriale del numero inserito da tastiera
numero
.end-var
BIPUSH 0
ISTORE fattoriale//Inizializzazione di fattoriale a zero
BIPUSH 0
ISTORE numero
getch: IN // Legge un carattere
DUP // Duplica il top dello stack
IFEQ reread // Se è = 0 (nessun tasto)
GOTO done // Tasto premuto, procedi

reread:
POP // Cancella il duplicato
GOTO getch // Torna in attesa

done: ISTORE numero
LDC_W OBJREF
ILOAD numero
INVOKEVIRTUAL FATT
ISTORE fattoriale//memorizzazione del risultato nella variabile "fattoriale"
ILOAD fattoriale
HALT
.end-main

.method FATT(n)
ILOAD n
IFEQ zero//se n è uguale zero salta alla label zero (caso base)
LDC_W OBJREF
DUP
ILOAD n
BIPUSH 1
ISUB
INVOKEVIRTUAL FATT
ILOAD n
INVOKEVIRTUAL MOLTIPLICA
GOTO fine
zero: BIPUSH 1
fine: IRETURN
.end-method


.method moltiplica (x,y)
.var
prodotto
.end-var
BIPUSH 0
ISTORE prodotto
ciclo: ILOAD y
IFEQ fine
ILOAD prodotto
ILOAD x
IADD
ISTORE prodotto
IINC y -1
GOTO ciclo
fine: ILOAD prodotto
IRETURN
.end-method