#include <reg52.h> #include <intrins.h> void delay(unsigned int ms) { unsigned int i, j; for (i = ms; i > 0; i--) for (j = 114; j > 0; j--); } void main() { unsigned int int_a = 0x12345678; unsigned int int_b = 0x87654321; float float_a = 0.12345678; float float_b = 0.87654321; unsigned int start_time = 0; unsigned int end_time = 0; // 整数加法运算 start_time = millis(); unsigned int int_result = int_a + int_b; end_time = millis(); printf("Integer addition: %d\n", int_result); printf("Execution time: %d ms\n", end_time - start_time); delay(1000); // 整数减法运算 start_time = millis(); unsigned int int_result_sub = int_a - int_b; end_time = millis(); printf("Integer subtraction: %d\n", int_result_sub); printf("Execution time: %d ms\n", end_time - start_time); delay(1000); // 整数乘法运算 start_time = millis(); unsigned int int_result_mul = int_a * int_b; end_time = millis(); printf("Integer multiplication: %d\n", int_result_mul); printf("Execution time: %d ms\n", end_time - start_time); delay(1000); // 整数除法运算 start_time = millis(); unsigned int int_result_div = int_a / int_b; end_time = millis(); printf("Integer division: %d\n", int_result_div); printf("Execution time: %d ms\n", end_time - start_time); delay(1000); // 浮点加法运算 start_time = millis(); float float_result = float_a + float_b; end_time = millis(); printf("Float addition: %f\n", float_result); printf("Execution time: %d ms\n", end_time - start_time); delay(1000); // 浮点减法运算 start_time = millis(); float float_result_sub = float_a - float_b; end_time = millis(); printf("Float subtraction: %f\n", float_result_sub); printf("Execution time: %d ms\n", end_time - start_time); delay(1000); // 浮点乘法运算 start_time = millis(); float float_result_mul = float_a * float_b; end_time = millis(); printf("Float multiplication: %f\n", float_result_mul); printf("Execution time: %d ms\n", end_time - start_time); delay(1000); // 浮点除法运算 start_time = millis(); float float_result_div = float_a / float_b; end_ |