Binary & Int representations | Bitwise Operations Flashcards
voltage for binary numbers
0: 0V
1: 3.3V
How many bit patters can an n-bit register hold?
2^n bit patters
Range of unsigned integers and how are they encoded?
Range: 0 to (2^n)-1
Encoded using binary numbers
Range of signed integers and how are they encoded?
Range: -(2^n-1) to (2^n-1)-1
Encoded using two’s complement
How is a number negated?
- Take one’s complement (flip bits)
- Add 1 to the result
How to distinguish a +/- signed int?
The leftmost bit is the signed bit. 0 = + and 1 = -
Do we use sign-magnitude and one’s complement of signed integers?
No, they are awkward to handle in hardware, they have +0 and -0. Rarely used today.
What are hex numbers commonly used for?
Shorthands for denoting bit patterns
What data model does Linux on ARMv8 in AArch 64 use?
LP64 data model
Long ints and
Pointers are
64 bits long
What are the 5 A64 keywords, their sizes in bits and corresponding C keyword?
- Byte, 8 bits, char
- Halfword, 16 bits, short int
- Word, 32 bits, int
- Doubleword, 64 bits, long int / void
- Quadword, 128, N/A
How to define an unsigned integer in C?
unsigned int x;
or for char
unsigned char x;
What do bitwise logical instructions do?
Manipulate 1 or more bits in a register
what’s it called when these two are anded together and the result is all 0’s
1010
0000
———
0000
A bitmask “masks out” these bits
Check if bit 3 is set in x20
uses ands, check notes
set bits 4&5 in x20
uses orr, check notes
orr doesn’t need an s
What does bit clear mean and what is its opcode?
AND NOT, bic
Clear bits 2-5 in x20
use bic (bitclear), check notes
Opcode for exclusive or
eor
Opcode for OR NOT
orn
NOT opcode and what is it an alias for?
mvn xd, xm
(move not)
Alias for: orn xd, xzr, xm
Exclusive or not opcode
eon
Explain rotate right and what is its opcode?
Bits shifted out the right are inserted on the left.
ror
Explain Signed Extend Byte and what is its opcode?
Sign-extends bit 7 to bits 8-31
stxb
What are all the sign-extend operations, what do they do and what registers do they use?
- Signed Extend Byte: extends bits 8-31, uses w
- Signed Extend Halfword: extends bits 15 to bits 16-31, uses w
- Signed Extend Word: extends bits 31 to bits 32-64, uses x