1.
256 service routines are allowed in LC-2 ISA. The TRAP instruction’s opcode is 1111 (i.e. bits (15:12) are all 1), next four bits must be zero (MBZ) and last eight bits are trapvector which determines routines. So there are 28 = 256 trap routines possible.4.
; It is assumed that the registers are already loaded ADD R3, R2, R1 BRzn NegTest1 ADD R1, R1, #0 ; result is positive so check for negative operands BRzp DONE ADD R2, R2, #0 ; R1 is negative so check R2 BRzp DONE BR OVERFLOW ; R1 and R2 are negative, but R3 is positive NegTest1 ADD R1, R1, #0 ; result is negative so check for positive operands BRnz DONE ADD R2, R2, #0 ; R1 is positive so check R2 BRnz DONE BR OVERFLOWNote: This is just one of the several possible solutions and one of the simpler ones in terms of algorithm. There are other solutions like negating R2 and R1 and adding both to R3 and see if result is 0, etc.
LDR R2, R1, #0 ; R2 = mem[R1+0] STR R2, R0, #0 ; mem[R0+0] = R2 => mem[R0] = mem[R1]
MAR ß SR MDR ß mem[MAR] MAR ß DR mem[MAR] ß MDR