Thu, 21 Nov 2013, 00:33
Late in the lecture today, I wrote on the board the code that the operating system would have to write in order to set the I/E bit (bit 14) of the KBSR. I just got email from a student: > Hello Dr. Patt,I was studying today's lecture and i am confused > with one thing.In the piece of code that you wrote for addressing > bit 14 of KBSR, you wrote as following: > LDI R4,KBSR > LD R3,A > ADD R4,R4,R3 > STI R4,KBSR > KBSR .FILL XFE00 > A .FILL X4000 > My question is, shouldn't we use "AND R4,R4,R3" instead of "ADD R4,R4,R3"? > > Thanks. > <<name withheld to protect the student who wants to substitute AND for ADD>> Two things are important here. Thing 1. No, I meant ADD, not AND. Recall what I was trying to do. KBSR contained 00xxxxxxxxxxxxxx A contained 0100000000000000 If I AND them as you suggest, I get 0000000000000000 in KBSR. But if I ADD them, and then store the result in KBSR, I get in KBSR 01xxxxxxxxxxxxxx so it works! And, then I asked, "But does it really work." And several students were quick to point out that if bit 14 is already a 1, then adding x4000 does not set bit 14; it clears bit 14 and sets bit 15. Not what I wanted to do! Which brings us to thing 2. What should I do? And several students pointed out the correct answer which is to first clear bit 14 and then add x4000. So, the real operating system code to set the I/E bit of the KSBR is: LDI R4,KBSR LD R3,A NOT R5,R3 ;R5=1011111111111111, a mask for clearing bit 14 AND R4,R4,R5 ; this clears bit 14 ADD R4,R4,R3 ; this sets bit 14 STI R4,KBSR KBSR .FILL XFE00 A .FILL X4000 Good luck with the rest of the course. See you in class on Monday. Yale Patt