U Proc
U Proc
Computer System
1. CPU: controls operations, reads and executes instruction, stores the results, has Arithmetic
logic unit (ALU). CPU generates consecutive address to fetch information from memory, the
program counter. Can also hold the data temporarily in registers.
2. Memory - For data storage. Semiconductor memories store data as long as power is
available; magnetic memories can hold the data even in the absence of power.
Semiconductor memories can be ROM, the read only memory or RAM Random access
(read/write) memory.
3. I/O: Is the interface for the outside world. They are slow compared to CPU and memory,
and work asynchronously. IO devices typically use hand-shake signals for communications
Computer System
Address Bus: Used to access a unique location in memory (or I/O). CPU
sends out address of location from where it needs to access the data.
With n lines in the address bus CPU can access 2n address locations
Data Bus: These lines are used to carry data between CPU and devices
(memory and/or I/O). To ensure only one device responds to a specific
address, devices connected to data lines should have tri-state outputs.
With m data lines, we say it is m-bit CPU
Control Bus: CPU informs devices what to do (Ex. read or write) on these
lines. All the synchronization and hand-shake operations (signals) are
carried out by the control bus.
Typically, address and data bus are similar in all the CPUs. Variations
occur in the control bus.
Hardware is the physical device; software consists of programs, typically
resides in RAM; Firmware brings up the board and resides in ROM
Execution steps
Microprocessor Microcontroller
Only CPU CPU + Memory + IO
General purpose Specific application
Higher clock speed Lower clock speed
Multi-tasking Single (of few) task
Higher power consumption Lower power consumption
Used in PCs Used in embedded systems
8086 Internal architecture
1. BIU (Bus Interface Unit) - Sends out address, fetches data(or instructions) and
writes back the result to the memory. The BIU can work asynchronously with
respect to the EU.
a. The Queue - CPU can pre-fetch (upto) 6 instructions (bytes) from memory and
store them in the BIU. This can be done in parallel with instruction execution in
the EU. Whenever EU wants an instruction, it can fetch the instruction from the
queue. This will be faster compared to fetching the same from a memory
location. Queue will be flushed out during a branch operation.
b. Segment registers: They hold the base address of four (independent)
segments. Segments helps to isolate different types of information (code,
data, stack) in the memory. We can configure the segment to be distributed
anywhere in the memory range. Segments can overlap or share a location too
c. Instruction pointer - Holds the 16 bit offset of next instruction, within a code
segment
Bit manipulation
Typical logical operation. AND, OR and XOR
AND d,s d <- d AND s. Each bit is logically anded.
Similar operation for OR and XOR. CF=OF=0 and AF is
undefined
NOT d d<- NOT(d). bitwise complement. If it is
memory location, need to have byte ptr or word ptr to
indicate 8 or 16 bit data respectively. No flags affected
TEST d,s perform D (bitwise) AND S. D and S are
not affected; flags are updatetd
Shift operation
Left shift corresponds to multiply and right shift operations divide
operations. These are faster than MUL and DIV instructions
SHL/SAL:Shift data left. (MSB) Bit shifted out goes to CF and empty bit
(LSB) is loaded with zero
SHR: Shift Right. Bit shifted out (LSB) goes to CF and empty bit (MSB)
is loaded with zero
SAR -Shift arithmatic right: Similar to SHR, but MSB is retained as it is
ROL: Rotate left. Bit (MSB) shifted out goes to CF and also enters into
empty (LSB) bit
ROR: Rotate right. Bit (LSB) sifhted out goes to CF and also enters into
empty (LSB) bit
RCL: Rotate Circular left. Bit (MSB) shifted out goes to CF, CF goes to
empty (LSB) bit
RCR: Rotate Circular right. Bit (LSB) shifted out goes to CF, CF goes to
empty (MSB) bit
Branch
All unconditional braches are +/-32K (signed 16 bit
offset) and all unconditional branches are +/-128
byres (signed 8 bit offset)
That is jumps are relative
FAR jumps are absolute
Syntax:
JMP label
Jcc Label (cc stands for condition)
JMP [BX]
Jcc [BX+SI]
Branch
JA/JBE Jump Above/Jump Below or Equal (CF OR ZF) = 0
JAE/JNB/JNC Above or Equal/Not Below/No Carry CF=0
JB/JNAE/JC Below/Above or Equal/Carry CF=1
JBE/JNA Below or Equal/Not Above (CF OR ZF) = 1
JE/JZ Equal/Zero ZF=1
JG/JNLE Greater/Not Less or Equal ((SF XOR OF) OR ZF) =1
JGE/JNL Greater or Equal/Not Less (than) (SF XOR OF) = 0
JL/JNGE Less than/Not Greater or Equal (SF XOR OF) = 1
JLE/JNG Less or Equal/ Not Greater ((SF XOR OF) OR ZF) =0
JNE/JNZ Not Equal/Not Zero ZF=0
JNO No Overflow OF=0
JNP/JPO No parity/Parity Odd PF=0
JO Overflow OF=1
JP/JPE Parity/ Parity Even PF=1
JS Sign SF=1
JNS No sign SF=0
LOOP <label> Decrement CX. If CX !=0, jump to the lable
Process Control operations
Process control will operate directly on flags.
Other than the specified flags, no other flags are affected
STC - Set carry: CF=1
CLC Clear carry: CF=0
CMC Coplement carry: CF is complemented
STD Set direction flag: For string operations, SI and/or DI
autometically decremented
CLD Clear direction flag: For string operations, SI and/or DI
automatically incremented
NOP No operations. Does not affect any registers, memory or
flags. Used to generate delay
HLT Halt. Stop execution of program. Interrupt or reset will
bring out of HLT state
String operations
SI and/or DI are used to point to source and destination
SI and/or DI are automatically updated
SI operates within the Data Segment (DS) and DI operates
within Extra Segment (ES)
Instructions should be terminated with either B (for byte) or
W(for word operand). Like LODSB or LODSW. AL is used
for byte and AX is used for word data
LODS load string: Accumulator <- [SI]; update SI
STOS Store string: [DI] <- Accumulator; Update DI
MOVS Move string: [DI] <- [SI]; update SI and DI
SCAS Scan string: compare Accumulator with [DI]; update DI
CMPS Compare string: Compare [DI] and [SI]; update SI and DI
Instruction Encoding
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Opcode D W MOD REG R/M
S2 S1 S0 Action
0 0 0 INTA
0 0 1 IO RD*
0 1 0 IO WR*
0 1 1 HALT
1 0 0 MemRD*
1 1 0 MemWR*
1 1 1