Guest User

Untitled

a guest
Jun 10th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
J 0.83 KB | None | 0 0
  1. ; Determines if a number is a power of two
  2. .class public Power
  3. .super java/lang/Object
  4.  
  5. .method public <init>()V
  6.     aload_0
  7.  
  8.     invokespecial java/lang/Object/<init>()V
  9.     return
  10. .end method
  11.  
  12. .method public static main([Ljava/lang/String;)V
  13.     .limit stack 2
  14.    
  15.     getstatic java/lang/System.out Ljava/io/PrintStream ; Load a PrintStream onto the stack
  16.    
  17.     ldc 256                         ; The number to check
  18.     invokestatic Power/isPowerOfTwo(I)I         ; Check the number
  19.    
  20.     invokevirtual java/io/PrintStream/println(I)V       ; Output the result (0 = its a power of two)
  21.    
  22.     return
  23. .end method
  24.  
  25. .method public static isPowerOfTwo(I)I
  26.     .limit stack 2
  27.     .limit locals 1
  28.  
  29.     iload_0     ; load the argument
  30.     ldc 1       ; put "1" on the stack
  31.     isub        ; subtract arg-1
  32.  
  33.     iload_0     ; load the argument again
  34.     iand        ; bitwise and
  35.  
  36.     ireturn     ; return the result
  37. .end method
Add Comment
Please, Sign In to add comment