microprocessor

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

MICRO PROCESSOR

1.Using programmed I/O concept, write a program to input 256 bytes and store them at address 2000H
through 20FFH. Bit 6 of port 10H is connected to the START input of the peripheral device, bit 7 of port
11H to the STATUS output. The device can send data to the CPU through port 12H

Ans :

; Program to input 256 bytes and store them at 2000H through 20FFH

START: MOV 10H, A ; Start input from peripheral device

MOV 20H, A ; Clear data to be input

IN 12H ; Read data from peripheral device

MOV 2000H, A ; Store input data at address 2000H

INC 2000H ; Move to next address

LOOP 256 ; Repeat 256 times

2. Using programmed I/O concept, write a program to output 256 bytes from memory locations 2000H
through 20FFH. Bit 6 of port 10H is connected to the START bit of the peripheral device, bit 7 of port 11H
to the STATUS output. The device can receive data from the CPU through port 12H.

Ans : ; Program to output 256 bytes from memory location 2000H through 20FFH

START: MOV 10H, A ; Start output to peripheral device

MOV A, 2000H ; Load first byte from memory

OUT 12H ; Send data to peripheral device

INC 2000H ; Move to next byte in memory

LOOP 256 ; Repeat 256 times

3 . Explain what is direct memory access and where is its application?

Ans : Direct Memory Access (DMA) is a system feature that allows peripherals (like hard drives, sound cards,
etc.) to access the computer's memory directly, without involving the CPU. DMA is used for high-speed data
transfer, which improves the efficiency of memory operations. Applications include disk storage access,
audio/video streaming, and network communication.

5. Explain the various modes of operation of PPI 8255.

Ans : The PPI 8255 can operate in three modes:

Mode 0: Basic I/O mode (simple input/output with no handshake).

Mode 1: Strobed input/output (with handshaking signals).

Mode 2: Bi-directional bus mode (data can be transferred both ways on the same port).
6. Write a program that takes an input from port A and port B and after detecting if any of them are zeros,
sends high value at pin 4 of port C.

Ans :

; Program to detect zero in port A or B and set port C

START: IN A0H ; Input from port A

IN B0H ; Input from port B

OR A ; Check if any zero in port A

OR B ; Check if any zero in port B

JZ ZERO_DETECTED

MOV C4, 1 ; Send high value to pin 4 of port C

ZERO_DETECTED:

RET

7. Write initialization instruction for the 8255 to set-up port A as an output port in mode 0, port B as an
output port in mode 1, and port C as an output port.

Ans : ; Initialization for PPI 8255

MOV A, 80H ; Set port A as output (mode 0)

OUT 03H ; Send to control register

MOV A, 10H ; Set port B as output in mode 1

OUT 03H

MOV A, 30H ; Set port C as output

OUT 03H

8. Write short notes on the following:

Ans : i. Program Input/Output: Programmed I/O (PIO) refers to a method of communication between the
CPU and peripheral devices using software-controlled commands. The CPU sends and receives data directly
with the I/O device through the corresponding port.

ii. Serial Input and Serial Output: Serial input/output (I/O) refers to transmitting data bit by bit over a
single data line, in contrast to parallel transmission where multiple bits are sent simultaneously. This is used
for communication over long distances or with limited data transfer rates.

iii. Direct Memory Access (DMA): Direct Memory Access allows peripherals to access memory directly,
bypassing the CPU to speed up data transfer. It is commonly used in systems that require large data
transfers like disk drives, sound cards, and graphics cards.

9. . Explain how the following work:

i. Jump and Call instructions:


Jump Instructions: These are used to transfer the program control to another part of the program. There are
two types:

Unconditional Jump (JMP): The control always jumps to the specified address.

Conditional Jump: The control jumps to a specified address based on a condition (e.g., JZ, JNZ).

Call Instructions: These are used to call a subroutine or function. It stores the return address (next
instruction after CALL) on the stack. The RET instruction is used to return from the subroutine.

