Week 11: LDR/STR encoding/decoding, Examples, and Stacks Flashcards

1
Q

For arm LDR / STR instructions, whenever a single byte is loaded into a register, the most significant bits are…

A

Set to zero

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

For ARM LDR / STR instructions, are register-based dynamic shifts allowed?

A

NO

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

For ARM LDR / STR instructions, are static shifts allowed?

A

YES

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

For ARM LDR / STR instructions, when P = 0 (post-indexed addressing), what is true?

A

The W (write-back) bit is ALWAYS set to zero

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

When will the W-bit always be 0?

A

When P=0

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

For ARM LDR / STR instructions, an immediate-offset is always

A

A 12-bit literal offset, there is no rotation

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

To calculate the absolute value in ARM, what can you do?

A

TEQ r0, #0
RSBMI r0, r0, #0

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

To clear higher-order bytes, what operation can you use?

A

AND

AND r0,r0,#0xFF
AND r1,r1,#0xFF

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

To clear specific bytes, what can you use?

A

BIC

BIC r2,r2,#0xFF0000
BIC r2,r2,#0xFF000000

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

Is the following valid?

BIC r2,r2,#0xFFFF0000

A

No, because only instructions that are 16-bits long can be used (FF)

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

To swap variables without using an intermediate register, what can be done?

A

ADD r0, r0, r1

SUB r1, r0, r1
SUB r0, r0, r1

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

To multiply by 2^n -1, 2^n, or 2^n + 1

What can be done?

A

For 2^n
Simply use a mov and LSL
MOV r2, r1, LSL #n

For 2^n + 1, use an ADD instruction
ADD r2, r1, r1, LSL#n

For 2^n - 1 use RSB
RSB r2, r1, r1, LSL#n

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

How do you divide by D?

A

Use MUL and ADR instructions:

[r0] / D = [r0] × (2^N/D) / 2^N

Select N to be a large integer at the same time not to cause an overflow when
evaluating [r0] × (2^N/D)

Evaluate [r0] × (2^N/D)

Arithmetic shift right the result N time

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

How do you convert a capital letter to a small letter?

If the character to be converted to a smaller letter is in r0 and r1 is a working register?

A

CMP r0, #’A’

RSBGES r1, r0, #’Z’

ORRGE r0, r0, #2_100000

First test if its greater than A

Then test if its between A-Z

If so, force bit 5 to 1 to make it lower case

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

How would you write out the following code in one line?

if (x < 0) x = 0;

A

BIC r0, r0, r0, ASR#31

The ASR#31 will fill the entire word with only the sign bit

If positive, the result will be 0x00000000

IF negative the result will be 0xFFFFFFFF

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

How do you implement a switch statement in ARM?

A
17
Q

The stack is a ____ queue, which means items enter through ______ and leave through ____

A

The stack is a LIFO queue, which means items enter through one end and leave through the same end

18
Q

Stacks are implemented using the

A

Stack Pointer

19
Q

The push and pop of a stack that grows up and already occupies memory looks like what?

A

PUSH

STR R0, [SP, #-4]!

POP

LDR R0, [SP], #4

20
Q

The push and pop of a stack that grows up and does not occupy memory looks like what?

A

PUSH

STR R0, [SP], #-4

POP

LDR R0, [SP, #4]!

21
Q

The push and pop of a stack that grows down and already occupies memory looks like what?

A

PUSH

STR R0, [SP, #4]!

POP

LDR R0, [SP], #-4

22
Q

The push and pop of a stack that grows down and does not already occupy memory looks like what?

A

PUSH

STR R0, [SP], #4

POP

LDR R0, [SP, #-4]!

23
Q

The two decisions that must be made when implementing a stack are:

A

Whether the stack is going to grow up or down

Whether or not the stack pointer is going to point to empty memory or full memory

24
Q

What is the difference between CISC and RISC processors when it comes to the stack?

A

CISC processors automatically maintain the stack.

RISC processors force the programmer to maintain the stack.