Today the teacher assigned homework, one of which is to judge the immediate number. As we all know, not all immediate numbers in ARM are legal.
Description: If the immediate value is denoted as
Example: Valid immediate numbers 0x0000F200, 0x00110000, 0x00012800
Invalid immediate numbers 0x1010, 0x00102, 0xFF1000
Obviously, all 8-bit immediate numbers are valid.
In fact, judging whether a number is an immediate number is also very simple from the definition:
1. Check if all bits that are 1 are in one byte
2. If condition 1 is met, see if it can be obtained by shifting left by an even number of bits
Anything that meets these two conditions is a legal immediate number, but I still wrote a small program to make the judgment. It seems that I am still so lazy, hehe.
#include
/****************************************************** *************
Description: Circular left shift function
Input: val, the immediate value to be judged
n, the number of bits to shift left (0--15)
Return: the immediate value after circular left shift n bits
*************************************************** **********/
unsigned int left(unsigned int val, int n)
{
if (n < 0 || n > 15)
{
return 0xffffffff;
}
unsigned int rtn;
rtn = val << (2 * n);
rtn |= (val & (0xffffffff << (32 - 2 * n))) >> (32 - 2 * n);
return rtn;
}
/****************************************************** *************
Description: Determine whether the immediate value is valid
Input: val, the immediate value to be judged
Return: true, the immediate value is valid
false, the immediate value is invalid
*************************************************** **********/
int Judge(unsigned int val)
{
int i = 0;
for (i = 0; i < 16; i++)
{
if(left(val, i) <= 0x000000ff )
return 1;
}
return 0;
}
int main(void)
{
int num = 0;
while(printf("Please input:"), 1 == scanf("%x", &num))
{
if(Judge(num))
{
printf("It is a legal immediate number!/n");
}
else
{
printf("Illegal immediate value!/n");
}
}
return 0;
}
Previous article:STM32 system structure, clock tree
Next article:The difference between arm 2440 and 6410
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- Let’s talk about the “Three Musketeers” of radar in autonomous driving
- Why software-defined vehicles transform cars from tools into living spaces
- 【ST NUCLEO-G071RB Review】GPIO
- Basic knowledge of base station antennas and network applications
- Photos + Our product board
- To save hundreds of thousands of dollars, a PhD student made a DIY super microscope and saw atoms directly!
- When importing AD to gerber files into CopperCam, the imported circuit diagram is wrong.
- [ESP32-Audio-Kit Audio Development Board Review] WS2812 Color Light Strip Control
- 【i.MX6ULL】Driver Development 5——Device Tree Principle and Lighting LED
- Calculation of wireless communication distance
- 【TI recommended course】#What is I2C design tool? #
- [Xianji HPM6750 Review] Testing CAN Transceiver