armv7 Cortex-M3 B指令机器码生成函数

void B_instruction_make()
{
    unsigned int input_hex_num,imm32,imm10,imm11,current_PC, dsc_PC;
unsigned int out_instruction1,out_instruction2;
int temp_hex_num;
    unsigned char I1,I2,J1,J2,S;
    printf( "Please input a hex current_PC:\r\n" );               
    scanf( "%x", &current_PC );
    printf( "current_PC = %x\r\n", current_PC );


printf( "Please input a hex dsc_PC:\r\n" );               
    scanf( "%x", &dsc_PC );
    printf( "dsc_PC = %x\r\n", dsc_PC );


    temp_hex_num = dsc_PC - current_PC;
printf( "temp_hex_num = %x\r\n", temp_hex_num );


if( temp_hex_num < 0 ){
        S = 1;
J1 = 1;
J2 = 1;
}else{
        S=0;
J1 = 0;
J2 = 0;
}
    printf( "temp_hex_num = %d\r\n", temp_hex_num );







    //input_hex_num = temp_hex_num & 0x1fffff;
    //printf( "input_hex_num = %x\r\n", input_hex_num );


    //input_hex_num = 0x200000 - input_hex_num;
//printf( "input_hex_num = %x\r\n", input_hex_num );


temp_hex_num = temp_hex_num - 4;

input_hex_num = temp_hex_num >> 1;


printf( "input_hex_num = %x\r\n", input_hex_num );
    imm10 = (input_hex_num >> 11) & 0x3ff;
imm11 = input_hex_num & 0x7ff;






out_instruction1 = 0x00;
out_instruction1 = out_instruction1 | (0x1e<<11);
out_instruction1 = out_instruction1 | (S<<10);
out_instruction1 = out_instruction1 | imm10;
    printf( "out_instruction1 = %x\r\n", out_instruction1 );
                     
out_instruction2 = 0x00;
    out_instruction2 = out_instruction2 | (0x2<<14);
printf( "out_instruction2 = %x\r\n", out_instruction2 );




printf( "J1 = %x\r\n", J1 );
    out_instruction2 = out_instruction2 | (J1<<13);
printf( "out_instruction1 = %x\r\n", out_instruction1 );
out_instruction2 = out_instruction2 | (0x1<<12);
out_instruction2 = out_instruction2 | (J2<<11);
out_instruction2 = out_instruction2 | imm11;
printf( "out_instruction2 = %x\r\n", out_instruction2 );




printf( "imm10 = %x\r\n", imm10 );
printf( "imm11 = %x\r\n", imm11 );










//imm11 = input_hex_num



}
//2000c264
//2000a710
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值