为什么引导程序boot.S中会有org 0x7c00

在一些书籍中,编写一个简单的引导程序,加上org 0x7c00,是因为这些程序最终的效果是为了显示字符,所以需要制定内存段基址。
而实际的一些操作系统的程序中并不需要指定,是因为最终的效果不是显示字符,所以不需要。

参考:
https://blog.csdn.net/judyge/article/details/52333656
http://www.voidcn.com/article/p-dhvjzeqo-ey.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是实现上述功能的代码示例(假设使用的是AVR单片机): ```c #include <avr/io.h> #include <avr/pgmspace.h> void write_flash(uint16_t address, uint8_t *data, uint16_t length) { uint16_t i; // 禁止中断 cli(); // 等待 Flash 写操作完成 while (SPMCSR & (1 << SPMEN)); // 擦除 Flash 存储单元 boot_page_erase(address); boot_spm_busy_wait(); // 写入数据到 Flash 存储单元 for (i = 0; i < length; i += 2) { uint16_t tmp = (data[i+1] << 8) | data[i]; boot_page_fill(address + i, tmp); } boot_page_write(address); boot_spm_busy_wait(); // 打开 RWW 模式 boot_rww_enable(); // 恢复中断 sei(); } void copy_memory(uint8_t *src, uint8_t *dst, uint16_t length) { for (uint16_t i = 0; i < length; i++) { dst[i] = src[i]; } } int main(void) { uint8_t flash_data[16] PROGMEM = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x7}; uint8_t sram_data[16]; // 将 Flash 中的数据块依次赋值给 SRAM 内存块的相应内存单元中 for (uint16_t i = 0; i < 16; i++) { sram_data[i] = pgm_read_byte(&flash_data[i]); } // 将 SRAM 内存中起始地址为$0230 的 16 个字节的数据块整体复制到起始地址为$0320 的内存块中 copy_memory(sram_data, (uint8_t*)0x0230, 16); copy_memory((uint8_t*)0x0230, (uint8_t*)0x0320, 16); while(1) { // do something } } ``` 上面的代码实现了将数据存储到Flash中、从Flash中读取数据到SRAM中、从SRAM中复制数据到另一个SRAM地址中。需要注意的是,AVR单片机中的Flash存储单元大小为半字(即16位),因此在存储时需要将每两个字节合并成一个半字。同时,读取Flash中的数据需要使用`pgm_read_byte`函数,防止出现地址错误的问题。在使用`boot_page_erase`、`boot_page_fill`和`boot_page_write`函数进行Flash操作时,需要先禁止中断,并在操作完成后恢复中断。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值