Lecture 8 - More on Sigma16 Flashcards
When is AND true?
if both operands are true
What is OR false?
if both operands are false
When is XOR true?
if both operands are different.
How do you work out the bitwise XOR of 2 8-bit words?
Compare the binary numbers. If they are the same put 0 and if they are different put 1
When is bitwise AND useful and how would it be used?**
It is useful when you want to isolate a particular bit
Eg., 4 most significant bits.
If we bitwise AND $F0 to the word you want to isolate the 4 most signficant bits in $7D.
$F0 = 1111 0000
$7D = 0111 1101
Since ANDing any bit with 0 gives 0 and ANDing any bit with 1 leaves the bit unchanged we can mask the bits we aren’t interested in so the
bitwise-AND = 0111 0000
What RRR instructions DON’T work with unsigned numbers?
MUL, DIV, CMPGT, CMPLT
What instructions work for non-numerics?
CMPEQ
What is special about R15?
The remainder from DIV always goes in here
Anything in there is overwritten
What is special about R0?
It is always 0
What is an instruction cycle?
The sequence of events & time involved in fetching & executing an instruction.
What is a memory cycle?
The time involved in reading/writing a single word from & to a single memory location (over the data bus)
How many memory cycles are involved in an instruction cycle?*
An instruction cycle may involve several memory cycles:
RRR takes 1 memory cycle (fetch)
RX takes 2 memory cycles
(except for LOAD and STORE which take 3 memory cycles)
So generally RX instructions are twice as slow as RRR instructions
What 2 instructions will you always find in the CPU?
Instruction Register: contains the operation word of the instruction being executed
Program counter: the address of the next instruction that will be executed.
It can be thought of as an index in an array of memory
What 2 registers are specific to Sigma16?
Instruction register: An address register contains the target address (EA) specified in an RX or X instruction
Data register: holds temporary data.
How do you describe the speed of memory cycles?
Accessing memory is a relatively slow process.
RRR instructions are 1 memory cycle because they are already on the circuit.
RX instructions generally take 2 memory cycles.
1 . to find out they are an RX instruction eg., JUMP
2. to find out where to go
LOAD & STORE take 3 memory cycles.
- to find out they are a LOAD/STORE
- to find out what they need to LOAD/STORE
- go to memory to load/store it
What does shiftl and shfitr mean?
If we have Ra, Rb, Rc: shiftl shifts Rb left by Rc places and stores in Ra. We add zeroes to the end of Ra for the spaces that we’ve shifted and on the other side, the bits are shifted out and dropped off.
How many memory cycles does JUMP instruction take?
To fetch it, it has two words of machine code.
So two memory cycles
What questions do we need to ask when examining the machine code instructions on a new CPU?
1) how many memory cycles are needed to fetch the whole instruction?
2) How many cycles are needed to fetch or store data?
3) How many independent memory locations can the instruction access?
Why can’t we have multiple types of instructions in a CPU?
Many complex instructions mean a long operation word and a complex CU.
A CU with many instruction types is slower than a simple one with few types
What is RISC?
Reduced instruction set computer
Why not have instructions of multiple types in a CPU?
Complex instructions mean a long operation word and a complex control unit.
Complex CU will be slower than a simple one with few types.
What design does Sigma16 use?
RISC
What are the benefits of RISC?
- Simple and limited number of the instruction set
- Prevents most instructions from accessing memory, except for LOAD and STORE
- Internal registers are used for arthmetic & logical operations to make it as fast as possible.
- Simple fast control unit
What is a virtual machine?
it’s a software model of a machine that may or may not exist as hardware.
What is the hypervisor used for?
It’s a software that is often run on the host to create and manage new guests that can be complete copies of real machines.
Why are virtual machines useful?
They allow a certain amount of protection.
It allows us to do certain experiments that might be dangerous to do on our own comp.
Confine sensitive activities.
What happens if a VM crashes?
The host will usually be fine and so will the hypervisor.
What is a subroutine?
A low-level structure that supports HLL.
Rather than repeating instructions in memory, we store one copy of the instruction in memory, and call it using a JUMP instruction, it runs and then once this has ran return back to the instruction after the call.This repeated each time it is called.
What is the return address?
After the subroutine is called, we must return to the return address.
How do we know where to jump back to after running a subroutine?
Use Jump and Link (JAL). JAL stores the return address in Rf, if we have:
JAL Rf, work[R0]
Can you have subroutines inside subroutines?
Yes, these are called nested subroutine calls
Why does an ordinary JUMP not work for a subroutine?
Because the location it jumps to is a variable, not a constant.
How many memory cycles does an RRR instruction take? Explain.
RRR instructions are 1 memory cycle because they are already on the circuit.
How many memory cycles does an RX instruction take? Explain.
RX instructions generally take 2 memory cycles.
1 . to find out they are an RX instruction eg., JUMP
2. to find out where to go
How many memory cycles does an LOAD/STORE instruction take? Explain.
LOAD & STORE take 3 memory cycles.
- to find out they are a LOAD/STORE
- to find out what they need to LOAD/STORE
- go to memory to load/store it
What is a 3 address instruction?
Performing & storing them in 1 go without loading them into registers.
THINK: doing the cooking in the cupboard
What are the pros & cons of 3 address instruction? What happened as a result of these?
Pros: easier for the programmer because there are less instructions to write
Cons: takes the computer longer to process instructions
Instruction set reduced to a small, but powerful size. You need to write slightly more code eg., LOAD, but doesn’t have check loads of instructions just RRR or RX.
How do you count how fast or slow a memory cycle was?
Everytime you see…
- RRR its 1
- RX it 2
Load or Store 3
Where should we store many nested subroutine calls?
In memory
Where are the address of the stack bottom and stack top originally set to?
The bottom address. At this point the stack is empty.
After a subroutine call, store return address on stack and increment the stack pointer (usually points to one above the stack top)
what kind of data structure is a stack (lifo)?
LIFO (last in first out)
** It’s like pilling things on top of each other & someone asks you to pick something on the top!
What is a stack?
A stack is set up and maintained by a programmer.
Unlike an array, a stack can grow and shrink (dynamic).
Occupies consecutive memory locations.
The first address is the stack bottom, the last one is the stack top (grows upwards in memory).
**Its like pilling things on top of each other & someone asks you to pick something on the top!
Don’t indent like an array, it just gives you the thing of the top which is why its good for storing the return address of the subroutine.
What part of the stack can you access?
The only thing you can access is the top of the stack which works perfectly for nested subroutines.
What is a PUSH operation?
storing an item on the stack
eg., save the return address
What is a PULL or POP operation?
Pulling an item from the stack which is always the last one that has been pushed
eg. retrieve the return address
What is a stack overflow?
Undesirable condition in which a particular computer program tries to use more memory space than the call stack has available.
What happens if a JAL call is made while in a subroutine?
Return address overwritten with a new return address
Must place the return address onto the stack (memory)
What tracks the stack top?
A register called the stack pointer (SP) which contains its current address.
When the stack is empty, initially the stack top and bottom are the same so…..
the stack pointer is set to the stack bottom because that is also where the stack pointer is.
Which direction does the stack grow in Sigma16? Is there an alternative way?
The stack grows upwards in Sigma16 & is maintained by the programmer
But many CPU designs grow downwards in memory so the stack address is at a lower address than the stack bottom.
How do tell if a number is odd/even?
Use bitwiseAND.
Mask: 0000 0001
1001 0111 MASK 0000 0001
/// need to check this if it is odd or even
one will have 00000001
one will have 00000000
Not sure which**
How many words are in these:
- LEA R1,0[R0]
- ADD R1, R0, R0
- 2 words of machinie code
- 1 word of machine code
Both mean the same thing