Binary & Int representations | Bitwise Operations Flashcards

1
Q

voltage for binary numbers

A

0: 0V
1: 3.3V

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How many bit patters can an n-bit register hold?

A

2^n bit patters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Range of unsigned integers and how are they encoded?

A

Range: 0 to (2^n)-1
Encoded using binary numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Range of signed integers and how are they encoded?

A

Range: -(2^n-1) to (2^n-1)-1
Encoded using two’s complement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How is a number negated?

A
  1. Take one’s complement (flip bits)
  2. Add 1 to the result
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to distinguish a +/- signed int?

A

The leftmost bit is the signed bit. 0 = + and 1 = -

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Do we use sign-magnitude and one’s complement of signed integers?

A

No, they are awkward to handle in hardware, they have +0 and -0. Rarely used today.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are hex numbers commonly used for?

A

Shorthands for denoting bit patterns

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What data model does Linux on ARMv8 in AArch 64 use?

A

LP64 data model
Long ints and
Pointers are
64 bits long

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the 5 A64 keywords, their sizes in bits and corresponding C keyword?

A
  1. Byte, 8 bits, char
  2. Halfword, 16 bits, short int
  3. Word, 32 bits, int
  4. Doubleword, 64 bits, long int / void
  5. Quadword, 128, N/A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to define an unsigned integer in C?

A

unsigned int x;
or for char
unsigned char x;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What do bitwise logical instructions do?

A

Manipulate 1 or more bits in a register

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what’s it called when these two are anded together and the result is all 0’s
1010
0000
———
0000

A

A bitmask “masks out” these bits

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Check if bit 3 is set in x20

A

uses ands, check notes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

set bits 4&5 in x20

A

uses orr, check notes
orr doesn’t need an s

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does bit clear mean and what is its opcode?

A

AND NOT, bic

17
Q

Clear bits 2-5 in x20

A

use bic (bitclear), check notes

18
Q

Opcode for exclusive or

A

eor

19
Q

Opcode for OR NOT

A

orn

20
Q

NOT opcode and what is it an alias for?

A

mvn xd, xm
(move not)
Alias for: orn xd, xzr, xm

21
Q

Exclusive or not opcode

A

eon

22
Q

Explain rotate right and what is its opcode?

A

Bits shifted out the right are inserted on the left.
ror

23
Q

Explain Signed Extend Byte and what is its opcode?

A

Sign-extends bit 7 to bits 8-31
stxb

24
Q

What are all the sign-extend operations, what do they do and what registers do they use?

A
  1. Signed Extend Byte: extends bits 8-31, uses w
  2. Signed Extend Halfword: extends bits 15 to bits 16-31, uses w
  3. Signed Extend Word: extends bits 31 to bits 32-64, uses x
25
Q

What are the unsigned extend operations?

A
  1. Unsigned extend byte: uxtb, take something that’s 8 bits wide, extend it to 32
  2. Unsigned extend halfword: uxth, takes something that’s 16 bits wide and extend to 32
  3. Unsigned extend word: uxtw, takes something that’s 32 bits wide, extends it to 64
26
Q

What does modulus arithmetic do?

A
  • Constrains numbers to the range 0 to M-1 where M is the modulus. - CPUs normally do modulus arithmetic.
  • If n is the size in bits, M=2^n
  • Carry out is ignored
27
Q

On a 4-bit CPU, what does 9+8 give?

A

(9+8) mod 16 = 1

28
Q

What can adds or subs be used for and what new flag gets set compared to ands?

A

Can be used for extended precision arithmetic and carry flag is set.

29
Q

Full adder circuit diagram

A

Check notes

30
Q

How are multi-bit numbers summed in hardware?

A

Using multiple full adder circuits (1 for each bit). See diagram in notes

31
Q

How is subtraction done in the ALU?

A

Negating the subtrahend and then adding. In 7-5, 5 is the subtrahend. The carry out is also ignored here.

32
Q

Subtract 7-5 in binary

A

2 but check notes on how it’s done

33
Q

What flags for signed branch instructions use?

A

N,Z,V

34
Q

How does the V flag work for subtraction? Also how to subtract -8 - 5?

A

V=true if xd=0, xn=1, xm=1 or xd=1, xn=0, xm=0
For -8-5, negate both binary representations of 8 and 5. Add.

35
Q

Difference between unsigned and signed arithmetic

A

Both use the same registers and hardware, but in unsigned, one interprets the data as unsigned numbers. A carry out indicates an overflow

36
Q

Chart for unsigned branching conditions

A

We use C instead of V
- eq, equal, ==, Z=1
- ne, not equal, !=, Z=0
- hi, higher than, >, Z==0 && C==1
- hs, higher than or same, >=, C==1
- lo, lower than, <, C==0
- ls, lower than or same, <=, !(Z==0 && C==1)

37
Q

What does an if statement use for branching conditions?

A

Logical complement

38
Q

How is binary multiplication done?

A
  • Repeated for every bit in the source register, each step consists of 2 sub-steps:
    1. a conditional addition
    2. an asr
  • If the original multiplier is negative, an extra step is needed: subtract the multiplicand from the high-order part of the result (from the product register)
39
Q

Where is the product of binary multiplication put?

A

In 2 concatenated registers