import Location; import java.io.PrintWriter; /** * A register for the abstract assembly language. Each * register has a specified name. You can build new registers * (dangerous) or request some of the standard ones, such as * the stack pointer. * * @author Samuel A. Rebelsky * @version 1.0 of April 2001 */ public class Register implements Location { // +--------+------------------------------------------------------------ // | Fields | // +--------+ /** The name of the register, such as esp. */ protected String name; /** The frame pointer. */ protected static Register fp = null; /** The stack pointer. */ protected static Register sp = null; // +--------------+------------------------------------------------------ // | Constructors | // +--------------+ /** * Build a new register with a specified name. */ public Register(String initialName) { this.name = initialName; } // Register(String) // +------------------+-------------------------------------------------- // | Location Methods | // +------------------+ /** * Print the register. */ public void print(PrintWriter out) { out.print("%" + this.name); } // print(PrintWriter) // +---------------+----------------------------------------------------- // | Class Methods | // +---------------+ /** * Get the frame pointer. */ public static Register getFramePointer() { if (fp == null) { fp = new Register("ebp"); } return fp; } // getStackPointer() /** * Get the stack pointer. */ public static Register getStackPointer() { if (sp == null) { sp = new Register("esp"); } return sp; } // getStackPointer() } // class Register