[Asm2class-usage] [asm2class - asm2class usage] RE: Example of java assembly source
Status: Beta
Brought to you by:
boretti
From: SourceForge.net <no...@so...> - 2004-05-19 14:47:07
|
Read and respond to this message at: https://sourceforge.net/forum/message.php?msg_id=2577062 By: nobody // // Copyright (C) 2004 Boretti Mathieu // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // // This class do the following Sum // // 1+1/2+1/4+1/8+... = sum(1/(2^n)) // // N times // // // Define a class named "org.boretti.asm2class.example.somme" // Lorg/boretti/asm2class/example/somme; : // // Define a method named "main" with String [] as parameter and no // return value. This method is public and static // * . main ([Ljava/lang/String;)V : // // push 0.0f onto the stack // fconst_0 // 0 // // store the head of the stack into register 1 fstore_1 // // // push 1 onto the stack // iconst_1 // 1 // // store the head of the stack into register 2 // istore_2 // // // Push the static field "out" from class java.lang.System // that is of type java.io.PrintStream onto the stack // getstatic Ljava/lang/System; out Ljava/io/PrintStream; // 1 // // Duplicate the head // dup // 1 1 // // Store this static field into register 0 // astore_0 // 1 // // Push a small text // ldc "Please insert a integer" // 1 t // // Display the text // invokevirtual Ljava/io/PrintStream; (Ljava/lang/String;)V println // // // Creer un DataInputStream // new Ljava/io/DataInputStream; // 1 // // Duplicate the head // dup // 1 1 // // Push the static field "in" from class java.lang.System // that is of type java.io.InputStream onto the stack // getstatic Ljava/lang/System; in Ljava/io/InputStream; // 1 1 <s> // // Call initializer method // invokespecial Ljava/io/DataInputStream; (Ljava/io/InputStream;)V <init> // 1 // // Read Line // invokevirtual Ljava/io/DataInputStream; ()Ljava/lang/String; readLine // 1 // // Convert String to Integer // invokestatic Ljava/lang/Integer; (Ljava/lang/String;)Ljava/lang/Integer; valueOf // 1 // // Convert nomber to int // invokevirtual Ljava/lang/Integer; ()I intValue // 1 // // Duplicate the head // START : dup // // load register 2 onto the stack // iload_2 // // compare head-1 and head of the stack and jump to FIN if the relation is < // if_icmplt FIN // // Push 1.0f onto the stack // fconst_1 // 1f // // Push register 0 onto the stack // aload_0 // 1f out // // Duplicate the head of the stack and insert 2 value down // dup_x1 // out 1f out // // Duplicate the head of the stack // dup // out 1f out out // // load register 2 onto the stack // iload_2 // out 1f out out <2> // // Duplicate the head of the stack and insert 2 value down // dup_x2 // out 1f <2> out out <2> // // Invoke print to display the counter for the loop // invokevirtual Ljava/io/PrintStream; (I)V print // out 1f <2> out // // push ":" onto the stack // ldc ":" // out 1f <2> out ":" // // Invoke print to display the ":" // invokevirtual Ljava/io/PrintStream; (Ljava/lang/String;)V print // out 1f <2> // // Push constant 1 onto the stack // iconst_1 // out 1f <2> 1 // // Shift left // ishl // out 1f <2d> // // Convert head of the stack to float // i2f // out 1f <2df> // // Divide the head of the stack // fdiv // out <v> // // Push register 1 onto the stack // fload_1 // out <v> <1> // // Add head-1 and head // fadd // out <s> // // Duplicate the head // dup // out <s> <s> // // store head into register 1 // fstore_1 // out <s> // // Display the current value of the sum // invokevirtual Ljava/io/PrintStream; (F)V println // // // Increment register 2 by 1 // iinc 2 1 // // Jump to START // goto START // // Drop the head of the stack // FIN : pop // // Return from the method // return ______________________________________________________________________ You are receiving this email because you elected to monitor this forum. To stop monitoring this forum, login to SourceForge.net and visit: https://sourceforge.net/forum/unmonitor.php?forum_id=373524 |