Assuming that you want to know how the assembly code is assembled, what type of command selection ends in the assembly code with certain properties, then (on x86 / x64) do the following:
Find the Intel instruction set reference guides (I think these are four volumes at the time of this writing). They contain operation code tables (binary command formats) and detailed lists of all allowed operation codes for a specific assembly mnemonics (command name).
Familiarize yourself with them and mentally divide them into two groups - those that correspond to your expected properties (for example, those that do not contain the symbol "x" ... or any other specific), and those that do not. Category 2, which you must remove from your code, if present.
Compile your code by telling the compiler not to drop intermediate intermediate fragments:
gcc -save-temps -c csource.c
- Parse the object file:
objdump -d csource.o
The disassembly output from objdump will contain binary instructions (operation codes), as well as the names of commands (mnemonics), that is, you will see which format of the operation code was selected. Now you can check if there are any operation codes from the 2nd set in accordance with 1. above.
Now begins the creative bit of work. When you find an instruction at the output of a disassembly that does not meet the expected requirements / requirements, find / create a replacement (or, most often, a replacement sequence of several instructions) that gives the same final result, but only composed of instructions that correspond to what you need.
Go back to the compilation intermediate elements at the top, find the csource.s assembly, make changes, reassemble / go, check.
If you want to make your assembly code standalone (i.e. do not use the system runtime libraries / make system calls directly), refer to the documentation on the internal functions of the operating system (how to make system calls) and / or disassemble the runtime libraries that they usually do it is on your behalf to find out how this is done.
Since 5. is definitely a homework of the same type as creating a C for() while() equivalent to a given while() , don't expect too much help there. Instruction set guides and assembler experiments (dis) are all you need here.
In addition, if you study, attend lessons on how compilers work / how to write compilers - they cover how assembly of assembly commands is performed by compilers, and I can well imagine that this is an interesting / complex project, for example, write a compiler whose output is guaranteed contains the character ' ? '( 0x3f ) but never' ! '( 0x21 ). You get the idea.
source share