ii. Arithmetic and Logic immediates:

Arithmetic Instructions: These include operations like addition, subtraction, increment, and decrement
performed directly with immediate values (e.g., MVI A, 5 adds 5 to the accumulator).
Logic Instructions: These include logical operations like AND, OR, XOR, and NOT, and can work with
immediate values (e.g., ANI 0F performs an AND operation with 0F).

iii. Extended Register Instructions:

These instructions work with the extended set of registers in processors, such as using the HL pair or DE
register pair for data manipulation in larger word sizes. Operations like MOV A, H or MOV H, L fall under this.

iv. Indirect Instructions:

Indirect addressing means using memory locations indirectly through registers like HL or DE to point to the
memory locations. For example, MOV A, M moves the content of the memory addressed by HL to the
accumulator.

10. 2. Explain how the following work:

Ans :

i. Bidirectional Registers:
Bidirectional registers can work in both input and output modes. For example, the 8255 PPI's port A, B, and C
can be configured as either input or output based on the required operation.

ii. Data Transfer Instructions:

Data transfer instructions allow the transfer of data between registers, memory, and I/O ports. Common
instructions include MOV, MVI, LDAX, STAX, IN, and OUT. These instructions do not alter data, just move it
between locations.

11. Write a program to add decimal 345 and 753 (use immediate bytes for that data):

Ans :

; Program to add 345 and 753 in decimal

MVI A, 45H ; Load 345 (in hexadecimal)

ADD 03CH ; Add 753 (in hexadecimal)

HLT
12. How much time delay does this SAP-2 routine produce?

Ans :

MVI B, 0AH

LOOP1:

MVI C, 47H

LOOP2:

DCR C

JNZ LOOP2

DCR B

JNZ LOOP1

RET

The total delay is based on the number of loops. In this case, the program runs 10 times in B and 47 times in
C. Thus, the delay will be 10 x 47 = 470 cycles.

13. Write an assembly language program to add two hexadecimal numbers 34 and 46. The answer is to be
stored in memory location 3000H:

Ans : ; Program to add hexadecimal numbers 34H and 46H

MVI A, 34H ; Load 34H into A

ADD 46H ; Add 46H to A

STA 3000H ; Store result in memory location 3000H

HLT

14. Write a program to copy 256 bytes of data from addresses 2000H to 20FFH to addresses 3000H to
30FFH:

Ans : ; Program to copy 256 bytes from 2000H-20FFH to 3000H-30FFH

LXI H, 2000H ; Load source address 2000H

LXI D, 3000H ; Load destination address 3000H

MOV C, 00H ; Initialize counter to 00H

LOOP:

MOV A, M ; Load byte from source

MOV M, A ; Store byte to destination

INX H ; Increment source address


INX D ; Increment destination address

INX C ; Increment counter

JNZ LOOP ; Repeat until 256 bytes

HLT

15. Write a program to copy 1024 bytes of data from 5000H to 53FFH to 9000H to 93FFH:

Ans : ; Program to copy 1024 bytes from 5000H-53FFH to 9000H-93FFH

LXI H, 5000H ; Load source address 5000H

LXI D, 9000H ; Load destination address 9000H

MOV C, 00H ; Initialize counter

LOOP:

MOV A, M ; Load byte from source

MOV M, A ; Store byte to destination

INX H ; Increment source address

INX D ; Increment destination address

INX C ; Increment counter

JNZ LOOP ; Repeat until 1024 bytes

HLT

16. Explain what the following program is doing:

LXI H, 2500H ; Load HL pair with address 2500H

MOV C, M ; Load memory content at 2500H into register C

INX H ; Increment HL pair to point to next memory location

MOV B, M ; Load content from address 2501H into B

MVI A, 00H ; Clear accumulator

LOOP:

ADD C ; Add C to accumulator

DCR B ; Decrement B

JNZ LOOP ; Loop if B is not zero

INX H ; Increment HL pair to point to next memory

