- 4 index registers. MSB is in bit 2, LSB is in bit 5. How do we extract it?
- LSB ← cpc >> 5 & 0x01
- MSB ← cpc >> 1 & 0x02
- index ← MSB | LSB

- Stack is usually allocated in memory, outside of the CPU. what if it was inside the cpu itself?
- advantages: speed.
- shortcomings: have to keep accessing the bus to get to the stack. takes up valuable real estate in the cpu. stack inside cpu would probably be small and could be wiped out if we did too many subroutine calls.

- comp instruction is redundant.
- Simplest answer is to use XOR. XOR $-1, Rx
- can also do it with sub/subc
→ dst ← dst + ~src + 1 (where dst is 0, followed by subtracting 1)
→ dst ← dst + ~src + psw.c (where dst and psw.c are 0)

- (cache question)

- zero address arithmetic is done on the stack.
- If we have a one address machine and we want to add A + B, we assume ‘A’ is in the accumulator.
- ADDA B ← the underlying hardware takes the accumulator + mem[b]. in order to do this, the ADDA instruction will take several bytes, probably a hi addr and a lo addr. the PC will be at the instruction ADDA, the next two PC values will contain the hi and lo address
- in a 2 address machine we can just say add r1, r2
- depending on the machine, those could be registers or memory locations. it can be add Regisiter Register, Register Memory, Memory Register, or Memory Memory.
- register register is the smallest
- the middle two will have the memory location following the add instruction
- the double-memory one will have the opcode followed by the two addresses, taking up 3 lcoations.
- adding an immediate would mean putting the opcode followed by the immediate value in 2 words.
- if the word following the opcode is an address, we have to do another fetch to memory to access the location
- worst case, memory memory addition, would take 5 fetches.
- compared to the zero address machine, we push A, push B, and then have an ADD instruction
- we have to fetch mem[TOS] to get srcval then TOS++ then mem[TOS] to get dst value
- dst = dst + src
- write result to mem[TOS]

Index