The present invention relates to the field of machine code assemblers. More particularly, the invention relates to a method for using the same assembly language and the same assembler for programming machine codes for various processors.
Assembly language is used primarily for direct hardware manipulation, access to specialized processor instructions, or to address critical performance issues. Typical uses are for device drivers, low-level embedded systems, and real-time systems. Programming in assembly language provides the programmer much control over the hardware performance of the system.
A group of statements written in an assembly language is referred to as a source code. Before the source code can be executed, the source statements of the source code must be transformed to machine readable/executable code. In order to generate a machine code from a source code, an assembler is required. The assembler includes a parser for reading the source code and a code generator for generating the machine readable/executable code. Thus, the assembler translates the source code into an object code, which consists of machine readable code, data, and address constants.
Each processor-architecture has its own machine code presentation. On this level, each instruction is simple enough to be executed using a relatively small number of electronic circuits. Processors differ by the number and type of operations they support. For example, a 64-bit machine would have different circuitry from a 32-bit machine, and thus require a different set of machine code operations. Different processors may also have different sizes and numbers of registers and different representations of data types in storage. While most general-purpose processors are able to carry out essentially the same functionality, the ways they do so differ; the corresponding machine code reflect these differences.
As of today many assembly languages use related syntax and grammar for programming. However, once the source code is written in an assembly language, the source code is typically translated by an assembler designed for a specific type of processor-architecture. Since typically a processor requires a specific representation of its machine code, only an assembler designed to generate that representation may be used. Thus different assemblers are required for different processor-architectures.
US 2002/0078324 discloses a microprocessor for processing various assembler codes. The disclosed microprocessor computes relative addresses of different program counter definitions. The relative addressing is dependent on the operating state or parameter of the respective assembler code. Nevertheless, the disclosed microprocessor only deals with relative addressing for different machine codes, it does not deal with different commands, symbols or data representations.
U.S. Pat. No. 7,111,287 discloses an assembler and an assembly language code that includes a plurality of code blocks associated with resource needs. The disclosed method allows the global assignment of resource needs to resources in order that run time resource conflicts are avoided. A grammar is also disclosed for allowing the definition of resource needs. Nevertheless, the described method requires the learning of a new grammar and a new assembly language in order assign resources efficiently.
It is an object of the present invention to provide an assembler capable of generating different machine codes for different processor-architectures.
It is another object of the present invention to provide a method for translating and assembling a generic source code into different machine codes.
It is still another object of the present invention to provide an assembler which does not require the programmer to learn a new assembly language or new grammar in order to program a new type of processor-architecture.
It is still another object of the present invention to provide a method that allows reusability of source code, programmed for one processor-architecture, for another processor-architecture.
Other objects and advantages of the invention will become apparent as the description proceeds.
The present invention relates to a method for realizing a generic assembler capable of translating a source code into machine codes for various processor-architectures comprising the steps of: (a) providing an assembler capable of reading a definitions file for translating source code commands into machine code commands; (b) loading said definitions file, which holds definitions related to a processor-architecture, into said assembler; (c) parsing and assessing, by said assembler, said definitions file for finding errors; (d) preparing the internal data structures of said assembler based on said definitions of said definitions file; and (e) translating a source code into a machine code, by said assembler using said definitions from said definitions file.
Preferably, the machine code is intended for a microprocessor.
Preferably, the definitions file defines register amounts and names.
Preferably, the definitions file defines the pipeline depth.
Preferably, the definitions file defines opcode sizes.
In one of the embodiments, the errors are found from definition conflicts in the definitions file.
In the drawings:
The heart of the invention lies in the use of a generic assembler capable of translating assembly commands to machine code based on a definitions file. By generic assembler it is meant to include an assembler that can parse commands used for known assemblers such as GAS for i64, and translate those commands into a specific machine code, intended for a specific processor-architecture, based on definitions from a definitions file. The definitions file may store addresses, sizes, symbols, register amounts and names, pipeline depth, opcode sizes memory definitions and address spaces etc. of a certain processor architecture. The definitions file may also define certain commands of the assembly language such as: RISC commands (for instance: addsub a command for adding or subtracting according to a given parameter), auxiliary commands (like: add for defining the parameters of addsub) and Label based commands (branch and load/store). Thus the same generic assembler may be used for generating different machine codes for different processor architectures based on different definitions from different definitions files. Each time a programmer wishes to translate a source code for a processor, he may load the intended processor's architectures definitions file into the generic assembler, and use the generic assembler for translating the source code to the processor's machine code. Once the definitions file is loaded into the assembler, the assembler translates the source code into a machine code according to the definitions in the definitions file.
For the sake of brevity an example is set forth for demonstrating the operation of the generic assembler. The described generic assembler can translate an assembly command from a source code to a machine code command using a definitions file. In this example the definition file, defines that there are only 2 available registers, in this processor-architecture, which their names are register1 and register2. The definitions file also defines that register1 and register2 are assigned the codes 0×1 and 0×2 respectively. Continuing the example, a source code command, written in assembly language, is shown:
In one of the uses of the invention, the engineer who designs the hardware of the processor is the one who creates the definitions file. Thus after the designing engineer defined his designed hardware in the definitions file and provided the definitions file, any assembly programmer can program for the processor without investing extra time in learning all the hardware setup.
While some embodiments of the invention have been described by way of illustration, it will be apparent that the invention can be carried into practice with many modifications, variations and adaptations, and with the use of numerous equivalents or alternative solutions that are within the scope of persons skilled in the art, without departing from the invention or exceeding the scope of claims.