CSA UNIT 2
CSA UNIT 2
In the Basic Computer, since the memory contains 4096 (= 2**12) words, so 12 bits specify
which memory address this instruction will use .
In the Basic Computer, bit 15 of the instruction specifies the addressing mode (0: direct
addressing, 1: indirect addressing)
Since the memory words, and hence the instructions, are 16 bits long, that leaves 3 bits for
the instruction’s op-code .
Addressing Modes
three addressing modes
1. Immediate operand: when the second part of the instruction code specifies an operand.
2. Direct address: when the second part of the instruction code specifies the address of the
operand.
3. Indirect address: when this part specifies an address in a memory where we can find the
true address of the operand.
The (I) bit of the instruction code specifies direct addressing If I=0 or Indirect addressing if
I=1.
Accumulator Register (AC): exist in single register processors (AC) and all operations are
performed with memory operand and this register.
Effective Address (EA):
The address that can be directly used without modification to access an operand for a
computation-type instruction, or as the target address for a branch-type instruction
The previous figure shows an example of addressing mode. In location 22 there is an ADD
instruction that adds the AC with operand in location 457 as an indication for direct
addressing mode as I=0.
On the other hand, the second part of the figure shows in location 35 and ADD instruction
between AC and the address of operand found in location 300. Location 300 contains the
operand address of 1350. In 1350 the operand will be read and added to the AC register, as
I=1 shows.
Computer Registers
A processor has many registers to hold instructions after it has been fetched from memory,
addresses of operands need to be accessed data manipulated with accumulator, general
purpose register, and others.
Program Counter (PC): used is to hold the memory address of the next instruction to be
executed. Size: 12 bits. :
The Address Register (AR) is used to keep track of what locations in memory processor is
addressing. Size: 12 bit
This AR register is always connected to address pins of memory unit.
Data Register (DR): When an operand is found, using either direct or indirect addressing, it
is placed in DR.
The processor then uses this value as data for its operation.
DR is connected to data pins of memory unit.
Accumulator (AC):
The Basic Computer has a single general purpose register–the Accumulator (AC)
it can be referred to in instructions.
E.g. load AC with the contents of a specific memory location;
store the contents of AC into a specified memory location.
AC is always one side in any data computation.
Temporary Register (TR):
a scratch register used to store intermediate results or other temporary data.
-For instruction reading, a PC is used to hold address of next instruction to be fetched and
executed.
- First the PC value is copied into AR to start an instruction reading cycle, then the 16 bit
instruction is fetched and placed in Instruction Register (IR).
The Basic Computer uses a very simple model of input/output (I/O) operations.
Input devices are considered to send 8 bits of character data to the processor.
And the processor can send 8 bits of character data to output devices.
The Input Register (INPR): holds an 8 bit character gotten from an input device; the
Output Register (OUTR ) : holds an 8 bit character to be send to an output device.
A path needed to transfer data between 8 registers beside memory unit and registers.
So a common bus will be the answer for that problem. The next figure shows the answer
consisting of a multiplexer or 3 state buffers with decoder. This gives a savings in circuitry
over complete connections between registers.
Three control lines, S2, S1, and S0 control which register the bus selects as its input and so
the selected register will issue its output to the bus.
The lines from the common bus are connected to the input of each register.
Either one of the registers will have its load signal activated, or the memory will have its read
signal activated.
And this will determine where the data from the bus gets loaded to during next clock
transition.
The memory will put its content to the bus when S2S1S0 =111 and its read control signal is
activated.
In the same manner, the memory will save the content of the bus,when its write control signal
is activated.
AR register is always used to hold address of data accessed from memory.
4 registers of 16-bit each, DR, AC, IR, and TR. Also we have two registers PC and AR are 12
bits each. The 12-bit registers, AR and PC, have 0’s loaded onto the bus in the high order 4
bit positions.
OUTR and INPR are 8-bit each and are connected to the lower 8 bits of the bus.
Five registers have 3 control inputs, LD, INC, CLR; those are AC, AR, TR, PC, and DR.
Any and only one source of those register can be selected to apply its content to the bus and
during the same clock cycle the bus content could be directed to one or many destinations of
registers or memory unit. For example we can do the next micro-operation:
DR AC and AC DR
S2S1S0 = 100
LD of DR is enabled
Transferring DR through ALU to AC
LD of AC is enabled
Computer Instructions
The Basic Computer has 3 instruction code formats
The content PC is put on the bus (S2S1S0=010) and LD of AR register is enabled during T0
cycle only.
Instruction Cycle
In Basic Computer, a machine instruction is executed in the following cycle:
□ Fetch an instruction from memory
□ Decode the instruction
□ Read the effective address from memory if the instruction has an indirect address
□ Execute the instruction
After an instruction is executed, the cycle starts again at step 1, for the next instruction
Fetch and Decode:
Initially the PC is loaded with address with first instruction in the program then SC is cleared
giving time instance T0.
After each clock pulse SC is incremented resulting of T1, T2, and so on.
A portion of bus system that shows hardware implementation of micro-operations taking
place during T0 and T1
During T0
S2S1S0=010 which means PC apply its output to the bus
AR register LD = 1 which means what in the bus goes into AR register
During T1
Memory RD=1 which means memory unit will get its data out as AR register
indicates.
S2S1S0=111 which means what is read from memory goes to the bus
IR register LD = 1 which means what on the bus will go into IR register .
PC register INR = 1 which means increment PC register.
D7= 1 and I = 0
Execution of register reference starts with timing signal T3 and completed here.
Also Sc is cleared to indicate the end of execution and return to fetch new instruction
with T0.
the first seven instructions will be carried on accumulator or carry bit, E bit.
the next 4 skip instructions will add one to PC register only if their condition is met.
Those conditions will be
Accumulator is positive, A15=0
Accumulator is negative, A15=1
Accumulator is zero, A0 to A15 are zero.
E is 0, carry bit is zero.
Used here a 3 by 8 decoder is used to decode the 3 bits to 8 lines D0 to D7, although
D7 not used here.
The effective address of the instruction is in AR and was placed there during timing
signal T2 when I = 0, or during timing signal T3when I = 1.
The execution of MR instruction starts with T4. The complete execution of this type
of instructions will require a sequence of micro-operations during T4 and T5 and
likely T6.
List of all memory reference Instructions:
Input Output & Interrupts
□ Computer must communicate with external device to receive and send data with it.
□ Instructions and data must come to computer from external input device.
Computational result must be transmitted to user through an output device.
The serial info from the keyboard is received serially and shifted into INPR.
The serial info for the printer is stored in the OUTR and converted to serial and sends
to the printer.
The 1 bit FGI is a control flip flop that sets to 1 when new data is available in input
device and cleared to m0 (by processor) when computer receives it (needed to
synchronize time difference between processor and input device).
When key is pressed in keyboard its code is shifted to serial and shifted to INPR and
FGI is set (by the device). This insures that data in INPR will be untouched by
another key pressed till it’s cleared by the processor.
First the FGO is set to 1 (usually by the device) and processor scans that flag. If FGO
is 1 then it will transfer AC to OUTR and clears FGO to 0. The output device accepts
data in OUTR and sets FGO to 1 indicating it ready for another transfer.
INP instruction transfer data from INPR register to AC0 to AC7 and clears FGI=0
OUT instruction transfers AC0 to AC7 to OUTR and clears FGO=0
The next 2 instructions scans flags and skip next instruction if flag=1 (usually
designed for branching to different locations in program based on value of FGI or FGI
flags).
The last 2 instructions sets and clear Interrupt Enable flip flop (see next section).
Interrupt Initiated IO and Interrupt Cycle
Program controlled transfer described earlier keeps scanning flag bits and when set it
initiate data transfer.
Inefficient since keeps processor doing nothing except scanning IO flags. Also.
For slow device transfer it can be considered wasting a lot of time (different data
transfer rate between IO and processor).
The solution will be the device can interrupt and tell processor when it wants to be
served.
The I/O interface, instead of the CPU, monitors the I/O device.
When the interface founds that the I/O device is ready for data transfer, it generates an
interrupt request to the CPU. CPU does not check the flags except when it is
interrupted by the device.
Upon detecting an interrupt, the CPU stops momentarily the task it is doing, branches
to the service routine to process the data transfer, and then returns to the task it was
performing.
Flowchart of interrupt cycle.
Interrupt Cycle
The interrupt cycle is a HW implementation of a branch and save return address
operation.
The return address is stored in PC and it will be stored in location 0 of
memory (RAM).
PC will be updated to 1 which means it will execute the instruction held at
address = 1 and
Clears both IEN=0 and R=0.
At end of interrupt routine BUN to 0 is inserted with I=1. Means go back to
where it was interrupted from by "indirect BUN 0".
An example of interrupt cycle
Buses A and B are used to transfer the source operands to the A and B inputs
of the ALU, where an arithmetic or logic operation may be performed. The result is
transferred to the destination over bus C. If needed, the ALU may simply pass one of
its two input operands unmodified to bus C. We will call the ALU control signals for
such an operation R=A or R=B. The three-bus arrangement obviates the need for
registers Y and Z.
A second feature is the introduction of
the Incrementer unit, which is used to increment
the PC by 4. Using the Incrementer eliminates the
need to add 4 to the PC using the main ALU.
The source for the constant 4 at the ALU input
multiplexer is still useful. It can be used to
increment other addresses, such as the memory
addresses in LoadMultiple and StoreMultiple
instructions.
Consider the three-operand instruction
Add R4,R5,R6
The control sequence for executing this
instruction is given as below