Revision Microprocessor PDF
Revision Microprocessor PDF
SECTION A
Question 1
(a) List and describe the flag bits available in the 8085 microprocessor.
- Sign Flag (S): This flag is set if the result of an arithmetic operation is negative.
- Zero Flag (Z): This flag is set if the result of an arithmetic operation is zero.
- Auxiliary Carry Flag (AC): This flag is set if there is a carry from the lower nibble (4 bits) to
the upper nibble during an arithmetic operation.
- Parity Flag (P): This flag is set if the number of 1s in the result of an operation is even.
- Carry Flag (CY): This flag is set if there is a carry from the most significant bit during an
arithmetic operation.
(b) List all FOUR (4) types of data transfer group for the 8085 microprocessor instructions set. Give
an example of instruction for each type.
- Register-to-register transfer: These instructions transfer data from one register to another.
An example of this type of instruction is MOV A, B, which transfers the contents of register B
to register A.
- A stack is a linear data structure that implements a collection of elements, with two main
operations:
- "Last-In First-Out" (LIFO) is a property of a stack, which means that the last element added
to the stack is the first one to be removed. This is due to the fact that elements are added
and removed from the top of the stack only.
- Instruction Cycle: The instruction cycle refers to the series of steps that the CPU follows in
order to execute a single instruction from a program. This cycle includes the following steps:
This cycle is repeated for every instruction in a program until the program terminates or is
interrupted.
- Machine Cycle: The machine cycle refers to the timing of the signals and operations within a
single instruction cycle. It defines the timing and sequence of signals that control the
transfer of data and the execution of instructions.
- State: The state of the CPU refers to the internal state of the processor at a particular point
in time, including the values stored in its registers, the status of its flags, and the location of
the current instruction. The state of the CPU changes as it executes instructions, and the
sequence of states that a CPU goes through during the execution of a program can be
thought of as a state machine.
(e) Sketch the timing diagram when the microprocessor fetches and execute the instruction MOV
M, A at memory location 1020H.
1. The microprocessor first fetches the instruction from memory location 1020H. The
instruction is stored in the instruction register (IR) of the microprocessor.
3. The microprocessor retrieves the contents of the Accumulator (A) and stores it in the
temporary register.
4. The microprocessor retrieves the memory address pointed to by the HL register pair and
stores it in the memory data register (MDR).
5. The microprocessor transfers the contents of the temporary register to the memory location
pointed to by the MDR.
6. The microprocessor increments the program counter (PC) to the next memory location,
which holds the next instruction to be executed.
7. The cycle repeats itself, with the next instruction being fetched and executed in a similar
manner.
Question 2
(a) Develop an assembly language program based on the following statement.
(i) Write value AAH to memory locations 4000H, 4002H and 4004H
(ii) Data in B register is AND's with data in D register and the result is store to E register
AND B, D
MOV E, B
(iii) Exchange the contents of memory locations 3000H and 3002H.
(iv) Read two 8-bit data from port address FOH and FIH. Add both data and send to port
address F2H.
MOV AL, [FOH];// Read the first 8-bit data from port address FOH
ADD AL, [FIH]; //Read the second 8-bit data from port address FIH and add it to the first
data
MOV [F2H], AL; //Send the result to port address F2H
(b) Given the following sub-routine to convert two-digit BCD numbers in memory to the equivalent
HEX number.
(ii) Calculate the executing time for the sub-routine if the 8085 microprocessor is driven by
5 MHz crystal.
The 8085 microprocessor has a clock speed of 5 MHz, meaning it can execute 5 million
clock cycles per second.
For the given sub-routine, the following is the number of clock cycles required by each
instruction:
To convert this to time, we divide the number of clock cycles by the clock speed of the
processor:
55 clock cycles / 5 million clock cycles per second = 0.000011 seconds or approximately
11 microseconds.
Question 3
(a)
(i) Explain the process of enabling, disabling and masking RST5.5, RST6.5 and RST 7.5 of the
8085 microprocessor interrupts.
The 8085 microprocessor has five maskable interrupts, including RST 5.5, RST 6.5, and RST 7.5.
- Enabling Interrupts:
To enable an interrupt in the 8085, the corresponding bit in the Interrupt Enable Register (IE)
must be set to 1. The IE register is an 8-bit register, and each bit in the register corresponds
to a specific interrupt. For example, to enable RST 5.5, the 3rd bit in the IE register must be
set to 1.
- Disabling Interrupts:
To disable an interrupt, the corresponding bit in the IE register must be set to 0. For example,
to disable RST 5.5, the 3rd bit in the IE register must be set to 0.
- Masking Interrupts:
Interrupts can also be masked by setting the Interrupt Mask Register (IMR). The IMR register
is also an 8-bit register and operates similarly to the IE register, with each bit corresponding
to a specific interrupt. To mask an interrupt, the corresponding bit in the IMR register must
be set to 1. When an interrupt is masked, it will not be executed even if it is enabled.
(iii) Figure 3.1 below show a continuous 100 Hz square wave signal is connected to RST7.S
interrupt pin. If the RST7.5 interrupt is enabled, the microprocessor will be interrupted
for every 10 ms. This technique is called event timer and can be used in timer-based
applications instead of software delay. Using this technique, develop a program to toggle
port peo ON and OFF for every 1 second.
(b) The basic microprocessor system is to be designed based on the following components
• 8085 microprocessor
• Two (2) unit of2K x 8 bit RAM started at location 4000H
• One (I) unit 4K x 8 bit EPROM started at location OOOOH
(ii) Design the decoding circuit for the memory system using any combinational logic or
decoder chip.
(iii) Complete the wire connections of the components so that the basic system is functional.
You can add-on other components as needed.
1. Connect the data bus (D0-D7) and address bus (A0-A15) of the 8085 microprocessor
to the data bus and address bus of the EPROM, RAM1, and RAM2.
2. Connect the chip select (CS) signals from the decoding circuit to the chip select inputs
of the EPROM, RAM1, and RAM2.
3. Connect the read/write (R/W) signal from the 8085 to the R/W inputs of the EPROM,
RAM1, and RAM2.
4. Connect the ready signal from the RAM chips to the interrupt (INTR) pin of the 8085,
if needed.
6. You may also need to connect the clock signal (CLK) from an oscillator to the 8085
and the memory chips.
SECTION B
Question 4
Figure 4.1 below shows an IC tester system based on 8085 microprocessor for an OR gate. The
microprocessor will output an 8-bit logic pattern at Port C to the input of the device and read the output
at Port B. The required 8-bit logic patterns generated in sequence by the microprocessor is based on the
OR gate truth table: 00000000, 01010101, 10101010 and 11111111. A common anode seven segment
display unit connected at Port A will display 'P' (PASS) if the gate is in good condition. Otherwise, it will
display 'F' (Fail) if the gate is in failure condition. The IC tester system will start to operate whenever the
pushbutton connected at PC7 is pressed.
(a) Sketch the complete interface circuit for pushbutton switch and seven segment display with
microprocessor system.
(b) Construct a flowchart or pseudo code for the system.
START
Initialize Port A as output for 7 segment displays
Initialize Port B as input for OR gate output
Initialize Port C as output for OR gate input
Clear Port C
Wait for pushbutton press at PC7
FOR i = 0 to 7
Output logic pattern at Port C based on OR gate truth table
Read output at Port B
Compare with expected result
If match, continue
If not match, display 'F' at Port A and go to END
END FOR
Display 'P' at Port A
END
; Initialize Ports
MVI C, 00h ; Clear Port C
OUT C ; Output to Port C
MVI B, 00h ; Clear Port B
IN B ; Input from Port B
MVI A, 0C0h ; Initialize Port A for 7 segment display
OUT A ; Output to Port A
SECTION A
Question 1
(a) Stack is temporary memory storage. Explain the method used to store the data in stack and
briefly explain the function of stack pointer.
(i) After executing this program, determine the content in register B, C, D and E
After executing these programs, the content in register B would be 0304H, in register C would
be undefined, in register D would be 0102H, and in register E would be undefined.
(ii) Based on programming, Specify the content of the stack by sketching a diagram of stack.
The stack diagram should contain the address and the data contain of stack.
Address | Data
2FFF | 0102H
2FFE | 0302H
2FFD | 0304H
Initially, the stack pointer SP points to address 3000H and the stack grows downwards, so
after pushing B and D onto the stack, the stack pointer moves downwards to address 2FFF
and the stack content is as shown above. When the POP instruction is executed, the data at
the top of the stack is popped out and loaded into the specified register, so the content of B
is 0304H and the content of D is 0102H.
(c) List and describe the flag bits available in the 8085 microprocessor.
- Sign flag (S): This flag indicates the sign of the result of an arithmetic operation. If the most
significant bit of the result is set, the sign flag is set, indicating a negative result. If the most
significant bit is clear, the sign flag is cleared, indicating a positive result.
- Zero flag (Z): This flag indicates whether the result of an arithmetic or logical operation is
zero. If the result is zero, the zero flag is set, indicating that the operation has produced no
result. If the result is non-zero, the zero flag is cleared.
- Carry flag (CY): This flag indicates whether an arithmetic operation has produced a carry out
of the most significant bit. If a carry occurs, the carry flag is set, indicating that the result has
overflowed. If no carry occurs, the carry flag is cleared.
- Parity flag (P): This flag indicates the parity of the result of an arithmetic or logical operation.
If the number of set bits in the result is even, the parity flag is set, indicating an even parity.
If the number of set bits is odd, the parity flag is cleared, indicating an odd parity.
- Auxiliary carry flag (AC): This flag indicates whether a carry has occurred from bit 3 to bit 4
during an arithmetic operation. This flag is used for BCD arithmetic. If a carry occurs, the
auxiliary carry flag is set, indicating that a correction should be made to the result. If no
carry occurs, the auxiliary carry flag is cleared.
(d) Explain program counter, instruction cycle, machine cycle and T-state.
- Program Counter (PC): It is a register in the CPU that stores the memory address of the next
instruction to be executed. It increments the address after each instruction is executed, so
that the next instruction is fetched and executed in the following cycle.
- Instruction Cycle: It is the complete process of fetching an instruction, decoding it, executing
it and storing the result in memory. It is also referred to as the fetch-decode-execute cycle.
- Machine Cycle: It is the time taken to complete one instruction cycle. It is made up of a
number of clock cycles and is dependent on the clock speed of the CPU.
(a) Briefly describe what is machine language programming and what language a microprocessor is
recognizes.
Operands: One or more binary codes that specify the data or memory location to
be operated on. For example, in an addition operation, the operands would
specify the two numbers to be added.
Address: An optional component that specifies the memory location where the
instruction is stored.
(ii) State an example each of the different types of instructions below:
a) Direct
An example of a direct instruction in a high-level programming language is a
move or copy operation, such as "MOVE X, Y" or "X = Y", which transfers the
value stored in one location (Y) to another location (X).
b) Immediate
An example of an immediate instruction in a high-level programming language
is a load constant operation, such as "LOAD #10", which loads a constant value
(10) into a register or memory location.
c) Implicit
An example of an implicit instruction in a high-level programming language is
a type coercion, such as "X = 10", where the value 10 is automatically
converted to the type of the target location (X). In this example, the type
coercion instruction is implicit and not explicitly stated in the code.
(c) Assembly language statements are written in standard format, explain each of the
standard format below with the support from any related example:
(i) Label
A label is a user-defined string that represents a location in memory where a
specific instruction or data value is stored. In assembly language, a label is used to
identify a specific memory address that can be referred to by other instructions.
The label is typically followed by a colon to distinguish it from other elements in
the instruction.
LOOP:
DELAY:
(ii) Mnemonic
A mnemonic is a short code that represents a specific machine instruction.
Mnemonics are used to make the assembly language instructions easier to read
and understand for humans.
MOV A, B
Mnemonic = MOV
(iii) Operand
An operand is a value that is used as input to an instruction. In assembly language,
an instruction typically requires one or more operands to specify the data that is
being operated on. The operand can be a register, memory address, or constant
value.
MOV B, 20H
Operand = 20H
(iv) Comment
A comment is a line of text that provides additional information about the code,
but is not executed as part of the program. Comments are used to explain the
purpose of a section of code or to provide additional information about a specific
instruction. In assembly language, comments are typically preceded by a
semicolon (;) or another special symbol to distinguish them from other parts of
the instruction.
• In this example, the comment "move the contents of BX into AX" provides
additional information about the purpose of the instruction.
(d) The program in Table 1 shows machine codes and memory locations to store the program. By
referring Appendix, A, convert the mnemonics given to the missing hex code and identify the
memory location each of the machine code stored.
(i) List ports available on this chip and state the address of each port.
Port A: 80H
Port B: 81H
Port C: 82H
(ii) Briefly explain the function of mode 0 and mode 1 in this 8255A chip.
Mode 0
- known as the basic input/output mode, which provides 8-bit input
and output operations.
- Port A can be used as an input port, Port B can be used as an output
port, and Port C is divided into two 4-bit sections, one for input and
one for output.
Mode 1
- known as the Strobed Input/Output mode, which provides 8-bit input
and output operations.
- Port A and Port B can be used as either input or output ports, while
Port C is divided into two 4-bit sections, one for input and one for
output. In this mode, the input and output operations are performed
under the control of a strobe signal.
(iii) Write a code to set all port to input port and using mode 0. Assume 8255 chip using 80H
as a base address.
This code first loads the value 0C0H into register C, which represents the
enable/disable status of the interrupts. The bit values 1 and 0 indicate the
enable/disable status of each interrupt. The code sets bit 6 and 7 to 1 to enable
RST 6.5 and RST 7.5, respectively. It sets bit 5 to 0 to disable RST 5.5. Finally,
the code sends the contents of register C to port 0FFH, which is the interrupt
control register. This updates the interrupt enable/disable status.
(c) The 8085 microprocessor have two lines specially designed for serial data
transfer.
Asynchronous Serial Data Transfer: This method of serial data transfer uses starts
and stop bits to synchronize the transfer of data between the transmitting and
receiving devices. The start bit signals the beginning of the transmission, and the
stop bit signals the end. The data is transmitted one bit at a time.
(ii) By using 4800 bit/s as a baud rate and 10 MHz for value of crystal, write a
complete code to send a serial 8 bit data. Show your calculation as well.
; Initialize the serial port
OUT 0EH ; Send the value to port 0EH to set the baud rate
OUT 0FH ; Send the value to port 0FH to set the baud rate
RLC
OUT 10H
RLC
OUT 10H
RLC
OUT 10H
RLC
OUT 10H
RLC
OUT 10H
RLC
OUT 10H
baud rate = crystal frequency / (16 * (baud rate generator value + 1))
Given the crystal frequency of 10 MHz and a baud rate of 4800 bit/s, we can calculate
the baud rate generator value as follows:
Question 3
(a) Develop an assembly language program based on the following statement.
(i) Transfer the data from memory location 2100H to B register, 3100H to C register, then
do the “AND” operation value in B register with the value in C register, store the result
into memory location 4001H.
MOV BX, 2100H ; Move data from memory location 2100H to BX register
MOV CX, 3100H ; Move data from memory location 3100H to CX register
AND BX, CX ; Perform AND operation between BX and CX
MOV [4001H], BX ; Store result in memory location 4001H
(ii) By using minimum instruction, swap 4 bit lower with 4 bit upper data in memory
location 3500H and store the result into memory location 3501H .
MOV AX, [3500H] ; Move data from memory location 3500H to AX register
MOV BX, 0FH ; Move 0FH to BX register (used for masking)
AND AX, BX ; Mask the lower 4 bits of AX and store in AX
SHR AX, 4 ; Shift the masked lower 4 bits to right by 4 bits
MOV BX, [3500H] ; Move data from memory location 3500H to BX register
AND BX, 0F0H ; Mask the upper 4 bits of BX and store in BX
SHL BX, 4 ; Shift the masked upper 4 bits to left by 4 bits
OR AX, BX ; Perform OR operation between masked lower and upper bits
MOV [3501H], AX ; Store the result in memory location 3501H
(i) By using 10 MHz crystal, calculate the total time needed to complete the delay sub-
routine. Refer to Appendix A.
(ii) By using the same crystal (10 MHz), modify the delay sub-routine to make a 250 mS
delay. Write the complete program of the new delay subroutine by using the assembly
language.
The number of times the loop should run can be calculated as:
Number of times the loop runs = 250 milliseconds / (15 cycles / 10 MHz) = 166666.67
Since the number of times the loop runs needs to be an integer, we can round it up to
the nearest integer. Therefore, the number of times the loop should run is:
NOTE MICROPROCESSOR
CPU SEQUENCING
7 machine cycles:
Find the time needed to process STA add. Instruction if frequency of oscillator = 10MHz
T =1/f
T =1/10MHz
=1.3uS
HALT State
- The T-halt state is entered after execution of the HLT instruction. The
instruction is executed in the T4-state of the opcode fetch machine cycle by
the processor setting the internal halt flip-flop.
LOOP – LABEL
MVI – MNEMONIC
20H – OPERAND
Move data between registers or between memory locations and registers. Includes
moves, loads, stores and exchanges.
Arithmetic Instruction
Logic Instruction
Branch/Jump Instruction
Includes instructions for maintaining stack, reading from input port, writing to output
port, setting and reading interrupt mask and clearing flags.
Condition
INTERRUPTS
SERIAL COMMUNICATION