microprocessor
microprocessor
microprocessor
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
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
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.
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 :
JZ ZERO_DETECTED
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.
OUT 03H
OUT 03H
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.
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.
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).
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.
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.
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.
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 :
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:
HLT
14. Write a program to copy 256 bytes of data from addresses 2000H to 20FFH to addresses 3000H to
30FFH:
LOOP:
HLT
15. Write a program to copy 1024 bytes of data from 5000H to 53FFH to 9000H to 93FFH:
LOOP:
HLT
LOOP:
DCR B ; Decrement B
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 :
LOOP:
NOP
DCR C
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:
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.
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).
-----------
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:
And the carry flag will hold the leftmost bit of the original accumulator value (which was 0).
Final state:
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.
o PUSH operation: SP is decremented, and the data is stored at the memory location pointed
to by SP.
o It is used for saving return addresses during subroutine calls, saving register contents, and
managing interrupts.
Question 21:
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:
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.
MOV reg1, reg2: Copies data between registers in one machine cycle.
Q29:
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.
MVI A, 39H
ADI 97H
DAA
HLT
DAA: Adjust the result for Binary-Coded Decimal (BCD). Adjusts D0H to 00H and increments carry.
Result: The program performs addition in BCD and halts. Final result = 36H in BCD.
Working:
Fetch the instruction using the PC.
Communication Paths:
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.
- *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:*
- *Example:*
If addr = 1000, the value at memory location 1000 is loaded into the Accumulator.
- *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 *Control Unit* generates the subtraction operation using the *ALU* (Arithmetic Logic Unit).
- *Pseudo-code:*
- *Example:*
- *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:*
- *Pseudo-code:*
- *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:*
- *Example:*
If A = 12, the value 12 will be sent to the *Output Register* for display on a *LED display* or other output
device.
- *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.
- *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
Ans-
Loop:
JZ Done ; If B == 0, exit
Done:
HLT
Ans –
Loop:
NoSubtract:
JMP Loop
HLT
Ans
HLT;
HLT
Ans
HLT
HLT
5.Write a program to arrange first 10 numbers from memory address 3000H in an ascending order.
MOV D, M
MOV M, A
DCX H
MOV M, D
JNZ START
Problem demo:
(3005H) = 14H
(3006H) = 89H
START: LXI D, 4000H ; Load the address of the memory location containing the
length
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
JNZ LOOP ; Repeat the process until the counter becomes zero