1 2 3 4 5 6 7 8 9 a b c d e f 0xfe00 = 1111 1110 0000 0000 (1 << 9) = 0000 0001 0000 0000 1111 1110 0000 0000 + 0000 0001 0000 0000 = 0000 0000 0000 0000
0x1a23 = 0001 1010 0010 0011 0x9210 = 1001 0010 0001 0000
0001 1010 0010 0011 1001 0010 0001 0000 1001 1010 0011 0011
int16_t X;
= -32767;
X = X 0 2; X
1111 1111 1111 1111 2^15 = 32768 x = -32768 x = +32767 Signed integer overflow, wraps around to the highest opposite signed number.
24 bits
This register is used to configure the mode of the pins in port A. Each pin can be configured as input, output, analogue, or alternate functions. #### GPIOA->ODR This register is used to set the output state of the pins #### GPIOA->IDR This register is used to read the input state of the pins
->ODR |= (1 << 2) GPIOA
while(GPIOA->IDR & (1 << 4))
SP = SP - 4 = 0x20000ff8 0x20000ff8 = 0x0000007
R0 = 0x0000007 SP = SP + 4 = 0x0000ffc
R2 = 0x0000005 SP = SP + 4 0X00000ffc 0X00001000
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | a | b | c | d | e | f |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
We will convert the hex into binary, understand what (1<<9) is, and then perform and AND comparison between the two values. Then convert back to hex
a 1. 0x1a23 1. Convert hex to binary 1. 1 = 1 = 0001 2. a = 10 = 1010 3. 2 = 2 = 0010 4. 3 = 3 = 0011 5. Combined = 0001 1010 0010 0011
1. (0x9210)
1. Convert hex to binary
1. 9 = 9 = 1001
2. 2 = 2 = 0010
3. 1 = 1 = 0001
4. 0 = 0 = 0000
5. Combined = 1001 0010 0001 0000
1. |
1. Now we do a #bitwise OR comparison between the two 16bit values
1. 0001 1010 0010 0011
OR 1001 0010 0001 0000
= 1001 1010 0011 0011
1. Convert back to hex
1. 1001 = 9 = 9
2. 1010 = 10 = a
3. 0011 = 3 = 3
4. 0011 = 3 = 3
5. ANS = 0x9a33
int16_t X; // X is a signed 16 bit num
= -32767
X = X - 2 X
1111 1111 1111 1111 >1111 = 1+2+4+8 = 15 >1111 = 16+32+64+128 = 240 >1111 = 256+512+1024+2048 = 3840 >1111 = 4096+8192+16384+MSB= 28672 >15+240+3840+28672 = 32767
What is MSB: MSB is the most significant bit, this defines whether a number is negative or positive. If its 1, then the number is negative, if its 0, its a positive.
so a 16bit signed number has a range of -32768 to +32767 Why can negative hold one more? There is only +0, there is no -0
So now, we know that -32768 is the maximum negative number that a 16bit signed int can hold, so if we add -2 to it, step by step; 1. -32767 - 1 = -32768 (MAX -) 2. -32768 - 1 = +32757 (MAX +)
Because we tried to -1 from an already max number, we got a **Signed Integer Overflow
GPIOA -> MODER This register is used to configure the mode of the pins in port A. each pin can be configured as Input, Output, Analog, or Alternate functions
GPIOA -> ODR This register is used to set or reset the output state of the pins.
GPIOA -> IDR This register is used to read the input state of the pins.
->ODR |= (1 << 2) GOIOA
while(GPIOA->IDR & (1 << 4))
{
// WAIT
}
“Memory locations that are also connected to the real world” They are a bit like memory locations, but memory locations can hold values bigger than 1 bit while GPIO ports hold states, 1 bit, 1 or 0.
GPIOA->IDR