131 Week 13 - Arithmetic Operations Flashcards

1
Q

Move instruction

A

Used to copy data between registers, or set an immediate to a register.
Syntax:
mov destinationRegister, sourceRegister
E.g.,
mov r1, r2 (9Copy value of r2 into r1)
or
mov r1, #77 (set r1 to the value 77)

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

Adding instruction

A

Used to add the contents of 2 registers together. It assumes that its operands are encoded using two’s complement.
Syntax:
add destinationRegister, sourceRegister1, sourceRegister2
E.g.,
add r1, r1, r2 (add r1 and r2 and store the result in r1)

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

Subtracting instruction

A

Used to subtract the contents of one register from another.
Syntax:
sub destinationRegister, sourceRegister1, sourceRegister2
E.g.,
sub r1, r1, r2 (subtract r2 from r1 and store the result in r1)
which can also be written as:
sub r1, r2

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

Writing complex instructions

A

Unlike in high level languages, you cannot complete multiple operations on the same line.
Complex instructions must be broken down into smaller steps.

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

Current Program Status Register (CPSR)

A

An ARM register that records the state or effects of the program after an arithmetic instruction in case of need for a carry bit, overflow or comparisons.
Arithmetic instructions will affect its value every time

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

CPSR Flags

A

N bit: The “negative flag”. Flags if the instruction result was negative.
Z bit: The “zero flag”. Flags if the instruction result was zero.
C bit: The “carry flag”. Flags if the Instruction causes a carry-out or borrow.
V bit: The “overflow flag”. Flags if the Instruction produces an overflow in 2’s complement numbers.

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

Bit shifting

A

A key operation to manage individual bits in a register.
It can be used for fast multiplication/division with powers of 2 e.g., multiply by 16 or divide by 8.
You can only use shifts on r0-r7
Syntax
shiftType resultRegister, registerEvaluated, numShifts

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

Logical shift left

A

All bits are moved left by a specified amount.
All bits from the left side are deleted and the space at the right side is replaced with zeros.
Operator: lsl (Logical Shift Left)

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

Logical shift right

A

All bits are moved right by a specified amount.
All bits from the right side are deleted and the space at the left side is replaced with zeros.
Operator: lsr (Logical Shift Right)

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

Arithmetic shift right

A

All bits are shifted right by a specified amount similar to logical shift right. However,
If the number is positive (msb is 0), the empty space on the left will be filled with zeros.
If the number is negative (msb is 1), the empty space on the left will be filled with ones
This keeps the numbers in the correct representation in twos complement.
Operator: asr (Arithmetic Shift Right)

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

Rotate right shift

A

All bits are shifted right however instead of removing bits from the right side and adding new bits to the left side of the number, any bit that is removed from the right-hand side is added back to the left-hand side of the number.
Operator: ror (ROtate Right)

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

Logical operators

A

Allows you to apply boolean operations to registers.
Syntax:
logicalOperator resultRegister, registersEvaluated, registersEvaluated

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

AND

A

For all bits in the register, compare bits of the same position. If both bits at the position are 1, return 1, else return 0.
Operator: and
E.g., and r0,r1,r2

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

OR

A

For all bits in the register, compare bits of the same position. If both bits at a point in a register are 0, return 0, else return 1.
Operator: orr
E.g., orr r0,r1,r2

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

Exclusive OR

A

For all bits in the register, compare bits of the same position. If both bits at a point in a register are either 0 or 1, return 0, else return 1.
Operator: eor
E.g., eor r0,r1,r2

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

Move Not

A

Similar to move but you apply the NOT operation to all the bits in the register before moving.
Operator: mvn
E.g., mvn r0,r1

17
Q

Immediate operand

A

An immediate operator is an operator that represents a fixed integer value – a constant.
An immediate operator can be used in place of a register input to input an integer instead of the contents of a register.
Immediates start with a # and are interpreted as a signed integer encoded using two’s complement.

18
Q

Loading large numbers

A

Mov can only load between 0x00000000 to 0x0000FFFF to registers meaning you cannot load larger numbers using only mov.
Larger numbers can be loaded however, by splitting it into the upper and lower halves and loading them separately using movt which loads values into the upper 16 bits of a register, leaving the lower 16 bits alone.
E.g., storing 0x7fffffff in register r0:
load lower bits: mov r0, 0xffff
load upper bits: movt r0, 0x7fff