MOV M, A ; Store accumulator to memory at HL


HLT

This program adds the values stored at consecutive memory locations, starting from 2500H. It loads the first
value from 2500H into register C, then adds it to A, stores the result back to memory, and continues for a
total of B iterations.

17. Write a program for an 8085 microprocessor to produce a delay of 1 second using a 1MHz clock:

Ans :

; Program to generate 1 second delay using 1 MHz clock

MVI C, 0FFH ; Load the counter with 255

LOOP:

NOP ; No operation (takes 1 clock cycle)

NOP

DCR C

JNZ LOOP ; Repeat until counter is zero

HLT

Each NOP instruction takes one clock cycle, and the program uses the counter to create a delay. With a 1
MHz clock, it takes 1 second for the loop to complete.

18. Determine the hexadecimal number left in the accumulator and the state of the carry flag after the
execution of the following program:

MVI A, 6FH ; Load 6FH into A

MVI B, 4AH ; Load 4AH into B

ANI 44H ; Perform AND with 44H

RAL ; Rotate accumulator left

HLT

Ans : Let's break down the instructions and analyze the state of the accumulator and carry flag step by
step.

Initial values:

- *MVI A, 6FH*: This loads 6F (0110 1111 in binary) into the accumulator A.

- *MVI B, 4AH*: This loads 4A (0100 1010 in binary) into register B.

First operation:

- *ANI 44H*: This performs a bitwise AND between the accumulator A (which holds 6F or 0110 1111) and
44H (which is 0100 0100 in binary).

The result of the AND operation is:


0110 1111 (6F)

0100 0100 (44H)

-----------

0100 0100 (44H)

So, after the ANI instruction, the accumulator A will hold 44H (0100 0100 in binary), and the carry flag will be
unaffected (it remains as it was before the operation).

Second operation:

RAL: The RAL (Rotate Accumulator Left) instruction rotates the contents of the accumulator left by one bit,
and the carry flag is shifted into the rightmost bit of the accumulator.

Before the RAL, the accumulator contains 44H (which is 0100 0100 in binary). When rotated left, the result
will be:

- The leftmost bit (0) will be moved to the carry flag.

- The rest of the bits shift one position to the left.

So the new value of the accumulator becomes:

1000 1000 (88H)

And the carry flag will hold the leftmost bit of the original accumulator value (which was 0).

Final state:

- The value in the accumulator is 88H.

- The carry flag is 0.

Thus, after the program execution:

- The *accumulator* contains 88H.

- The *carry flag* is 0.

19. What is the function of the stack pointer in 8085? Explain its use in writing programs.

Ans : Stack Pointer: The stack pointer (SP) in the 8085 is a 16-bit register that holds the address of the top
element in the stack. The stack is used to store data temporarily, particularly for function calls and storing
return addresses. When a CALL instruction is executed, the return address is pushed onto the stack, and
when RET is encountered, the return address is popped from the stack to resume execution.

Question 20:

What is the function of the stack pointer in 8085? Explain its use in writing programs.

Answer:
The stack pointer (SP) in the 8085 microprocessor is a 16-bit register that holds the memory address of the
top of the stack.
 Function: It is used to keep track of the stack, which is a portion of memory used for temporary
storage during program execution. The stack operates on a Last In First Out (LIFO) basis.

 Use in Writing Programs:

o PUSH operation: SP is decremented, and the data is stored at the memory location pointed
to by SP.

o POP operation: Data is retrieved from the stack, and SP is incremented.

o It is used for saving return addresses during subroutine calls, saving register contents, and
managing interrupts.

Question 21:

Explain the effect of the sequence of instructions:


PUSH D, PUSH B, POP D, POP B

Answer:

1. PUSH D: The contents of register pair D (D and E) are stored in the stack. SP is decremented twice.

2. PUSH B: The contents of register pair B (B and C) are stored in the stack. SP is decremented twice.

