1 / 6

Lecture 13 Java Virtual Machine: Instruction Set

Lecture 13 Java Virtual Machine: Instruction Set. Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology. 1. Java Program. class SumI { public static void main (String[] args) { int count=10; int sum =0;

fadhila
Download Presentation

Lecture 13 Java Virtual Machine: Instruction Set

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 13Java Virtual Machine: Instruction Set Instructors: Fu-Chiung Cheng (鄭福炯) Associate Professor Computer Science & Engineering Tatung Institute of Technology 1

  2. Java Program class SumI { public static void main (String[] args) { int count=10; int sum =0; for (int index=1;index<count;index++) sum=sum+index; } // method main } // class SumI 2

  3. Java ByteCode Method void main(java.lang.String[]) 0 bipush 10 // byte push 10 to stack (0x10) 2 istore_1 // load 10 (top of stack) to count 3 iconst_0 // push 0 to stack 4 istore_2 // load 0 (top of stack to sum 5 iconst_1 // push 1 to stack 6 istore_3 // load 1 (top of stack) to index 7 goto 17 // go to 17 3

  4. Java ByteCode 10 iload_2 // load sum to stack 11 iload_3 // load index to stack 12 iadd // add 13 istore_2 // store “top of stack” to sum 14 iinc 3 1 // index ++ 17 iload_3 // load index to stack 18 iload_1 // load count to stack 19 if_icmplt 10 // if index < count goto 10 22 return 3

  5. import java.io.*; class ReadFile { public static void main (String[] args) { try { FileInputStream in = new FileInputStream(args[0]); int c; while((c = in.read()) != -1) System.out.println(c); in.close(); } catch(Exception e) { e.printStackTrace(); } } // method main } // class ReadFile

  6. Reading 3:Chap 6: Java Virtual Machine Instruction set

More Related