hexadecimal calculation

0xc0 00 00 00~0xc0 7f ff ff

共8M空间


即0xc0 80 00 00大小

8*16^5=8*(2^4)^5=8*2^20=8MB


0x0000 0000~0x1fff ffff

共512M空间

即0x2000 0000大小

2*(16)^7=2*(2^4)^7=2*(2^28)=2^29=2^9*2^20=512*2^20=512M


0xa000 0000~0xbfff ffff

共512M空间

因0xbfff ffff-0xa000 0000=0x1fff ffff

0x1fff ffff+1=0x2000 0000

其余,同上


0xc000 0000~0xffff ffff

共1G空间

0xffff ffff-0xc000 0000=0x3fff ffff

0x3fff ffff+1=0x4000 0000=4*(16)^7=2^2*((2^4)^7)=2^2*2^28=2^30=1G


2^10=1KB

2^20=1MB

2^30=1GB


1Gb=128MB

#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include “aip_common.h” #include <string.h> #include <stdlib.h> #define ZERO (0) #define MAX_LINE_LENGTH (256) #define ADD_VALUE (0xF) #define FALSE (0) #define WRONG (1) #define SUCCESS (1) #define TRUE (1) #define STORESIZE (9) #define ENDOFSTRING (8) #define FOUR (4) /* / / Display Application : Main Processing Task / / ---------------------------------------------------------------------------------------------------------------------------------/ / Function: main / / Description: This function processes DA_510B_IMG_1.mhx file to extract address values, applies offset calculation, / / and generates WRITE_ADDRESS.TXT output file with formatted address pairs. / / Arguments: void / / Return: U4 - Process execution status (ZERO for success, WRONG for failure) / /=/ U4 main(void) { U4 u4_t_search_target; FILE stp_t_creatfile_da_510b_img_1; FILE* stp_t_creatfile_write_address; U1 u1_t_p_test_line[MAX_LINE_LENGTH]; size_t u4_t_test_len; U1* u1p_t_s315_pos; U1* u1p_t_addr_start; U1 u1_t_p_test_new_hex_addr[STORESIZE]; U4 u4_t_test_address; U4 u4_t_test_new_address; S4 s4_tp_store_string[STORESIZE] = { ZERO }; U4 u4_t_return_value = ZERO; /* Unified return status variable */ u4_t_search_target =(U4) FALSE; stp_t_creatfile_da_510b_img_1 = NULL; stp_t_creatfile_write_address = NULL; u1p_t_s315_pos = NULL; u1p_t_addr_start = NULL; u4_t_test_address = (U4)ZERO; u4_t_test_new_address = (U4)ZERO; /* Open input file for reading / stp_t_creatfile_da_510b_img_1 = fopen(“DA_510B_IMG_1.mhx”, “rb”); / Handle input file open failure / if (NULL == stp_t_creatfile_da_510b_img_1) { printf(“Input file open failed\n”); u4_t_return_value = (U4)WRONG; } else { / Create output file for writing / stp_t_creatfile_write_address = fopen(“WRITE_ADDRESS.TXT”, “w”); / Handle output file creation failure / if (NULL == stp_t_creatfile_write_address) { printf(“Output file creation failed\n”); fclose(stp_t_creatfile_da_510b_img_1); u4_t_return_value = (U4)WRONG; } else { printf(“Input file opened successfully\n”); / Process each line in input file / while (fgets(u1_t_p_test_line, (U4)MAX_LINE_LENGTH, stp_t_creatfile_da_510b_img_1) != NULL) { / Remove newline character from line end / u4_t_test_len = strlen(u1_t_p_test_line); if (u4_t_test_len > 0 && u1_t_p_test_line[u4_t_test_len - 1] == ‘\n’) { u1_t_p_test_line[u4_t_test_len - 1] = ‘\0’; } / Search for “S315” marker in current line / u1p_t_s315_pos = strstr(u1_t_p_test_line, “S315”); / Process line containing target marker / if (u1p_t_s315_pos != NULL) { printf(“Target line found: %s\n”, u1_t_p_test_line); u1p_t_addr_start = u1p_t_s315_pos + (U4)FOUR; / Verify sufficient characters after marker / if (strlen(u1p_t_addr_start) >= (U4)ENDOFSTRING) { / Extract and store address string / strncpy(s4_tp_store_string, u1p_t_addr_start, (U4)ENDOFSTRING); s4_tp_store_string[(U4)ENDOFSTRING] = ‘\0’; printf(“Raw hexadecimal address: %p\n”, s4_tp_store_string); / Convert hex string to numeric value / u4_t_test_address = strtoul(s4_tp_store_string, NULL, 16); / Apply address offset calculation / u4_t_test_new_address = u4_t_test_address + ADD_VALUE; / Format new address as 8-digit hex string / snprintf(u1_t_p_test_new_hex_addr, sizeof(u1_t_p_test_new_hex_addr), “%08lX”, u4_t_test_new_address); printf(“Address after adding 16: 0x%s\n”, u1_t_p_test_new_hex_addr); / Write formatted address pair to output file / fprintf(stp_t_creatfile_write_address, “0x40000000,0x%s\n”, u1_t_p_test_new_hex_addr); fprintf(stp_t_creatfile_write_address, “0x43FFFFF0,0x43FFFFFF\n”); printf(“File written successfully: WRITE_ADDRESS.TXT\n”); u4_t_search_target = (U4)SUCCESS; } else { printf(“Error: Characters after S315 less than 8\n”); } break; } } / Handle case where target marker was not found / if (!u4_t_search_target) { printf(“line S315 not found\n”); / Write default address format to output file / fprintf(stp_t_creatfile_write_address, “0x40000000,0x00000000\n”); fprintf(stp_t_creatfile_write_address, “0x43FFFFF0,0x43FFFFFF\n”); printf(“Default format written to file\n”); } / Close output file handle / fclose(stp_t_creatfile_write_address); } / Close input file handle */ fclose(stp_t_creatfile_da_510b_img_1); } system(“pause”); return u4_t_return_value; }帮我把main函数里面函数功能封装到不同函数中,按照我的编码习惯
最新发布
07-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值