Mon, 31 Oct 2011, 01:15
A student writes: > Dr. Patt, > > I was working on the problem set, when I came across a dilemma. > Number 3 says that the value in R1 is unsigned. However, the LC3 > considers all integers to be signed, correct? (I really hope I'm > right about that) As is usually the case in these matters, one needs to be careful about what one is asking about. R1 contains 16 bits. It could be two ascii codes, it could be an address. It could also be an integer. If the ALU is adding the contents of R1, then the ALU treats the contents as a 2's complement integer. But what is actually being represented is whatever the user has in mind. For example, suppose the user has in mind the ascii code for + - then the contents of R1 would be x002B. Suppose the LC-3 executes ADD R1,R1,R1. The contents of R1 is now x0056, which is "V" if the programmer is thinking in terms of ascii codes. Perhaps silly to add ascii codes, but silliness is up to the programmer. When the LC-3 executes an ADD instruction, it assumes the two source operands are 2's complement integers. Whether that is what the programmer had in mind is another story. If the programmer had something else in mind, that is just too bad for the programmer. The LC-3 can not read minds, it can only do what it can do, and if asked to add what is in a register, it treats the contents of that register as a 2's complement integer. OK? > My question is, if R1 can be unsigned, when we put R1 into R2 in the > first line of the program, does the LC-3 treat the value that is now > in R2 as an unsigned integer as well? Or is it considered to be signed? When the LC-3 puts R1 into R2, it puts the 16 bits that constituted the value in R1 into R2. The LC-3 does not care what it is. Only if you ask the LC-3 to add does it treat that value as a 2's complement integer. If you ask it to do something else with that value, it may treat it as an unsigned integer. For example, what if you now asked the LC-3 to execute LDR, R5,R2,#0, how would it treat the contents of R2. Clearly as a 16-bit address. ...and addresses as you know are unsigned integers. > For instance, if xFFFF is in R1, the unsigned value would be 65535. If it is signed it would be -1. That is true. And, if you execute LD R2,R1,#0, you would load from x65535, but if you execute ADD R2,R1,#1, you would say R1 contains the value -1. > Having a negative number would change how the program operates. > Are we supposed to include this in our description of how the program > operates or should we just assume that it remains as unsigned throughout > the program? I think I will leave it in your hands at this point. ...unless you are still stuck. > <<name withheld to protect the student who forgot a fundamental notion>> The fundamental notion is that the same bit pattern in a memory location can represent many different things, depending on what the computer is being asked to do with that bit pattern. OK? Good luck on the exam. Yale Patt