Finals Flashcards
Provide the symbol table for the following:
What are the three types of number encoding?
- Sign Magnitude Representation
- 1’s complement representation
- 2’s complement representation
How is a Sign Magnitude Representation encoded?
What makes this encoding ackward?
Encode: -+10 (using 8 bits)
Encode: -+7 (using 4 bits)
Encode: +-123
- Use MSB to represent the sign of the number (0 for +, 1 for - )
- Use remaining n-1 bits for the magnitude (that is the absolute value) of the number
- The magnitude is encoded using unsigned number encoding
- +-10 = 10001010 (for neg), 00001010 (for pos)
- +-7 = 1111(for neg), 0111(for pos)
- -+123 = 11111011(for neg), 01111011(for pos)
- Ackward because:
- There are two distinct representations for value 0, 0000 and 1000
- Arithmetic
- If signs are different we need to
- determine the number with the larger magnitude
- Subtract the larger magnitude number by the smaller
- adjust sign as necessary
- If signs are different we need to
What is the one’s complement representation?
- Encode +-5 (using 4 bits)
- +-101 (using 8 bits)
What makes this encoding ackward?
Using n = bits, represent 0 as 11111111 and compute, 0+1
- Positive numbers have MSB 0, and the same encoding for unsigned numbers.
- Negative numbers are encoded as the bit-wise negation of the representation of the numbers absolute value
- Encodings:
- +-5 = 0101 (for pos), 1010(for neg)
- +-101(8 bits) =01100101(for pos), 10011010(for neg)
- Ackward
- two distinct 0’s, 0000, 1111
- drawbacks with arithmetic
- 11111111 (neg 0) + 1 = 000000000
What is two’s complement encoding?
Encode:
- +-12 (using 8 bits)
- Non-negative numbers have 0 in MSB and encoded using unsigned number encoding
- Negative numbers uses the “two’s complement” of the representation of the number’s absolute value
- you toggle every bit and then add 1 to the result.
- self-inverting, apply twice and you get back your original number
- As a consequence MSB sign bit, 0 for non-neg, 1 for neg
- Encodings:
- +-12 = 00001100 (for pos), 11110100(for neg)
What are the advantages to two’s complement representation?
Draw the timing diagram of the following:
Provide the timing diagram for the following circuit:
When running a subroutine, jumping is handled by the PC register value.
When about to jump, the PC register value is saved for the return.
Where is that value saved?
The PC’s value is saved in R7
LC-3 ISA provides two basic instructions for updating the PC register for subroutines?
What are they/
JSR and RET
JSR
- The instruction saves the content of the PC register to R7 and jumps to the address specified by the label in the instrucitons
- PC holds the address of the instruction following the instruction being executed.
RET
- Causes the return from the subroutine to the caller
- It loads the content of R7 into PC
Provide a simple example code of using a subroutine.
JSR is limited to a jump of -210 to 210-1
How would you jump further than that?
JSSR
Put the address of the start of the subroutine into a register (LEA R5, mySub)
Call subroutine using JSSR specifying the register that holds the address to the subroutine (JSRR R5)
In order to use the RTS what concepts do we need?
- A stack pointer - a register that holds the address of the top of the runtime stack (TOS)
- Push/pop operations - these allow you to push and pop items onto the RTS
- A frame pointer - this is used to allow you to work with teh current activation record.
- An activation record (for a subroutine call) is the space allocated on the RTS for arguments and return value(s) for the subroutine call.