A method of emulating a floating-point register stack operation in a Reduced Instruction Set Computing (RISC) processor, the RISC processor including a floating-point register file containing a plurality of floating-point registers, a decoding section for decoding operation instructions of the RISC processor, a floating-point operation section connected to the decoding section for reading and writing the floating-point register file according to an output value of the decoding section so as to perform a floating-point operation, and a control register for controlling the decoding section and the floating-point operation section to emulate the floating-point register stack operation using the floating-point register file, wherein the control register maintains a stack enable bit, the decoding section includes a pointer register, and the floating-point operation section includes a pointer operation module, the method comprising the following steps:
- Step A:
- determining if the floating-point registers are selected to emulate the floating-point register stack operation according to the stack enable bit, and setting the pointer register;
- and
- Step B:
- operating the pointer register so as to emulate a stack operation of a stack operation pointer, and modify and monitor a status of the stack operation pointer when the floating-point register stack operation is emulated;
- wherein the Step A includes the following steps:
- Step A1:
- selecting a bit in the control register as the stack enable bit, wherein the stack enable bit denotes that the RISC processor emulates a floating-point register stack of an X86 processor and performs the floating-point register stack operation when the stack enable bit is set to 1, and that the RISC processor neither emulates a floating-point register stack of the X86 processor nor performs the floating-point register stack operation when the stack enable bit is set to 0, and
- Step A2:
- setting at least 3 bits of the pointer register for storing the value of the stack operation pointer, and
- the value of the stack operation pointer is n, and in the case of the stack enable bit being 1:
- if a floating-point register number i involved in a given operation is equal to or less than 7, using a floating-point register number j to substitute for the floating-point register number i to conduct the given operation, wherein j=(i+n) mod 8, and
- if the floating-point register number i involved in the given operation is more than 7, using the floating-point register number i directly to conduct the given operation.