Jasmin的屠夫算法

时间:2017-09-14 03:27:19

标签: algorithm jasmin jvm-bytecode

我一直在收到错误,而且我一直试图永远打印出来。我找了关于Jasmin的信息,据我所知,确实没有太多的信息。任何有关我的代码的帮助将不胜感激。在复活节的下一个十年里,我应该使用Butchers算法在命令行上使用Jasmin进行打印。我的大部分问题都出现在本月印刷和我的代码下面......

.class public example/Easterdeb
.super java/lang/Object

;
; standard initializer
.method public <init>()V
   aload_0
   invokenonvirtual java/lang/Object/<init>()V
   return
.end method

.method public static main([Ljava/lang/String;)V
   ; set limits used by this method
   .limit locals 20
   .limit stack 6

   ; setup local variables:

   ;    1 - the PrintStream object held in java.lang.System.out
   getstatic java/lang/System/out Ljava/io/PrintStream;
   astore_1

   ;    2 - the integer 10 - the counter used in the loop
   bipush 10
   sipush 2016
   istore_2       ;count is in 2
   istore 4       ;year is in 4 

   ; now loop 10 times printing out a number

 Loop:

   ; compute 10 - <local variable 2> ...
  iload 4      ;year
   bipush 19
   irem
   istore 5     ; a is in 5
   iload 4
   bipush 100
   idiv
   istore 6     ; b is in 6
   iload 4
   bipush 100
   irem
   istore 7     ; c is in 7
   iload 7
   iload 6      
   bipush 4
   idiv
   istore 8     ; d is in 8
   iload 6      
   bipush 4
   irem
   istore 9     ; e is in 9
   iload 6
   bipush 8
   iadd 
   bipush 25
   idiv
   istore 10    ; f is in 10
   iload 6 
   iload 10
   isub
   bipush 1
   iadd
   bipush 3
   idiv
   istore 11    ; g is in 11
   bipush 19
   iload 5
   imul
   iload 6        
   iadd
   iload 8
   isub          
   iload 11
   isub
   bipush 15
   iadd
   bipush 30
   irem
   istore 12     ; h is in 12
   iload 7
   bipush 4
   idiv
   istore 13     ; i is in 13
   iload 7
   bipush 4
   irem
   istore 14     ; k is in 14
   bipush 32
   bipush 2
   iload 9  ;load e
   imul
   iadd
   bipush 2
   iadd
   iload 13 ; load i
   imul
   iload 12 ; load h
   isub
   iload 14 ; load k
   isub
   bipush 7
   irem
   istore 15      ; x is in 15
   iload 5
   bipush 11
   iload 12
   imul
   iadd
   bipush 22
   iload 15
   imul
   iadd
   sipush 451
   idiv
   istore 16      ; m is in 16
   iload 12
   iload 15
    iadd
   bipush 7
   iload 16
   imul
   isub
   bipush 114
   iadd
   bipush 31
   idiv
   istore 17     ; easter month is in 17  
  iload 12
  iload 15
   iadd
   bipush 7
   iload 16
  imul
  isub
   bipush 114
   iadd
   bipush 31
   irem
   bipush 1
   iadd
   istore 18     ; p is in 18

   iload 17        
   bipush 4  
   isub
   ifeq Print_April 
   aload_1     
   ldc "March"
   swap
   goto PRINT_IT   
   Print_April: 
   aload_1   
   ldc "April"
   PRINT_IT:

   invokestatic java/lang/String/valueOf(I)Ljava/lang/String;
   astore_3

   ; ... and print it

   aload_1    ; push the PrintStream object
   aload_3    ; push the string we just created - then ...
   invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V

   ; decrement the counter and loop
   iinc 4 1    ;increment year
   iinc 2 -1
   iload_2
   ifne Loop

   ; done
   return

.end method

所以我在这里弄明白它是

.class public Easter

.super java/lang/Object

.method public <init>()V

aload_0

 invokespecial java/lang/Object/<init>()V

 return

.end method

.method public static main([Ljava/lang/String;)V

       .limit stack 100

       .limit locals 50

      getstatic java/lang/System/out Ljava/io/PrintStream;

       astore_1

       ;    2 - the integer 10 - the counter used in the loop
       sipush 2009
       istore 4       ;year is in 4
       bipush 10
       istore_2       ;count is in 2 


       ; now loop 10 times printing out a number

     Loop:

       iinc 4 1
       iload 4  
       bipush 19
       irem
       istore 5     ; a is in 5


       iload 4  
       bipush 100
       idiv
       istore 6     ; b is in 6


       iload 4  
       bipush 100
       irem
       istore 7     ; c is in 7

       iload 6      
       bipush 4
       idiv
       istore 8     ; d is in 8

       iload 6      
       bipush 4
       irem
       istore 9     ; e is in 9

       iload 6
       bipush 8
       iadd 
       bipush 25
       idiv
       istore 10    ; f is in 10

       iload 6 
       iload 10
       isub
       bipush 1
       iadd
       bipush 3
       idiv
       istore 11    ; g is in 11

       bipush 19
       iload 5
       imul
       iload 6        
       bipush 15 
       iadd
       iadd
       iload 8
       iload 11
       iadd
       isub
       bipush 30
       irem
       istore 12     ; h is in 12

       iload 7
       bipush 4
       idiv
       istore 13     ; i is in 13

       iload 7
       bipush 4
       irem
       istore 14     ; k is in 14

       bipush 2
       iload 9  ;load e
       imul
       bipush 2
       iload 13 ; load i
       imul
       bipush 32
       iadd
       iadd
       iload 12 ; load h
       iload 14 ; load k
       iadd
       isub
       bipush 7
       irem
       istore 15      ; x is in 15

       bipush 11
       iload 12       ;load h
       imul
       bipush 22
       iload 15
       imul
       iload 5         ;load a
       iadd
       iadd
       sipush 451
       idiv
       istore 16      ; m is in 16

       iload 12
       iload 15
       bipush 114
       iadd
       iadd
       bipush 7
       iload 16
       imul
       isub
       istore 17
       iload 17
       bipush 31
       idiv
       istore 18    ; easter month is in 17

       iload 17
       bipush 31
       irem
       istore 19    ; p is in 19

       iload 18       
       bipush 4  
       isub
       ifeq Print_April
       aload_1  
       ldc "March " 
       goto PRINT_IT
       Print_April:
       aload_1
       ldc "April "
       goto PRINT_IT
       PRINT_IT:       

             invokevirtual java/io/PrintStream/print(Ljava/lang/String;)V

              aload_1
              iload 19
              bipush 1
              iadd
              invokestatic java/lang/String/valueOf(I)Ljava/lang/String;
              invokevirtual java/io/PrintStream/print(Ljava/lang/String;)V

             aload_1
             ldc ", "
             invokevirtual java/io/PrintStream/print(Ljava/lang/String;)V

             aload_1
             iload 4
             invokestatic java/lang/String/valueOf(I)Ljava/lang/String;
             invokevirtual java/io/PrintStream/print(Ljava/lang/String;)V

              aload_1
              ldc "\n"
              invokevirtual java/io/PrintStream/print(Ljava/lang/String;)V

       iinc 2 -1    ; check loop
       iload_2
       ifne Loop


       return

.end method

0 个答案:

没有答案