3. POP D: The data at the memory locations pointed to by SP is loaded into register pair D (D and E). SP
is incremented twice.
4. POP B: The data at the memory locations pointed to by SP is loaded into register pair B (B and C). SP
is incremented twice.

Result: The values of register pairs B and D are swapped using the stack.

Q24: Timing diagram for opcode MOV C, A (4FH) stored in location 2005H being fetched.

 Steps:

1. Address 2005H is placed on the address bus.

2. ALE signal is enabled to latch the address.

3. RD signal is activated to read data (opcode).

4. Data (4FH) is placed on the data bus and transferred to the microprocessor.

Timing Diagram: Include T-states (T1, T2, T3) showing the operations of the address bus, data bus, ALE, RD,
and IO/M signals.

Q25: Timing diagram for MVI A, 32H.

 Opcode Fetch: Fetch the opcode for MVI A.


 Memory Read: Read the immediate data 32H from the next memory location.
Timing diagram involves T1, T2, and T3 cycles for both fetch and memory read operations.
Q5, Q6, Q7, Q8: Explain and draw timing diagrams for register, indirect, and immediate addressing modes.
Refer to standard textbooks for diagrams and explanations:

 MOV reg1, reg2: Copies data between registers in one machine cycle.

 MOV reg, M: Reads data from a memory location.

MOV M, reg: Writes data to a memory location.

 OUT port: Sends data to an I/O port.

Q29:

 XCHG: Exchanges contents of register pairs D and H.

 STAX B: Stores accumulator content in the memory location pointed to by register pair B.

 LDAX B: Loads accumulator content from the memory location pointed to by register pair B.

 LHLD address: Loads H and L registers with data from a specified memory address.

 SHLD address: Stores H and L register contents into a specified memory address.

 PCHL: Loads the program counter with the contents of register pair H.

 SPHL: Copies the contents of the H-L pair to the stack pointer.

 XTHL: Exchanges the contents of the H-L pair with the top of the stack.

Q30: What does the program do?

MVI A, 39H

ADI 97H

DAA

HLT

 MVI A, 39H: Load 39H into the accumulator.

 ADI 97H: Add 97H to the accumulator (result = D0H).

 DAA: Adjust the result for Binary-Coded Decimal (BCD). Adjusts D0H to 00H and increments carry.

 HLT: Halts the program.

Result: The program performs addition in BCD and halts. Final result = 36H in BCD.

Construct a simple microprocessor and explain its working


Components:

Program Counter (PC): Points to the next instruction to fetch.

Memory Address Register (MAR): Holds the address of memory locations.

RAM: Stores instructions and data.


Instruction Register (IR): Temporarily holds the fetched instruction.

Controller: Coordinates the operation of the processor.

Accumulator (A): Holds intermediate results.

Adder/Subtractor: Performs arithmetic operations.

B-register: Holds secondary data for operations.

Output Register: Stores the final output for display.

LED Display: Displays the final results.

Working:
Fetch the instruction using the PC.

Decode the instruction in the IR.

Perform arithmetic/logic operations using the accumulator, B-register, and adder/subtractor.

Send results to the output register and display on the LED.

Communication Paths:

Data flows between memory, registers, and ALU via buses.

Control signals manage data transfers and ALU operations.

Instruction Set of a Microprocessor

The *instruction set* of a microprocessor refers to a collection of commands or instructions that the
processor can understand and execute. These instructions are designed to perform various tasks such as
data manipulation, arithmetic operations, control flow, and input/output operations. Each instruction
typically corresponds to a specific operation, and its structure depends on the microprocessor's architecture
(e.g., 8-bit, 16-bit).

The instructions in the set are encoded in machine language, and the microprocessor executes them as part
of its instruction cycle.

### *Operations of Specific Instructions*

i. LDA addr (Load Accumulator)*


- *Operation:* The *LDA* instruction loads data from a specific memory address into the *Accumulator* (A).
This instruction is used to retrieve data from memory and store it in the accumulator for processing.

