我正在使用带有C编译器的微芯片版本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;
}
答案 0 :(得分:2)
如果使用PIC 18 assembly,则只有一个命令可以旋转一个值并将进位位存储在指定的寄存器中。
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
}