Non-Volatile Register

原文链接:https://www.techopedia.com/definition/8591/non-volatile-register

What Does Non-Volatile Register Mean?

A non-volatile register is a type of register witth contents that must be preserved over subroutine calls. Whenever the value of a nonvolatile register is changed by the routine, the old value has to be saved on the stack prior to changing the register and that value has to be restored before returning. A register is similar to a variable, except that there is a fixed number of registers. Every register is a unique location in the CPU in which a single value is saved. A register is the one and only place where mathematical functions, such as addition, multiplication, subtraction, etc., can be carried out. Registers often hold pointers that refer to the memory. Moving values between memory and registers is a common phenomenon.

Techopedia Explains Non-Volatile Register

The following are a few examples of non-volatile registers:

  • ebx: A non-volatile register used for general purposes. It is usually set to a common value all through a function to accelerate the calculations.
  • esi: A non-volatile register used for general purposes. It is commonly used as a pointer, especially for “rep-” class instructions that require a source and destination for data. Here, the esi points to the source. An esi generally holds data that is used all through a function as it is not prone to changes.
  • edi: Another non-volatile register used for general purposes. This is commonly used as a pointer. An edi is identical to an esi, with the exception that it usually points to the destination.
  • ebp: Another non-volatile register that is used as a general purpose register. It has two distinctive uses based on the compile settings. It is either a general purpose register or a frame pointer. If the compilation has not been optimized or if the code is hand written, ebp monitors the location of the stack when a function begins. Since the stack is changed all through a function, when ebp is set at the original value, the variables saved on the stack are allowed to be referenced easily. If compilation has been optimized, ebp will be used as a general purpose register to store any type of data, while the calculations for the stack pointer are carried out depending on its movement.

Volatile Register

In other words volatile registers are caller saved registers, as opposed to callee saved. See https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention?view=vs-2019#callercallee-saved-registers

Volatile keyword in C/C++

volatile means that the value of the variable can be changed by something which is not visible for the compiler. That means that the variable has to have a valid memory representation, it has to be read before any use, and stored if changed.

volatile keyword should be used always when modification of variable can be asynchronous such as registers in CPU.

Example would be that you are using microcontroller and you are waiting flag when button is pressed. Then you are reading register like this:

uint8_t* reg = 0x12345678; //Register address
while (*reg & 0x02) { //Read register until 0 = button pressed

}

This can easily fail since compiler will check it once and later will ignore value and you may end in infinite loop or you don’t even get anything since CPU can cache value of reg because it assumes noone can modify value where it points to.

If you do this:

volatile uint8_t* reg = 0x12345678; //Register address
while (*reg & 0x02) { //Read register until 0 = button pressed

}

You force compiler to do read instruction from actual memory before it uses content of variable. There is no cache in this case.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
图像识别技术在病虫害检测中的应用是一个快速发展的领域,它结合了计算机视觉和机器学习算法来自动识别和分类植物上的病虫害。以下是这一技术的一些关键步骤和组成部分: 1. **数据收集**:首先需要收集大量的植物图像数据,这些数据包括健康植物的图像以及受不同病虫害影响的植物图像。 2. **图像预处理**:对收集到的图像进行处理,以提高后续分析的准确性。这可能包括调整亮度、对比度、去噪、裁剪、缩放等。 3. **特征提取**:从图像中提取有助于识别病虫害的特征。这些特征可能包括颜色、纹理、形状、边缘等。 4. **模型训练**:使用机器学习算法(如支持向量机、随机森林、卷积神经网络等)来训练模型。训练过程中,算法会学习如何根据提取的特征来识别不同的病虫害。 5. **模型验证和测试**:在独立的测试集上验证模型的性能,以确保其准确性和泛化能力。 6. **部署和应用**:将训练好的模型部署到实际的病虫害检测系统中,可以是移动应用、网页服务或集成到智能农业设备中。 7. **实时监测**:在实际应用中,系统可以实时接收植物图像,并快速给出病虫害的检测结果。 8. **持续学习**:随着时间的推移,系统可以不断学习新的病虫害样本,以提高其识别能力。 9. **用户界面**:为了方便用户使用,通常会有一个用户友好的界面,显示检测结果,并提供进一步的指导或建议。 这项技术的优势在于它可以快速、准确地识别出病虫害,甚至在早期阶段就能发现问题,从而及时采取措施。此外,它还可以减少对化学农药的依赖,支持可持续农业发展。随着技术的不断进步,图像识别在病虫害检测中的应用将越来越广泛。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值