Assembly method, disassembly method, device and storage medium
By using preset method classes and a unified instruction format during assembly and disassembly, machine code and instruction structures are directly generated and filled in, solving the problem of long traditional toolchain processes and improving the development efficiency of assembly and disassembly tools.
Patent Information
- Application Number
- CN202211724568.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-30
- Publication Date
- 2026-01-09
- Estimated Expiration
- 2042-12-30
AI Technical Summary
Traditional assembler and disassembler tools have long toolchain processes, involving the parsing, splitting, and generation of text assembly instructions, resulting in low development efficiency.
By acquiring preset method classes, including assembly functions and instruction formats, the assembly instructions are directly stored in the bit range to generate machine code, avoiding the parsing and segmentation of text assembly instructions; during disassembly, a unified instruction format is used to match the target operator and operands and fill in the instruction structure, avoiding the generation of text assembly instructions.
It improves the development efficiency of assembler and disassembler tools, reduces workload, reduces interface integration and debugging overhead during development, and achieves unified management and updating of instruction formats.
Smart Images

Figure CN116088864B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to an assembly method, a disassembly method, a device and a storage medium, and belongs to the technical field of computers. BACKGROUND
[0002] Assembly refers to the process of compiling source code written in assembly language into machine code that can be recognized by a computer, and disassembly is the opposite, which refers to the process of converting machine code or executable program machine code into assembly language source code.
[0003] In the traditional assembly and disassembly process, according to the tool chain process of the traditional assembly and disassembly tool, in the assembly process, the readable text assembly instruction is first parsed into an abstract software operation, and then converted into binary machine code, and in the disassembly process, the binary machine code is converted into an instruction object, and then the instruction object is converted into a readable text assembly instruction.
[0004] However, the tool chain process of the traditional assembly and disassembly tool is long, involves parsing, splitting and generating of text assembly instructions, increases additional work investment, and causes the problem of low development efficiency of assembly and disassembly tools. SUMMARY
[0005] The present application provides an assembly method, a disassembly method, a device and a storage medium, which can solve the problem of long tool chain process of traditional assembly and disassembly tools, which involves parsing, splitting and generating of text assembly instructions, increases additional work investment, and causes the problem of low development efficiency of assembly and disassembly tools.
[0006] The present application provides the following technical solutions:
[0007] In a first aspect, an assembly method is provided, which comprises:
[0008] obtaining a preset method class; the preset method class includes at least one assembly function and an instruction format corresponding one-to-one to the at least one assembly function;
[0009] In the preset method class, a target assembly function is obtained;
[0010] The target assembly function receives a target operand corresponding to a target assembly instruction;
[0011] The target instruction format corresponding to the target assembly instruction is determined in the instruction format; the target instruction format is used to indicate a bit interval corresponding to the target assembly instruction;
[0012] The target assembly instruction is stored in the bit interval to obtain machine code corresponding to the target assembly instruction.
[0013] Optionally, the target instruction format is further used to indicate a target operator of the target assembly instruction and a target operator code corresponding to the target operator; the bit range includes a first bit range corresponding to the target operator and a second bit range corresponding to the target operand.
[0014] Optionally, the storing of the target assembly instruction into the bit range to obtain the machine code corresponding to the target assembly instruction comprises:
[0015] storing the target operator code into the first bit range;
[0016] determining a target operand code corresponding to the target operand;
[0017] storing the target operand code into the second bit range.
[0018] Optionally, the storing of the target assembly instruction into the bit range to obtain the machine code corresponding to the target assembly instruction comprises:
[0019] obtaining a target operator of the target assembly instruction; the bit range includes a first bit range corresponding to the target operator and a second bit range corresponding to the target operand;
[0020] determining a target operator code corresponding to the target operator in the operator code based on a preset relationship between operators and operator codes;
[0021] storing the target operator code into the first bit range;
[0022] determining a target operand code corresponding to the target operand;
[0023] storing the target operand code into the second bit range.
[0024] Optionally, the obtaining of the target operator of the target assembly instruction comprises:
[0025] obtaining a function name of the target assembly function as the target operator.
[0026] Optionally, the target instruction format is further used to indicate an instruction structure corresponding to the target assembly instruction; the instruction structure includes a number of the target operands and registers corresponding to the target operands.
[0027] In a second aspect, a disassembling method is provided, and the method comprises:
[0028] obtaining a preset method class;
[0029] In the preset method class, a target disassembly function is acquired;
[0030] A target machine code is received through the target disassembly function; the target machine code is obtained by assembling a target assembly instruction using the assembly method of the first aspect;
[0031] A target operator and a target operand are determined based on the target machine code;
[0032] At least one instruction format is acquired;
[0033] The at least one instruction format is matched with the target operator in sequence, and a target instruction format is determined in the at least one instruction format; the target instruction format is used to indicate an instruction structure corresponding to the target assembly instruction;
[0034] The target operand is filled into the instruction structure to obtain the target assembly instruction.
[0035] Optionally, the target operator and the target operand are determined based on the target machine code, and the method comprises:
[0036] The target machine code is decomposed to obtain a target operator code and at least one target operand code;
[0037] A target operator corresponding to the target operator code is determined in the operator based on a preset relationship between an operator and an operator code;
[0038] The target operand is obtained by converting the at least one target operand code.
[0039] In a third aspect, an electronic device is provided, which comprises a processor and a memory, and the memory stores a program which is loaded and executed by the processor to implement the steps of the assembly method of the first aspect or the steps of the disassembly method of the second aspect.
[0040] In a fourth aspect, a computer readable storage medium is provided, and the storage medium stores a program which, when executed by a processor, is used to implement the steps of the assembly method of the first aspect or the steps of the disassembly method of the second aspect.
[0041] The application has the beneficial effects that: a preset method class is acquired; the preset method class includes at least one assembly function and an instruction format corresponding to the at least one assembly function; in the preset method class, a target assembly function is acquired; a target operand corresponding to a target assembly instruction is received through the target assembly function; a target instruction format corresponding to the target assembly instruction is determined in the instruction format; the target instruction format is used to indicate a bit interval corresponding to the target assembly instruction; and the target assembly instruction is stored in the bit interval to obtain machine code corresponding to the target assembly instruction. The problem that a traditional assembly tool chain process is long, involves parsing, splitting and generating of text assembly instructions, increases additional work investment, and leads to low assembly efficiency tool development efficiency can be solved. The target operand is received through the target assembly function, and then the target operator and the bit interval of the target operand are determined according to the corresponding target instruction format, without using the text assembly instruction, so that the parsing, splitting and generating of the text assembly instruction are avoided, the work investment is reduced, and the development efficiency of the assembly tool is improved. Meanwhile, the structured assembly instruction is used to define the instruction format, the existing characteristics of the underlying programming language are utilized, and repeated development work is not needed, so that the development efficiency of the assembly tool is further improved.
[0042] In addition, a preset method class is acquired; in the preset method class, a target disassembly function is acquired; a target machine code is received through the target disassembly function; a target operator and a target operand are determined based on the target machine code; at least one instruction format is acquired; the at least one instruction format is matched with the target operator in sequence, and a target instruction format is determined in the at least one instruction format; the target instruction format is used to indicate an instruction structure corresponding to a target assembly instruction; the target operand is filled into the instruction structure to obtain the target assembly instruction, and a unified instruction format is shared with an assembly process. The problem that a disassembly tool development efficiency is low can be solved; the target machine code is received through the target disassembly function, the target instruction function is matched to obtain the target instruction function, the target operator and the target operand corresponding to the target machine code are filled into the instruction structure indicated by the target instruction format, the target assembly instruction can be obtained, the generation of the text assembly instruction is avoided, the development work of the disassembly tool chain is reduced, the development efficiency of the disassembly tool can be improved; meanwhile, the situation that the assembly and the disassembly tool are inconsistent in instruction format definition is avoided, the interface docking and debugging overhead in the development process are reduced, and the development efficiency of the assembly and the disassembly tool is further improved. BRIEF DESCRIPTION OF DRAWINGS
[0043] Figure 1 is a flowchart of an assembly method provided by an embodiment of the application;
[0044] Figure 2 is a schematic diagram of code automatic completion provided by an embodiment of the application;
[0045] Figure 3 is a schematic diagram of an assembly text of an assembly instruction and a program voice provided by an embodiment of the present application;
[0046] Figure 4 is a schematic diagram of a disassembly method provided by an embodiment of the present application;
[0047] Figure 5 is a schematic diagram of machine code decomposition provided by an embodiment of the present application;
[0048] Figure 6 is a block diagram of an assembly device provided by an embodiment of the present application;
[0049] Figure 7 is a block diagram of a disassembly device provided by an embodiment of the present application;
[0050] Figure 8 is a block diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0051] The technical solutions of the present application will be described clearly and completely below with reference to the accompanying drawings. Obviously, the described embodiments are some of the embodiments of the present application, but not all the embodiments. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments. It should be noted that the embodiments in the present application and the features in the embodiments can be combined with each other without conflict.
[0052] It should be noted that the terms "first", "second" and the like in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and do not necessarily describe a specific order or sequence.
[0053] In the application, the orientation words such as "up", "down", "top", "bottom" are generally directed to the direction shown in the drawings, or to the vertical, vertical or gravity direction of the components themselves; similarly, for the convenience of understanding and description, "inner", "outer" refers to the inner and outer relative to the contour of each component itself, but the above-mentioned orientation words are not used to limit the application.
[0054] As shown in Figure 1 The embodiments of the present application provide an assembly method, the implementation of the method can depend on a computer program, the computer program can run on a computer device such as a smart phone, a tablet computer, a personal computer or a server, and the present embodiment does not limit the running subject of the method. The method comprises at least the following steps:
[0055] Step 101, obtaining a preset method class.
[0056] The preset method class includes at least one assembly function and an instruction format corresponding to the at least one assembly function.
[0057] In the embodiment, the assembly function corresponds to the instruction format. The instruction format is used to indicate an instruction structure corresponding to the assembly instruction.
[0058] In the definition of the instruction format, the existing programming language (for example, Python, C++, etc.) is deeply coupled, so that the instruction structure of the assembly instruction conforms to the syntax and grammar requirements of the underlying programming language, and the assembly instruction can be directly simplified into a code sequence. In this way, the process of using the traditional assembly text instruction as an intermediate product and then using the just-in-time compilation and just-in-time execution technology to execute the assembly instruction by using the virtual machine of the underlying programming language to generate an instruction object is saved, so that the text analysis and segmentation work is saved, and the efficiency of the assembly instruction assembly is improved.
[0059] Meanwhile, by unifying the assembly instruction format with the existing underlying programming language, the existing mature development environment and development tool (for example, IDE, eclipse, etc.) can be directly reused, so that the code completion reminder, automatic error correction and debugging of the assembly instruction are realized (for reference Figure 2 ).
[0060] In the embodiment, the definition of the instruction format is divided into two parts: an operator and an operand. The operator part is used to distinguish the type of the instruction, for example, addition or subtraction, etc. The operator part is used to configure the attribute (for example, the input, output address or register number of addition) that needs to be operated by the assembly instruction.
[0061] In the embodiment, the preset method class is a method class that is set in advance. The method class is provided with at least one assembly function. Each assembly function is used to assemble different assembly instructions.
[0062] For example, taking assembly function A and assembly function B as an example, the instruction format corresponding to the assembly function A is instruction format A1, which is used to assemble assembly instruction A2. The instruction format corresponding to the assembly function B is instruction format B1, which is used to assemble assembly instruction B2.
[0063] In step 102, a target assembly function is obtained in the preset method class.
[0064] In the embodiment, the target assembly function is used to assemble the target assembly instruction.
[0065] In step 103, a target operand corresponding to the target assembly instruction is received by the target assembly function.
[0066] The iteration of the traditional assembly, disassembly tool chain is initially developed for assembly programmers. Since the traditional assembler needs to process the text assembly instructions written by the programmer, the text needs to be parsed and segmented; correspondingly, the traditional disassembler needs to convert the machine code into text assembly instructions for assembly programmers to read and analyze.
[0067] For example, refer to Figure 3 Take the assembly instruction as an addition assembly instruction as an example. In the assembly text, the assembly instruction is represented by the following formula:
[0068] Addi r0, r1, 1
[0069] In the traditional assembly process, the first line of the assembly text is read to obtain the operator of the addition assembly instruction as Addi, and the second half is read to obtain the operands as r0, r1, and 1; and the parsed op1=r0, op2=r1, and result=r1 are obtained.
[0070] In this embodiment, the target assembly instruction in the preset method class is obtained, the target operand corresponding to the target assembly instruction is received, and the target assembly function is used to perform assembly operation on the input operand.
[0071] For example, refer to Figure 2 Take the preset method class inst[0].assembly as an example, and the target assembly function as the Add function; the Add function reads to obtain op1=r0, op2=r1, and result=r1.
[0072] Step 104, determining the target instruction format corresponding to the target assembly instruction in the instruction format.
[0073] The target instruction format is used to indicate the bit interval corresponding to the target assembly instruction.
[0074] In this embodiment, the definition of the instruction format includes two parts of the operator and the operand, and correspondingly, the bit interval includes the first bit interval corresponding to the target operator and the second bit interval corresponding to the target operand.
[0075] In addition, the target instruction format is also used to indicate the instruction structure corresponding to the target assembly instruction; the instruction structure includes the number of target operands and the registers corresponding to the target operands.
[0076] Step 105, storing the target assembly instruction into the bit interval to obtain the machine code corresponding to the target assembly instruction.
[0077] The target assembly instruction is stored in the bit interval to obtain the machine code corresponding to the target assembly instruction, including: storing the target operator code corresponding to the target operator in the first bit interval; and storing the target operand code corresponding to the target operand in the second bit interval.
[0078] In the embodiment, the target operator code and the target operand code are binary codes, and the target operator code corresponding to the target operator is obtained before being stored in the first bit interval.
[0079] In one example, as shown in Figure 3 The target instruction format is also used to indicate the target operator of the target assembly instruction and the target operator code corresponding to the target operator.
[0080] At this time, the target assembly instruction is stored in the bit interval to obtain the machine code corresponding to the target assembly instruction, including: storing the target operator code in the first bit interval; determining the target operand code corresponding to the target operand; and storing the target operand code in the second bit interval.
[0081] For example, taking the target assembly instruction of the addition type and the target operator Add corresponding to the target assembly instruction as an example, the target operator code corresponding to the target operator can be 00, which occupies the range of [0, 2) bits in the bit interval. In the assembly process, the target operator code 00 corresponding to the target assembly instruction can be written into the range of [0, 2) bits in the bit interval, to complete the conversion from the abstract instruction to the binary machine code instruction.
[0082] In another example, a correspondence relationship is preset between the operator and the operator code, and after the target operator of the target assembly instruction is obtained, the target operator code corresponding to the target operator is obtained by querying the preset relationship between the operator and the operator code.
[0083] At this time, the target assembly instruction is stored in the bit interval to obtain the machine code corresponding to the target assembly instruction, including: obtaining the target operator of the target assembly instruction; the bit interval includes the first bit interval corresponding to the target operator and the second bit interval corresponding to the target operand; based on the preset relationship between the operator and the operator code, the target operator code corresponding to the target operator is determined in the operator code; the target operator code is stored in the first bit interval; the target operand code corresponding to the target operand is determined; and the target operand code is stored in the second bit interval.
[0084] The target operator of the target assembly instruction is obtained, including: obtaining the function name of the target assembly function as the target operator.
[0085] To sum up, the embodiment provides an assembly method, including: obtaining a preset method class; the preset method class includes at least one assembly function and an instruction format corresponding to the at least one assembly function; in the preset method class, obtaining a target assembly function; receiving a target operand corresponding to a target assembly instruction through the target assembly function; determining a target instruction format corresponding to the target assembly instruction in the instruction format; the target instruction format is used to indicate a bit interval corresponding to the target assembly instruction; storing the target assembly instruction into the bit interval to obtain machine code corresponding to the target assembly instruction. The problem that a tool chain process of traditional assembly is long, involves parsing, splitting and generating of text assembly instructions, increases additional work investment, and leads to low development efficiency of assembly efficiency tools can be solved. The target operand is received through the target assembly function, then the target operator and the bit interval of the target operand are determined according to the corresponding target instruction format, the text assembly instruction is not needed to be used, the parsing, splitting and generating of the text assembly instruction are avoided, the work investment is reduced, and therefore the development efficiency of the assembly tool is improved. Meanwhile, the structured assembly instruction is used for format definition of the instruction format, the existing characteristics of the underlying programming language are utilized, repeated development work is not needed, and therefore the development efficiency of the assembly tool is further improved.
[0086] As Figure 5 shown, the embodiment provides a disassembly method, implementation of the method can depend on a computer program, the computer program can run on a computer device such as a smart phone, a tablet computer, a personal computer or a server, and the embodiment does not limit the running subject of the method. The method at least includes the following steps:
[0087] Step 401, obtaining a preset method class.
[0088] Step 402, in the preset method class, obtaining a target disassembly function.
[0089] Step 403, receiving target machine code through the target disassembly function.
[0090] The target machine code is obtained by using the above assembly method to assemble the target assembly instruction.
[0091] Step 404, determining a target operator and a target operand based on the target machine code.
[0092] The target operator and the target operand are determined based on the target machine code, including: decomposing the target machine code to obtain a target operator code and at least one target operand code; determining a target operator corresponding to the target operator code in the operator based on a preset relationship between the operator and the operator code; and converting the at least one target operand code to obtain the target operand.
[0093] For example, refer to Figure 5 Taking the target machine code 0000100001000100011 as an example, the target machine code is decomposed to obtain 00001, 00001, 00010 and 00011, wherein the first 00001 is a target operator code corresponding to the target machine code, and the second 00001, 00010 and 00011 are target operand codes corresponding to the target machine code.
[0094] In step 405, at least one instruction format is obtained.
[0095] The at least one instruction format is the same as the at least one instruction format in the above-mentioned embodiment of the assembly method.
[0096] Traditional general-purpose compiling tools are mostly based on general-purpose CPUs as the main hardware object, and the assembler and the disassembler are independently developed, each having an independent instruction format definition and parsing method. The instruction format of the target hardware needs to be repeatedly defined in the assembler and the disassembler, which increases the redundant work, consumes more development manpower and time, and is not conducive to the unified management and updating of the hardware instruction format.
[0097] In the embodiment, the instruction format of the assembly instruction is defined in the preset method class, and the same instruction format is used in the assembly and disassembly process, thereby realizing the unification of the instruction format of the assembly and the disassembly, reducing the development manpower and time, and facilitating the unified management and updating of the instruction format.
[0098] In step 406, the at least one instruction format is matched with the target operator in sequence, and the target instruction format is determined in the at least one instruction format.
[0099] The target instruction format is used to indicate the instruction structure corresponding to the target assembly instruction.
[0100] In step 407, the target operand is filled into the instruction structure to obtain the target assembly instruction.
[0101] To sum up, the embodiment provides a disassembly method, including: obtaining a preset method class; obtaining a target disassembly function in the preset method class; receiving target machine code through the target disassembly function; determining a target operator and a target operand based on the target machine code; obtaining at least one instruction format; sequentially matching the at least one instruction format with the target operator, and determining a target instruction format in the at least one instruction format; the target instruction format is used for indicating an instruction structure corresponding to a target assembly instruction; and filling the target operand into the instruction structure to obtain the target assembly instruction, through sharing a unified instruction format with an assembly process. The problem of low development efficiency of a disassembly tool can be solved. The target machine code is received through the target disassembly function, and a target instruction function is obtained through matching, and the target operator and the target operand corresponding to the target machine code are filled into an instruction structure indicated by the target instruction format, so that the target assembly instruction is obtained, the generation of a text assembly instruction is avoided, the development work of a disassembly tool chain is reduced, and the development efficiency of the disassembly tool is improved. Meanwhile, the situation that an assembly tool and a disassembly tool are inconsistent in instruction format definition is avoided, the interface docking and debugging overhead in the development process are reduced, and the development efficiency of the assembly tool and the disassembly tool is further improved.
[0102] Figure 6 is a block diagram of an assembly device provided by an embodiment of the present application. The device includes at least the following modules: a method obtaining module 610, a function obtaining module 620, a target receiving module 630, a format determining module 640, and an instruction storing module 650.
[0103] The method obtaining module 610 is configured to obtain a preset method class; the preset method class includes at least one assembly function and an instruction format corresponding to the at least one assembly function in a one-to-one manner.
[0104] The function obtaining module 620 is configured to obtain a target assembly function in the preset method class.
[0105] The target receiving module 630 is configured to receive a target operand corresponding to a target assembly instruction through the target assembly function.
[0106] The format determining module 640 is configured to determine a target instruction format corresponding to the target assembly instruction in the instruction format; the target instruction format is used for indicating a bit position interval corresponding to the target assembly instruction.
[0107] The instruction storing module 650 is configured to store the target assembly instruction into the bit position interval to obtain machine code corresponding to the target assembly instruction.
[0108] For related details, refer to the above assembly method embodiment.
[0109] Figure 7 is a block diagram of a disassembling apparatus provided by an embodiment of the present application. The apparatus comprises at least the following modules: a first obtaining module 710, a second obtaining module 720, a target receiving module 730, a target determining module 740, a third obtaining module 750, a format matching module 760, and an instruction filling module 770.
[0110] The first obtaining module 710 is configured to obtain a preset method class.
[0111] The second obtaining module 720 is configured to obtain a target disassembling function in the preset method class.
[0112] The target receiving module 730 is configured to receive a target machine code through the target disassembling function.
[0113] The target determining module 740 is configured to determine a target operator and a target operand based on the target machine code.
[0114] The third obtaining module 750 is configured to obtain at least one instruction format.
[0115] The format matching module 760 is configured to sequentially match the at least one instruction format with the target operator, and determine a target instruction format in the at least one instruction format; the target instruction format is configured to indicate an instruction structure corresponding to a target assembly instruction.
[0116] The instruction filling module 770 is configured to fill the target operand into the instruction structure to obtain the target assembly instruction.
[0117] For related details, refer to the above-described disassembling method embodiments.
[0118] It should be noted that: the above-described two apparatus embodiments are only used as examples for the division of the above-described functional modules, and in actual applications, the above-described functions can be completed by different functional modules according to needs, that is, the internal structure of the assembly apparatus or the disassembly apparatus is divided into different functional modules to complete all or part of the functions described above. In addition, the assembly / disassembly apparatus and the assembly / disassembly method embodiments provided by the above-described embodiments belong to the same concept, and the specific implementation process is described in detail in the method embodiments, which will not be repeated here.
[0119] Figure 8 is a block diagram of an electronic device provided by an embodiment of the present application. The electronic device can be: a smart phone, a tablet computer, a notebook computer, a desktop computer, or a server. The electronic device can also be referred to as a user device, a portable terminal, a laptop terminal, a desktop terminal, a control terminal, etc., and the present embodiment does not limit this. The electronic device comprises at least a processor and a memory.
[0120] The processor can include one or more processing cores, such as a 4-core processor, a 6-core processor, etc. The processor can be implemented in at least one of a hardware form of a DSP (Digital Signal Processing), an FPGA (Field-Programmable Gate Array), a PLA (Programmable Logic Array). The processor can also include a main processor and a coprocessor. The main processor is a processor for processing data in an awake state, also known as a CPU (Central Processing Unit). The coprocessor is a low-power processor for processing data in a standby state. In some embodiments, the processor can be integrated with a GPU (Graphics Processing Unit) that is responsible for rendering and drawing the content required to be displayed on the display screen. In some embodiments, the processor can also include an AI (Artificial Intelligence) processor for processing machine learning-related computing operations.
[0121] The memory can include one or more computer-readable storage media, which can be non-transitory. The memory can also include a high-speed random access memory, and a nonvolatile memory such as one or more disk storage devices, flash storage devices. In some embodiments, the non-transitory computer-readable storage medium in the memory is used to store at least one instruction for being executed by the processor to implement the steps of the above-mentioned assembly method or disassembly method embodiments.
[0122] In some embodiments, the above-mentioned electronic device can also optionally include a peripheral device interface and at least one peripheral device. The processor, the memory, and the peripheral device interface can be connected through a bus or a signal line. Each peripheral device can be connected to the peripheral device interface through a bus, a signal line, or a circuit board. Illustratively, the peripheral device includes, but is not limited to, a radio frequency circuit, a touch display screen, an audio circuit, and a power supply, etc.
[0123] Of course, the above-mentioned electronic device can also include fewer or more components, and the present embodiment does not limit this.
[0124] Optionally, the present application also provides a computer-readable storage medium, which stores a program. The program is loaded and executed by the processor to implement the steps of the above-mentioned assembly method or disassembly method embodiments.
[0125] Optionally, the present application also provides a computer product, comprising a computer readable storage medium, wherein a program is stored in the computer readable storage medium, and the program is loaded and executed by a processor to implement the steps of the above-mentioned assembly method or disassembly method embodiments.
[0126] The technical features of the above-mentioned embodiments can be combined in any manner. In order to make the description simple, all possible combinations of the technical features in the above-mentioned embodiments are not described, however, as long as the combinations of the technical features do not exist contradictory, they should be considered as the scope of the present disclosure.
[0127] The above-mentioned embodiments only express several implementation manners of the present application, and the description is more specific and detailed, but it should not be understood as a limitation on the scope of the patent. It should be pointed out that, for ordinary skilled in the art, without departing from the concept of the present application, a number of modifications and improvements can be made, which are all within the scope of the present application. Therefore, the scope of the patent of the present application should be subject to the appended claims.
Claims
1. An assembling method characterized by, The method comprises: acquiring a preset method class; the preset method class comprises at least one assembly function and an instruction format corresponding to the at least one assembly function, the instruction format comprising an operator and an operand, wherein the operator is used to distinguish the type of the instruction, and the operator part configures the attribute of the operation required by the assembly instruction; in the preset method class, a target assembly function is acquired; a target operand corresponding to a target assembly instruction is received through the target assembly function; a target instruction format corresponding to the target assembly instruction is determined in the instruction format; the target instruction format is used to indicate a bit interval corresponding to the target assembly instruction, and the target instruction format is also used to indicate a target operator of the target assembly instruction and a target operator code corresponding to the target operator; the target assembly instruction is stored in the bit interval to obtain machine code corresponding to the target assembly instruction, comprising: acquiring a target operator of the target assembly instruction; the bit interval comprises a first bit interval corresponding to the target operator and a second bit interval corresponding to the target operand; based on a preset relationship between the operator and the operator code, a target operator code corresponding to the target operator is determined in the operator code; the target operator code is stored in the first bit interval; a target operand code corresponding to the target operand is determined; and the target operand code is stored in the second bit interval.
2. The method of claim 1, wherein, The target operator of the target assembly instruction is acquired, comprising: the function name of the target assembly function is acquired as the target operator.
3. The method of claim 1, wherein, The target instruction format is also used to indicate an instruction structure corresponding to the target assembly instruction; the instruction structure comprises the number of the target operands and the registers corresponding to the target operands.
4. A method of disassembling, characterized by, The method comprises: acquiring a preset method class; in the preset method class, a target disassembly function is acquired; a target machine code is received through the target disassembly function; the target machine code is obtained by assembling a target assembly instruction using the assembly method of any one of claims 1-3; based on the target machine code, a target operator and a target operand are determined; at least one instruction format is acquired; the at least one instruction format is matched with the target operator in sequence, and a target instruction format is determined in the at least one instruction format; the target instruction format is used to indicate an instruction structure corresponding to the target assembly instruction; the target operand is filled into the instruction structure to obtain the target assembly instruction.
5. The method of claim 4, wherein, The target operator and the target operand are determined based on the target machine code, comprising: the target machine code is decomposed to obtain a target operator code and at least one target operand code; based on a preset relationship between the operator and the operator code, a target operator corresponding to the target operator code is determined in the operator; the at least one target operand code is converted to obtain the target operand.
6. An electronic device comprising a processor and a memory, wherein the memory stores a program, characterized in that, The program is loaded and executed by the processor to implement the steps of the assembling method according to any one of claims 1 to 3, or the steps of the disassembling method according to any one of claims 4 to 5.
7. A computer-readable storage medium having stored therein a program, characterized in that, The program is loaded and executed by the processor to implement the steps of the assembling method according to any one of claims 1 to 3, or the steps of the disassembling method according to any one of claims 4 to 5.
Citation Information
Patent Citations
Instruction assembly method and device, computer equipment and storage medium
CN113407236A
Machine code instruction conversion method and device, electronic equipment and readable storage medium
CN115269006A