- *Explanation:*

- The *Program Counter (PC)* points to the address where the instruction is located.

- The *Memory Address Register (MAR)* gets the address of the memory location that holds the data.
- The *Control Unit* signals the memory to send data to the *Accumulator*.

Pseudo-code:*

MAR ← addr // Load the address of the data

A ← Memory[MAR] // Load data from memory into the Accumulator

- *Example:*

If addr = 1000, the value at memory location 1000 is loaded into the Accumulator.

ii. SUB (Subtract)*

- *Operation:* The *SUB* instruction performs subtraction. It subtracts the value stored in the *B-register*
from the value in the *Accumulator* and stores the result back in the *Accumulator*.

- *Explanation:*

- The *Accumulator (A)* holds the initial value.

- The *B-register* holds the second operand.

- The *Control Unit* generates the subtraction operation using the *ALU* (Arithmetic Logic Unit).

- *Pseudo-code:*

A ← A - B // Subtract the value in the B-register from the Accumulator

- *Example:*

If A = 15 and B = 5, after the SUB instruction, A will be 10.

iii. ADD (Add)

- *Operation:* The *ADD* instruction performs addition. It adds the value in the *B-register* to the value in
the *Accumulator, and the result is stored back in the **Accumulator*.

- *Explanation:*

- The *Accumulator (A)* holds one operand.

- The *B-register* holds the second operand.

- The *Control Unit* signals the *ALU* to perform the addition.

- *Pseudo-code:*

A ← A + B // Add the value in the B-register to the Accumulator


- *Example:*

If A = 7 and B = 3, after the ADD instruction, A will be 10.

#### *iv. OUT (Output)*

- *Operation:* The *OUT* instruction transfers the value from the *Accumulator* to an *output device*
(e.g., an output register or display).

- *Explanation:*

- The *Control Unit* initiates the transfer of the value in the *Accumulator* to the *Output Register*.

- The value is then sent to an external device for display or further processing.

- *Pseudo-code:*

Output_Register ← A // Transfer the value of the Accumulator to the Output Register

- *Example:*

If A = 12, the value 12 will be sent to the *Output Register* for display on a *LED display* or other output
device.

#### *v. HLT (Halt)*


- *Operation:* The *HLT* instruction halts the execution of the program. It is typically used to signal the end
of the program or to stop further processing.

- *Explanation:* - When the *HLT* instruction is executed, the microprocessor stops fetching and executing
further instructions.

- The processor enters a halted state until a reset or power cycle occurs.

Pseudo code Stop Execution // Halts further execution of instructions

- *Example:*

Once the HLT instruction is executed, the microprocessor ceases to perform any operations and waits for a
reset signal to begin execution again.

Definitions
i. Instruction Cycle: The complete process of fetching, decoding, and executing an instruction.

ii. Machine Cycle: Subset of the instruction cycle that involves data transfers or memory accesses.

iii. Fetch Cycle: Part of the instruction cycle where the processor retrieves the instruction from memory.

iv. Execution Cycle: The phase where the fetched instruction is executed

Pin Diagram of Microprocessor 8085


Some Important codes

1.Multiplication of two 8-bit numbers

Ans-

; Multiplication of two 8-bit numbers (A * B)

MVI A, 10H ; Load first number into A (multiplicand)

MVI B, 05H ; Load second number into B (multiplier)

MVI C, 00H ; Clear C (for result)

MVI D, 00H ; Clear D (for result)

Loop:

MOV E, B ; Copy multiplier to E

JZ Done ; If B == 0, exit

ADD C ; Add current multiplicand to result

MOV C, A ; Save new result to C

MOV A, E ; Restore multiplier

DCR B ; Decrement multiplier

JMP Loop ; Repeat loop

Done:

HLT

2.Division of two 8-bit numbers

Ans –

; Division of two 8-bit numbers (A / B)

MVI A, 20H ; Load numerator into A

