Advertisement
Guest User

Untitled

a guest
Apr 12th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .constant
  2. OBJREF 0x40
  3. .end-constant
  4.  
  5. .main
  6.  
  7. LDC_W OBJREF
  8. INVOKEVIRTUAL read_num
  9. HALT
  10.  
  11. .end-main
  12.  
  13. .method mult_16(a)
  14.  
  15. ILOAD a
  16. DUP
  17. IADD
  18. DUP
  19. IADD
  20. DUP
  21. IADD
  22. DUP
  23. IADD
  24. IRETURN
  25.  
  26. .end-method
  27.  
  28. .method read_num()
  29. .var
  30. cifra
  31. totale
  32. .end-var
  33. while:  IN
  34.     ISTORE cifra
  35.     ILOAD cifra //controlla se valore valido
  36.     IFEQ while
  37.     ILOAD cifra //controlla se compreso tra 0-9
  38.     BIPUSH 0x30
  39.     ISUB
  40.     IFLT check_end
  41.     ILOAD cifra
  42.     BIPUSH 0x3A
  43.     ISUB
  44.     IFLT convert_num
  45.     ILOAD cifra //controlla se compreso tra A-F
  46.     BIPUSH 0x41
  47.     IFLT while
  48.     ILOAD cifra
  49.     BIPUSH 0x47
  50.     ISUB
  51.     IFLT convert_let
  52.     GOTO while
  53. check_end:  ILOAD cifra
  54.         BIPUSH 0x0A
  55.         ISUB
  56.         IFEQ return
  57.         GOTO while
  58. convert_num:    ILOAD cifra
  59.         BIPUSH 0x30
  60.         ISUB
  61.         ISTORE cifra
  62.         GOTO next
  63. convert_let:    ILOAD cifra
  64.         BIPUSH 0x37
  65.         ISUB
  66.         ISTORE cifra
  67.         GOTO next
  68. next:
  69.     LDC_W OBJREF
  70.     ILOAD totale
  71.     INVOKEVIRTUAL mult_16
  72.     ISTORE totale
  73.     ILOAD totale
  74.     ILOAD cifra
  75.     IADD
  76.     ISTORE totale
  77.     GOTO while
  78. return:
  79. ILOAD totale
  80. IRETURN
  81. .end-method
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement