简体   繁体   English

为什么进位位永远不是1? 我查看了程序 memory 并且从来没有 1,只有 0

[英]Why carry bit is not 1 never? I looked in the program memory and never 1, just 0

I am writing a C program to generate Fibonacci numbers until 255 (as 8-bit values) using pic16f887.我正在编写一个 C 程序来使用 pic16f887 生成斐波那契数直到 255(作为 8 位值)。 I try to check the carry bit from STATUS which is bit 0 (LSB) (I checked the datasheet), but all the time is 0.我尝试从 STATUS 检查进位位,即位 0 (LSB)(我检查了数据表),但始终为 0。

#include <htc.h> 
#define N 20 
unsigned char i@0x20; 
unsigned char v[N]@0x30; 

void main(void)
{
    v[0] = 0;
    v[1] = 1;
    i = 2;
    while(1)    
    {
        v[i] = v[i-1] + v[i-2];

        if(STATUS &0b00000001) 
            goto end;
        i++;
    }
end:
    asm("NOP");
}

在此处输入图像描述

There's no ordering between the (presumably volatile) register read and the arithmetic and load/stores in the loop. (可能是易失性的)寄存器读取与循环中的算术和加载/存储之间没有顺序。 You can't "read the carry flag" from C because there is no way of positioning the flag read relative to the underlying arithmetic operations, even if you assume a machine that has a carry flag.您无法从 C 中“读取进位标志”,因为无法相对于基础算术运算定位读取的标志,即使您假设机器具有进位标志。 Instead you need to write the explicit logic for carry and hope the compiler can recognize it and make use of the carry flag if that's the most efficient way to do it.相反,您需要为进位编写显式逻辑,并希望编译器能够识别它并使用进位标志,如果这是最有效的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM