左移一次并从进位中获取值

发布于 2024-11-07 11:28:48 字数 1546 浏览 0 评论 0原文

我正在使用带有 C 编译器的 microchip v8.63 版本。

下面的代码,我想“将值 1206420333240d 移动一次”,我知道 1 位进入进位寄存器。但我不知道如何用 pic18F4550 的汇编语言检索该值。 我的问题是,如何使用 pic 18F4550 的汇编器进行一次移位并从进位中获取值?

包括整个项目。

unsigned int rood = 1206420333240;


void main (void)
{   
    //int rood[] = {0,0,1,0,1,0,1,0,1,0,1,1,1,0,0,0,0,1,1,0,1,0,1,0,1,0,0,0,1,1,0,1,1,1,0,1,0,1,0,1,0,0,0,1,1};

    TRISD = 0x00;               // PORTD  als output
    TRISB = 0b00110000;         // RB4 en RB5 als input
    TRISA = 0x00;               // RA output

    RCONbits.IPEN = 0;          // prioriteit disable
    INTCONbits.GIE = 1;         // enable interrupt
    INTCONbits.RBIE = 1;        // interrupt portB on

    while(1)
    {   
        _asm sleep _endasm  
    }
}

#pragma interrupt ISR
void ISR (void)
{


    if (INTCONbits.RBIF==1)
    {
        if(PORTBbits.RB5==0)        // S3 pressed ?
        {
            int i = 0;
            int b;
            do {
                // Try to shift left (SHF) and get value in carry.
                _asm
                    mov  EAX, 1206420333240d
                _endasm
                //LATAbits.LATA2 = rood << 1;
                //LATDbits.LATD1 ^= 1;

                //do-while for the frequentie (1500 is de freq)
                b = 0;
                do {
                    b++;
                }while(b <= 2000);

                i++;
            }while(sizeof(rood) <= 50);

            //LATDbits.LATD1 ^= 1;      // D2 togglen

        }

    }   
    INTCONbits.RBIF = 0;
}

I'm using microchip version v8.63 with C compiler.

The following piece of code, I want to 'shift once the value 1206420333240d', I know that the 1 bit comes in the carry register. But I don't know how to retrieve this values in assembly language for the pic18F4550.
My question is, how can I shift once with assembler for the pic 18F4550 and get the value from the carry?

In included the whole project.

unsigned int rood = 1206420333240;


void main (void)
{   
    //int rood[] = {0,0,1,0,1,0,1,0,1,0,1,1,1,0,0,0,0,1,1,0,1,0,1,0,1,0,0,0,1,1,0,1,1,1,0,1,0,1,0,1,0,0,0,1,1};

    TRISD = 0x00;               // PORTD  als output
    TRISB = 0b00110000;         // RB4 en RB5 als input
    TRISA = 0x00;               // RA output

    RCONbits.IPEN = 0;          // prioriteit disable
    INTCONbits.GIE = 1;         // enable interrupt
    INTCONbits.RBIE = 1;        // interrupt portB on

    while(1)
    {   
        _asm sleep _endasm  
    }
}

#pragma interrupt ISR
void ISR (void)
{


    if (INTCONbits.RBIF==1)
    {
        if(PORTBbits.RB5==0)        // S3 pressed ?
        {
            int i = 0;
            int b;
            do {
                // Try to shift left (SHF) and get value in carry.
                _asm
                    mov  EAX, 1206420333240d
                _endasm
                //LATAbits.LATA2 = rood << 1;
                //LATDbits.LATD1 ^= 1;

                //do-while for the frequentie (1500 is de freq)
                b = 0;
                do {
                    b++;
                }while(b <= 2000);

                i++;
            }while(sizeof(rood) <= 50);

            //LATDbits.LATD1 ^= 1;      // D2 togglen

        }

    }   
    INTCONbits.RBIF = 0;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

山川志 2024-11-14 11:28:48

如果使用 PIC 18 组件,则有一个命令可以旋转左值并将进位位存储在指定寄存器中。

RLCF REG, 0, 0

(请参阅上述链接文档中的第 243 页)。注意:您必须询问进位寄存器以检索值,并可能将最低有效位设置为“0”以抵消旋转操作并将其转换为移位操作。

您可以诉诸内联汇编来执行此操作,但是,我想知道为什么以下内容不起作用:

int carry = (value & 0X80) >> 7; // substitute the correct bit masks here
value = value << 1;

if( carry == 1 )
{
    // Perform action
}

If using PIC 18 assembly then there is a single command that will rotate a value left and store the carry bit in a nominated register.

RLCF REG, 0, 0

(see page 243 in the above linked document). NB: you would have to interrogate the carry register to retrieve the value and potentially set the least significant bit to '0' to counteract the rotation operation and turn it into a shift operation.

You could resort to inline assembly to perform this, however, I am wondering why the following wouldn't work:

int carry = (value & 0X80) >> 7; // substitute the correct bit masks here
value = value << 1;

if( carry == 1 )
{
    // Perform action
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文