Computer Composition Principles Experiment Report II - Understanding Assembly Language

Experimental data:
https://wwpv.lanzoue.com/b05drqjef
Password: d19t

  1. Use the txt file to write the following C source code, the file is named [Student Number_hello.c] and use the Mingw tool (an
    abbreviation for Minimalist GNU for Windows) to compile gcc.exe with options in the bin folder (), open the file and take a screenshot .
#include<stdio.h>
#define A 1000
int main()
{
    
    
	printf("hello_%d",A);
	return 0;
}
options Generated file extension Open generated file screenshot
gcc.exe -E xx.c .i preprocessing
gcc.exe -S xx.c .s compile
gcc.exe -c xx.c .o compilation
gcc.exe xx.c -o xx.exe .exe Link
gcc.exe xx.c -v .txt Version Information

Note: Refer to the figure below for the actual use of the first to four commands. Reference
compile c program
:
GCC Compiler Common Commands
C Language Compilation - gcc Compilation Instructions
gcc Compilation Command Detailed Explanation and Best Practice
C Language Compilation Process Detailed Explanation

Step 1: Open the DOS window:
press and hold shift + right mouse button, select "Open XXXX window here"

Step 2: Know the common options of Gcc
-E *.i preprocessed file
-S *.s assembly file
-c * .o target file object (binary)
  hello.o + printf.o + math.o = *.exe
  printf.o + math.o+… packaged into a library file
-o specify to generate the desired EXE file name
-v

Step 3: Type the following command
.\gcc.exe .\2100130499_hello.c -E (display to the screen)
.\gcc.exe .\2100130499_hello.c -E > 2100130499_hello.i (redirect the content on the screen to txt)
. \gcc.exe .\2100130499_hello.c -v (display version information on the screen, cannot be redirected directly)
.\gcc.exe .\2100130499_hello.c -v 2>&1 > 2100130499_hello.txt (need to add 2>&1 and then Redirection)
.\gcc.exe .\2100130499_hello.c (automatically generate executable file a.exe)
.\gcc.exe .\2100130499_hello.c -o change to your student number.exe (specify to generate a specific file name exe)
Note: -c -S and other options will be automatically generated

  1. Use the txt file software to open the [student number _hello.s] assembly file, and change the "hello" of the assembly statement to "Kitty" (Screenshot after modification), and use gcc.exe student number_hello.s -o student number_Kitty.exe to run student number_Kitty.exe in the DOS interface,Screenshot of running effect.
    Reference screenshot:
    modify assembly
    run the program

  2. Copy the cumulative C source code from 1 to 10 below to [Student Number_sum.c],
    (1) Use gcc.exe Student Number_sum.c -O0 -S-o student number_sum_O0.s, view the generated file, screenshot
    (2) Use gcc.exe student number_sum.c -O2 -S-o student number_sum_O2.s, view the generated file, screenshot
    (3) Compare the number of main function code lines in the assembly file generated by -O0 and -O2,The number of lines is written on the screenshot.

#include<stdio.h>
int main()
{
    
    
	int i, sum = 0;
	for( i = 1; i < 10; i++)
	{
    
    
		   sum += i;
	}
	printf(“sum=%d”,sum);
	return 0;
}

(1)
(2)

  1. Download " 2100130499.exe " in the attachment . Install and use the ultraEdit software, modify the file forcibly, change the printed "2100130499" to "your own student number", and take a screenshot of the modified part of the ultraEdit software (framed in a red frame), as well as the previous modification and modification in DOS Screenshots of the last 2 runs.

    Attachment: 2100130499.exe
    Note: Search for 20130499 directly, as shown in the figure below, and then click the string on the right to change it to your student number
    look up

  2. (Experiment 3 content - interested students should do it in advance) Download "2100130499VIP.exe" in the attachment. Install and use the ultraEdit software, forcibly modify the if...else branch statement in the file, change "2100130499 ordinary member" to "your own student number VIP", and take a screenshot of the modified part of the ultraEdit software (framed in red), And the running screenshots of the first modification and the second modification in DOS.

Please refer to Experiment 3 of Principles of Computer Composition - Modifying the program of the binary file to change the final running result The second question

Guess you like

Origin blog.csdn.net/qq_46373141/article/details/130758915