3.pdf 1. Assume r1 0x0OCCCCEE, and ro Ox000OFFFF, answer the following questions
ID: 3746135 • Letter: 3
Question
3.pdf 1. Assume r1 0x0OCCCCEE, and ro Ox000OFFFF, answer the following questions. (1) What is the value of 12 after executing BIC 12,r01? (2) What are the values in rO and ri after running the following program? What does this program do? EOR ro,ro,ri EOR riro,ri EOR rO,rOri (3) What are the values for Z and N flag after executing CMP r1, ro (4) What are the values for Z and N flag after executing TEQrl, ro (5) What are the values for Z and N flag after executing CMN ri, ro 2. If r1 0x00FF, and r2-5, what is the value of ro after each of the following instructions has been executed (assume that each instruction uses the same data)? 1) ADD ro,r1,r1, LSL #2 2) ADD ro,r1,r1, LSL R2 3) ADD ro,r1,r1, ROR #4Explanation / Answer
1. Given r1=0x00CCCCEE , r0=0x0000FFFF
(1) BIC r2,r0,r1
BIC denotes bit clear
Result: r2=r0 & (Not(r1))
NOT r1= 0xccccef
r0=0x00CCCCEE
therefore r2=0x00ccccee
(2) r0=? r1=?
EOR is Bit-wise exclusive-or
EOR r0,r0,r1
EOR r1,r0,r1
EOR r0,r0,r1
=>The above three instructions, execute one by one
=> The value of r0 is found in first instruction and is used in next instruction
=>In the second instruction, the new r0 is used and Similarly the value of r1 found.
=> Hence the value of r0 and r1 keeps changing consequently.
EOR r0,r0,r1 is equivalent to r0 = r0 EOR r1
r0=00CCCCEE (EOR) 0000FFFF
Step 1 Result : r0=00CC3311
Next
EOR r1,r0,r1
r1=r0 EOR r1
=00CC3311 (EOR)00CCCCEE
r1=0000FFFF
Step2 Result: r1=0000FFFF
Next
EOR r0,r0,r1
r0=r0 EOR r1
=00CC3311 (EOR) 0000FFFF
r0=00CCCCEE
Step3 Result: r0=00CCCCEE
(3)values of flag Z and N after executing CMP r1,r0
CMP r1,r0 sets the condition flag according to r1-r0 result
Answer= cbccef
Hence N=0, Z=0 (Both are not set)
=>N is the negative flag and is set if the result is negative.
=>Z is the zero flag and is set if the result is zero
(4)values of flag Z and N after executing TEQ r1,r0
TEQ r1,r0 is r1 XOR r0
Ans: cc3311
Hence N=0, Z=0 (Both are not set)
(5)values of flag Z and N after executing CMN r1,r0
CMN r1,r0 is r1+r0
Ans: cdcced
Hence N=0, Z=0 (Both are not set)
2. r1=0x00FF r2=5 r0=?
(1)ADD r0,r1,r1, LSL #2
ADD r0,r1,r1 gives result as r0=r1+r1
LSL is Logical shift left
ADD r0,r1,r1, LSL #2 result is r0=r1+r1 <<2 ; r0=r1+ 2power2 * r1
i.e r0=r1+4*r1
r0=r1+3FC
Answer : r0=4FB
(2)ADD r0,r1,r1, LSL R2
ADD r0,r1,r1 gives result as r0=r1+r1
LSL is Logical shift left
ADD r0,r1,r1, LSL R2 is r0=r1+r1 << r2
r0=r1+ (2^r2)*r1
r0=r1+(2^5)*r1
r0=r1+32*r1
=r1+31CE =32CD
Answer : r0=32CD
(3)ADD r0,r1,r1, ROR #4
ADD r0,r1,r1 gives result as r0=r1+r1
ADD r0,r1,r1, ROR #4 is r0=r1+r1 rotated right 4 bits
ROR is Rotate Right
=>((Unsigned) x>>y)| (x<<(32-y))
r0=1FE ROR #4
r0= 11100000000000000000000000011111 (Binary)
Answer: r0=E000001F
3. r0=0xFEE2A0FD
MOV r0,r0, ASR #31
r0=r0/(2^31)
=r0/(2147483648)
=0.07a8bf5bc97fcf4
Answer: Value of r0 after executing the given instruction is r0=0.07a8bf5bc97fcf4
4. r1=0x0ff r2=4
(1)MOV r3,r1, LSL r2
Here MOV r3,r1 denotes r3=r1
LSL is Logical Shift Left
ie. x<<y, The least significant bits are filled with zeroes.
Hence MOV r3,r1, LSL r2
Results in r3=r1 << value specified in r2
r3=r1*(2^r2)=r1*2^4
r3=r1 *16= 15EA
Answer: r3=15EA
(2)MOV r3,r1, LSR r2
LSR is Logical Shift Right
i.e (unsigned)x>>y,the most significant bits are filled with zeroes.
r3=r1 >> value specified in r2
r3=r1/(2^r2)=r1/(2^4)
r3=r1/16
Answer: r3=b.9745d1745d178
(3)MVN r3,r1, LSL r2
MVN is move negated
MVN r3,r1 ; results as r3=NOT(r1)
r3=-100 * (2^r2)
=-100 *(16)
Answer: r3 =-1600
(4)MVN r3,r1, LSR r2
r3=NOT(r1) LSR(r2)
r3=-100 /(2^r2)
=-100/(16)
=-b.a2e8ba2e8ba3
Answer: r3=-b.a2e8ba2e8ba3
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.