Gururaj - MPMC M-3 2018
Gururaj - MPMC M-3 2018
MODULE 3
Topics: Signed number arithmetic, String Instructions, 8255 I/O programming, Memory Interfacing.
⮚ Positive numbers
If the sign bit is 0 then the data is positive, else it is negative.
The maximum positive number that can be represented in byte data is +127. ie., 0111 1111.
If the data is larger than +127, then we must use word-sized data.
The maximum positive number that can be represented in byte data is +32767.
⮚ Negative numbers
The magnitude of negative numbers is represented using 2’s complement. The conversion
is done by Assembler. Following steps are used :
• Write the magnitude of the number.
• Invert each bit
• Add 1 to it.
Ex: Represent how -5 is represented in the computer
5 = 0000 0101
Inverted data = 1111 1010
Adding 1 = 1111 1011
So, -5 = 1111 1011
Examples of negative word data:
Microprocessors & Microcontrollers Module 3
● In the example above; +96 is added to +70 and the result according to the CPU is –90
(5AH).
● The reason is that, the result was more than what AL could handle. Like all other 8-bit
registers, AL could only contain up to +127. The designers of the CPU created the
overflow flag specifically for the purpose of informing the programmer that the result of
the signed number operation is erroneous.
The CPU indicates the existence of the problem by raising the OF (overflow) flag, but it is
up to the programmer to take care of it. The CPU understands only 0s and 1s and ignores the
human convention of positive and negative numbers.
Examples:
Microprocessors & Microcontrollers Module 3
Eg
: SAL AX, CL it shifts BX contents CL times in left direction if CL=2 then AX becomes 48C4H.
It shifts right the contents of a register or a memory location which is of a byte /word & the MSB
is copied to emptied space..SAR is used with signed numbers, & the sign of the number is not
changed after the shift operation. The shift may be once or more than once (i.e, CL times).
After the shifting the moved out LSB goes to the carry flag, & in the space created at MSB, once
again the previous MSB is copied.
All the flags, except AC flag, are affected. The SAR instruction. is useful for dividing a signed
binary number by a power of 2. When an odd number is shifted, the result will be truncated.
Before After
Signed operand must be sign-extended before division takes place using IDIV.
An application of signed number arithmetic is given in the following Program. It computes the
average of the Celsius temperatures: +13, -10, + 19, +14, -18, -9, +12, -19, and + 16.
Microprocessors & Microcontrollers Module 3
When using the MOVS instruction, we must indicatethe assembler whether we want to move a
string as byte or as word. This we can do by adding a “B” or a “W” to the MOVS mnemonic.
MOVSB says move a string as bytes; MOVSW says move a string as words.
Ex:
MOV SI, OFFSET SOURCE ;Load offset of start of source string in DS into SI
MOV DI, OFFSET DESTINATION ; Load offset of start of destination string in ES into DI
CLD ;Clear DF to auto increment SI and DI after move
MOV CX, 04H ;Load length of string into CX as counter
REP MOVSB ; Move string byte until CX = 0
The B attached to CMPS tells the assembler that the strings are of type byte. If you want to tell
the assembler that strings are of type word, write the instruction as CMPSW. The REPE
CMPSW instruction will cause the pointers in SI and DI to be incremented by 2 after each
compare, if the direction flag is set.
Program Examples:
Microprocessors & Microcontrollers Module 3
Microprocessors & Microcontrollers Module 3
All of these ports can function independently either as input or as output ports. This can be done
by programming the bits of an internal register of 8255 called CWR (control word register).
The internal block diagram & the pin configuration of 8255 are shown below.
Pin-out of 8255
Microprocessors & Microcontrollers Module 3
The 8-bit data bus buffer is controlled by the read/write control logic. RD, WR, A1, A0, &
RESET are the signals given by the µp to the 8255.
The 8-bit, tri state bidirectional buffer is used to interface the 8255 internal data bus with the
external system data bus. This buffer receives or transmits data upon the execution of
instructions sent by µp. the control word or status information is also transferred through the
buffer.
CS is a chip select line.
A1-A0
there are the address I/p lines & are driven by the µp. these lines along with RD, WR, & CS from the fol
RD WR CS A A0 READ CYCLE
0 1 0 0 0 port A to data bus
0 1 0 0 1 port B to data bus p
RESET
A logic high on this line clears the CWR of 8255. All ports are set as i/p ports by default after reset.
PA7-PA0
these are portA lines that act as either latched output or buffered input lines depending upon the contro
PC7-PC4
upper nibble of port C lines. They may act as either o/p latches or I/p buffers lines. This port can also
Microprocessors & Microcontrollers Module 3
In I/O mode we can program all the ports of 8255 in required mode of operation. But in BSR
mode only port C can be used to set/reset its individual bits.
Under I/O mode further there are 3 modes: mode 0, mode 1 & mode2.
Mode 0
simple input or output .Each of the 3 ports can be used in this mode. Data can be simply read from & w
● O/P ports are latched & i/p ports are not latched.
● A maximum of 4 ports are available so that overall 16 I/O configurations are possible.
Mode 2
Bidirectional handshake input/output. Only port A can be initialized in mode2. It functions in both the
If port A is used in Mode2, then pins PC3-PC7 are used as handshake lines for PortA . Otherwise
if port B is in mode1 then PC0-PC2 pins are used for handshaking for port B.
Ex: data transfer between µp & floppy disk.
Example 1: Set portA as input and portB as output , read a byte from portA and
manipulate it and send to prot B. Assume portA =0DC50H
MOV DX,0DC53H
MOV AL 82H
OUT DX,AL ; Initialize Conrol Word PA=input and PB=output
MOV DX,0DC50H
IN AL,DX ; read from input port
ADD AL, 02 ; manipulate data
Microprocessors & Microcontrollers Module 3
Example 2:
Microprocessors & Microcontrollers Module 3
• Memory Organization
● The number of bits that a semiconductor memory chip can store is called its capacity. It can
be in the units of K bits (kilobits)/M bits (megabits).
● Memory chips are organized into a number of locations within the IC. Each location can hold
1 bit, 4-bits, 8-bits, or even 16-bits.
● Each memory chip contains 2x locations, where x is the number of address pins on the chip.
● Each location contains y bits, where y is the number of data pins on the chip.
● The entire chip will contain 2x * y bits – the capacity of the chip.
less than the total number of address pins). The number of address pins found on a memory
device is determined by the number of memory locations found within it.
Data Connections. All memory devices have a set of data outputs or input/outputs. The device
illustrated in the following Figure has a common set of I/O (input/output) connections.
As shown in the figure above,the memory chips have CS (chip select) pin that must be activated
for memory contents to be accessed. That means, no data can be written into or read form the
memory chip unless CS is activated.
Sometimes, OE (output enable)/RD (read)/WR (write) pins may also be present along with CS
pin.
Numbe of Memory
Address lines
6 64 bytes 2^6 =64
7 128
8 256
9 512
10 1024 (1Kbytes) 2^10=1024
11 2048 (2Kb)
12 4096 (4Kb)
13 8192(8Kb) 2^13 =8192
16 64Kb
201 1Mb 2^20 = 1Mb
Example 1:
A given memory chip has 12 address pins and 8 data pins. Find the memory organization and the
capacity.
Solution:
Memory chip has 12 address lines 212 = 4,096 locations.
Memory chip has 8 data lines Each location hold 8 bits of data.
Thus, the memory organization is 4,096 x 8 = 4K x 8 = 32K bits capacity.
Example 2: A 512K memory chip has 8 data pins. Find the organization.
Solution:
The memory chip has 8 data lines Each location within the chip can hold 8 bits of data.
Given, the capacity of the memory chip = 512K.
Microprocessors & Microcontrollers Module 3
✔ Consider the following memory decoding diagram. We have, A0-A15 from the CPU, directly
connected to A0-A15 of the memory chip.
✔ A16-A18 are used for the A, B, and C inputs of 74LS138; A19 is controlling G1 pin. G2A and G2B are
grounded.
✔ This gives the address range (for the memory chip controlled by Y4): C0000H to CFFFFH.
Microprocessors & Microcontrollers Module 3
Q.Explain 74138 decoder configuration to enable the memory address F0000H to F7FFFH
to connect four 8K RAMs.
Soln:
Given Address range is F0000H – F7FFFH with four 8K RAMs.
This Memory range distributed to Each RAM as following:
1st block of Memory RAM1 :
F0000H TO F1FFFH = 1111 0000 0000 0000 0000 To 1111 0001 1111 1111 1111
2nd block of Memory RAM2 :
F2000H TO F3FFFH = 1111 0010 0000 0000 0000 To 1111 0011 1111 1111 1111
3nd block of Memory RAM3 :
F4000H TO F5FFFH = 1111 0100 0000 0000 0000 To 1111 0101 1111 1111 1111
4th block of Memory RAM4 :
F6000H TO F7FFFH = 1111 0110 0000 0000 0000 To 1111 0111 1111 1111 1111
Microprocessors & Microcontrollers Module 3
Out of all the 20 bits in the address , 13 bits are enough to address 8K bytes memory. So, bit 0 to
bit 12 are used for addressing and bits 13,14 and 15 can be used for chip select for 4 RAMs.
000 for RAM1
001 for RAM2
010 for RAM3
011 for RAM4.
Remaining bits 16-19 can be used for enabling 74LS138 decoder. The design is as shown below:
74LS138
Decoder
G2A
G2B
G1
A13 000 RAM1
A14
A15
001 RAM2
A16
● For mass storage devices such as hard disks and for transferring data on the Internet, the
CRC (Cyclic Redundancy Check) method is employed.
2. Take the 2's complement of the total sum, and that is the checksum byte, which becomes the
last byte of the stored information.
3. To perform the checksum operation, add all the bytes, including the checksum byte. The result must be
zero. If it is not zero, one or more bytes of data have been changed (corrupted).
Checksum Program
When the PC is turned on, one of the first things the BIOS does is to test the system ROM. The
code for such a test is stored in the BIOS ROM. The following code segment shows the program
using the checksum method. In the code all the bytes are added together without keeping the
track of carries. Then, the total sum is ORed with itself to see if it is zero. The zero flag is
expected to be set to high upon return from this subroutine. If it is not, the ROM is corrupted.
Microprocessors & Microcontrollers Module 3
The 74S280 chip has 9 inputs and 2 outputs. Depending on whether an even or odd number of
ones appear in the input, the even or odd output is activated (according to following Table).
As shown in Table, if all 9 inputs have an even number of 1 bits, the even output goes high (as in
cases 1 and 4). If the 9 inputs have an odd number of high bits, the odd output goes high (as in
cases 2 and 3).
● If the number of 1s in the byte has changed from even to odd and the 1 from the saved parity
DRAM makes the number of inputs even (case 4 above), the odd output becomes low, which
is inverted and passed to the 74LS74 D flip-flop. This makes Q = 1 and 𝑄= 0, which signals
the NMI to display a parity bit error message on the screen.
It must be noted that, memory access time is not the only factor in slowing down the CPU. The
other factor is the delay associated with signals going through the data and address path.
Delay associated with reading data stored in memory has the following two components:
1. The time taken for address signals to go from CPU pins to memory pins, (going through
decoders and buffers (e.g., 74LS245)); plus the time taken for the data to travel from memory to
CPU, is referred to as a path delay.
2. The memory access time to get the data out of the memory chip. This is the larger (80% of the
read cycle time) of the two components.
The total sum of these two (path delay + memory access time) must equal the memory read cycle
time provided by the CPU.
Microprocessors & Microcontrollers Module 3
74LS138
Decoder
G2A
G2B
G1
A13 000 RAM1
A14
A15
001 RAM2
A16