Week 11: LDR/STR encoding/decoding, Examples, and Stacks Flashcards
For arm LDR / STR instructions, whenever a single byte is loaded into a register, the most significant bits are…
Set to zero
For ARM LDR / STR instructions, are register-based dynamic shifts allowed?
NO
For ARM LDR / STR instructions, are static shifts allowed?
YES
For ARM LDR / STR instructions, when P = 0 (post-indexed addressing), what is true?
The W (write-back) bit is ALWAYS set to zero
When will the W-bit always be 0?
When P=0
For ARM LDR / STR instructions, an immediate-offset is always
A 12-bit literal offset, there is no rotation
To calculate the absolute value in ARM, what can you do?
TEQ r0, #0
RSBMI r0, r0, #0
To clear higher-order bytes, what operation can you use?
AND
AND r0,r0,#0xFF
AND r1,r1,#0xFF
To clear specific bytes, what can you use?
BIC
BIC r2,r2,#0xFF0000
BIC r2,r2,#0xFF000000
Is the following valid?
BIC r2,r2,#0xFFFF0000
No, because only instructions that are 16-bits long can be used (FF)
To swap variables without using an intermediate register, what can be done?
ADD r0, r0, r1
SUB r1, r0, r1
SUB r0, r0, r1
To multiply by 2^n -1, 2^n, or 2^n + 1
What can be done?
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 do you divide by D?
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 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?
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 would you write out the following code in one line?
if (x < 0) x = 0;
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