MVI B, 05H ; Load denominator into B

MVI C, 00H ; Clear C (quotient)

MVI D, 00H ; Clear D (remainder)

Loop:

CMP B ; Compare A with B

JC NoSubtract ; If A < B, skip subtraction

SUB B ; Subtract B from A


INX C ; Increment quotient

NoSubtract:

MOV A, D ; Restore A for next subtraction

MOV B, C ; Restore quotient for next iteration

JMP Loop

HLT

3. 1’s complement using 8bit and 16bit number

Ans

1's complement of an 8-bit number

MVI A, 55H ; Load number into A

CMA ; A = NOT A (1's complement)

HLT;

1's complement of a 16-bit number

; A = upper byte, B = lower byte

MVI A, 55H ; Load upper byte of number into A

MVI B, 00H ; Load lower byte of number into B

CMA ; A = NOT A (1's complement)

CMB ; B = NOT B (1's complement)

HLT

4. 2’s complement using 8bit and 16bit number

Ans

2's complement of an 8-bit number

MVI A, 55H ; Load number into A

CMA ; A = NOT A (1's complement)

INR A ; A = A + 1 (2's complement)

HLT

2's complement of a 16-bit number

; A = upper byte, B = lower byte

MVI A, 55H ; Load upper byte of number into A

MVI B, 00H ; Load lower byte of number into B

CMA ; A = NOT A (1's complement)


CMB ; B = NOT B (1's complement)

INR A ; A = A + 1 (2's complement)

INR B ; B = B + 1 (2's complement)

HLT

5.Write a program to arrange first 10 numbers from memory address 3000H in an ascending order.

MVI B, 09 :"Initialize counter"

START :"LXI H, 3000H: Initialize memory pointer"

MVI C, 09H :"Initialize counter 2"

BACK: MOV A, M :"Get the number"

INX H :"Increment memory pointer"

CMP M :"Compare number with next number"

JC SKIP :"If less, don’t interchange"

JZ SKIP :"If equal, don’t interchange"

MOV D, M

MOV M, A

DCX H

MOV M, D

INX H :"Interchange two numbers"

SKIP:DCR C :"Decrement counter 2"

JNZ BACK :"If not zero, repeat"

DCR B :"Decrement counter 1"

JNZ START

HLT :"Terminate program execution"

6.Write a program to exchange the data at 5000M& 6000M memory location.

LDA 5000M : "Getting the contents at5000M location into accumulator"

MOV B, A : "Save the contents into B register"

LDA 6000M : "Getting the contents at 6000M location into accumulator"

STA 5000M : "Store the contents of accumulator at address 5000M"

MOV A, B : "Get the saved contents back into A register"

STA 6000M : "Store the contents of accumulator at address 6000M"


7.Write a program to add data at 3005H & 3006H memory location and store the result at 3007H memory
location.

Problem demo:

(3005H) = 14H

(3006H) = 89H

Result = 14H + 89H = 9DH

The program code can be written like this:

LXI H 3005H : "HL points 3005H"

MOV A, M : "Getting first operand"

INX H : "HL points 3006H"

ADD M : "Add second operand"

8.Program to transfer a block of data from one memory location to another.

START: LXI D, 4000H ; Load the address of the memory location containing the
length

MOV C, M ; Load the length of the block into register C

LXI H, 2000H ; Load the starting address of the source memory block into
HL pair

LXI D, 3000H ; Load the starting address of the destination memory block
into DE pair

LOOP: MOV A, M ; Move the data from the source memory into the
accumulator

STAX D ; Store the data into the destination memory

INX H ; Increment the HL pair to point to the next source memory


location

INX D ; Increment the DE pair to point to the next destination memory


location

DCR C ; Decrement the counter (length of block)

JNZ LOOP ; Repeat the process until the counter becomes zero

HLT ; Halt the program

Source block - 2000H to 2004H contains 10H,20H,30H,40H,50H

Destination block – 3000H to 3004H

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy