Problem - Write An Assembly Language Program To Add Two 8 Bit Numbers Stored at Address 2050 and Address 2051 in 8085
Problem - Write An Assembly Language Program To Add Two 8 Bit Numbers Stored at Address 2050 and Address 2051 in 8085
Problem - Write An Assembly Language Program To Add Two 8 Bit Numbers Stored at Address 2050 and Address 2051 in 8085
in 8085
microprocessor. The starting address of the program is taken as 2000.
Algorithm –
1. Load the first number from memory location 2050 to accumualtor.
2. Move the content of accumulator to register H.
3. Load the second number from memory location 2051 to accumaltor.
4. Then add the content of register H and accumulator using “ADD” instruction and storing result at 3050
5. The carry generated is recovered using “ADC” command and is stored at memory location 3051
Program –
200E HLT
1. LDA 2050 moves the contents of 2050 memory location to the accumulator.
2. MOV H, A copies contents of Accumulator to register H to A
3. LDA 2051 moves the contents of 2051 memory location to the accumulator.
4. ADD H adds contents of A (Accumulator) and H register (F9). The result is stored in A itself. For all arithmetic
instructions A is by default an operand and A stores the result as well
5. MOV L, A copies contents of A (34) to L
6. MVI A 00 moves immediate data (i.e., 00) to A
7. ADC A adds contents of A(00), contents of register specified (i.e A) and carry (1). As ADC is also an arithmetic
operation, A is by default an operand and A stores the result as well
8. MOV H, A copies contents of A (01) to H
9. SHLD 3050 moves the contents of L register (34) in 3050 memory location and contents of H register (01) in 3051
memory location
10. HLT stops executing the program and halts any further execution
Problem – Write an assembly language program to add two 16 bit numbers by using:
(a) 8 bit operation
(b) 16 bit operation
Example –
(a) Addition of 16 bit numbers using 8 bit operation – It is a lengthy method and requires more memory as compared to 16
bit operation.
Algorithm –
1. Load the lower part of first number in B register
2. Load the lower part of second number in A (accumulator)
3. Add both the numbers and store
4. Load the higher part of first number in B register
5. Load the higher part of second number in A (accumulator)
6. Add both the numbers with carry from the lower bytes (if any) and store at the next location
Program –
MEMORY ADDRESS MNEMONICS COMMENTS
Algorithm –
1. Load 00 in a register C (for borrow)
2. Load two 8-bit number from memory into registers
3. Move one number to accumulator
4. Subtract the second number with accumulator
5. If borrow is not equal to 1, go to step 7
6. Increment register for borrow by 1
7. Store accumulator content in memory
8. Move content of register into accumulator
9. Store content of accumulator in other memory location
10. Stop
Program –
MEMORY MNEMONICS OPERANDS COMMENT
Algorithm –
1. Load 0000H into CX register (for borrow)
2. Load the data into AX(accumulator) from memory 3000
3. Load the data into BX register from memory 3002
4. Subtract BX with Accumulator AX
5. Jump if no borrow
6. Increment CX by 1
7. Move data from AX(accumulator) to memory 3004
8. Move data from CX register to memory 3006
9. Stop
Program –
MEMORY MNEMONICS OPERANDS COMMENT
Data tranfer instructions are the instructions which transfers data in the microprocessor. They are also called copy instructions.
SHLD 16-bit address directly stores from H & L registers SHLD 2050
LXI r.p., 16-bit data loads the specified register pair with data LXI H, 3050
STAX 16-bit address indirectly stores from the accumulator A STAX 2050
OUT 8-bit port address outputs contents of A to the specified port OUT 15
In the table,
R stands for register
M stands for memory
r.p. stands for register pair
Arithmetic instructions in 8085 microprocessor
In the table,
R stands for register
M stands for memory
Mc stands for memory contents
r.p. stands for register pair
Logical instructions in 8085 microprocessor
ORA R A = A OR R ORA B
CMP M Compares Mc with A and triggers the flag register CMP 2050
CPI 8-bit data Compares 8-bit data with A and triggers the flag register CPI 50
In the table,
R stands for register
M stands for memory
Mc stands for memory contents
Problem – Write a program to move blocks of bits from source location starting at 2500 to destination location starting
from 2600 where size of blocks is 05 bytes.Example –
Algorithm –
8. Stop
Program –
2. LXI is used to load register pair immediately using 16-bit address (3 Byte instruction)
4. STAX is used to store accumulator into register pair indirectly (3 Byte instruction)
7. JNZ is used to jump if not zero to given memory location (3 Byte instruction)
2014 HLT
Problem – Multiply two 8 bit numbers stored at address 2050 and 2051. Result is stored at address 3050 and 3051. Starting
address of program is taken as 2000.
Example –
Algorithm –
2. As the multiplication of two 8 bit numbers can be maximum of 16 bits so we need register pair to store the result.
Program –
2012 HLT
Sign Flag (S) – After any operation if the MSB (B(7)) of the result is 1, it indicates the number is negative and the sign flag
becomes set, i.e. 1. If the MSB is 0, it indicates the number is positive and the sign flag becomes reset i.e. 0.
from 00H to 7F, sign flag is 0
from 80H to FF, sign flag is 1
1- MSB is 1 (negative)
0- MSB is 0 (positive)
Example:
MVI A 30 (load 30H in register A)
MVI B 40 (load 40H in register B)
SUB B (A = A – B)
These set of instructions will set the sign flag to 1 as 30 – 40 is a negative number.
MVI A 40 (load 40H in register A)
MVI B 30 (load 30H in register B)
SUB B (A = A – B)
These set of instructions will reset the sign flag to 0 as 40 – 30 is a positive number.
Zero Flag (Z) – After any arithmetical or logical operation if the result is 0 (00)H, the zero flag becomes set i.e. 1, otherwise it
becomes reset i.e. 0.
00H zero flag is 1.
from 01H to FFH zero flag is 0
1- zero result
0- non-zero result
Example:
MVI A 10 (load 10H in register A)
SUB A (A = A – A)
These set of instructions will set the zero flag to 1 as 10H – 10H is 00H
Auxiliary Carry Flag (AC) – This flag is used in BCD number system(0-9). If after any arithmetic or logical operation D(3)
generates any carry and passes on to B(4) this flag becomes set i.e. 1, otherwise it becomes reset i.e. 0. This is the only flag
register which is not accessible by the programmer
1-carry out from bit 3 on addition or borrow into bit 3 on subtraction
0-otherwise
Example:
MOV A 2B (load 2BH in register A)
MOV B 39 (load 39H in register B)
ADD B (A = A + B)
These set of instructions will set the auxiliary carry flag to 1, as on adding 2B and 39, addition of lower order nibbles B and 9 will
generate a carry.
Parity Flag (P) – If after any arithmetic or logical operation the result has even parity, an even number of 1 bits, the parity
register becomes set i.e. 1, otherwise it becomes reset i.e. 0.
1-accumulator has even number of 1 bits
0-accumulator has odd parity
Example:
MVI A 05 (load 05H in register A)
This instruction will set the parity flag to 1 as the BCD code of 05H is 00000101, which contains even number of ones i.e. 2.
Carry Flag (CY) – Carry is generated when performing n bit operations and the result is more than n bits, then this flag becomes
set i.e. 1, otherwise it becomes reset i.e. 0.
During subtraction (A-B), if A>B it becomes reset and if (A<B) it becomes set.
Carry flag is also called borrow flag.
1-carry out from MSB bit on addition or borrow into MSB bit on subtraction
0-no carry out or borrow into MSB bit
Example:
MVI A 30 (load 30H in register A)
MVI B 40 (load 40H in register B)
SUB B (A = A – B)
These set of instructions will set the carry flag to 1 as 30 – 40 generates a carry/borrow.
MVI A 40 (load 40H in register A)
MVI B 30 (load 30H in register B)
SUB B (A = A – B)
These set of instructions will reset the sign flag to 0 as 40 – 30 does not generate any carry/borrow.
Which of the following in 8085 microprocessor performs HL = HL + HL?
(A) DAD D
(B) DAD H
(C) DAD B
(D) DAD SP
Answer: (B)
Explanation: DAD will perform Double addition (16 bit) between HL pair and any other pair of register. Among HL, BC, DE and
SP; B, H and D register will be used first.
So, DAD H will do HL = HL + HL;
DAD B will do HL = HL + BC;
DAD D will do HL = HL + DE;
SP is stack pointer and it is not a pair register, DAD SP will do HL = HL + SP;
So, option (B) is correct.
******************
Match the following:
List - I List - II
(a)XCHG (i)only carry flag is affected.
(b)SUB (ii) no flags are affected.
(c)STC (iii) all flags other than carry flag are affected.
(d)DCR (iv)all flags are affected.
codes:
(D) (ii) (iv) (i) (iii)
***
Specify the contents of the accumulator and the status of the S, Z and CY flags when 8085 microprocessor performs
addition of 87 H and 79 H.
(A) 11, 1, 1, 1
(B) 10, 0, 1, 0
(C) 1, 1, 0, 0
(D) 00, 0, 1, 1
Answer: (D)
***
Two control signals in microprocessor which are related to Direct Memory Access (DMA) are
(A) INTR & INTA
(B) RD & WR
(C) S0 & S1
(D) HOLD & HLDA
Answer: (D)
Explanation: HOLD signal is used to request the access to the Bus and for other DMA events. The request is made to
the Processor. HLDA is the acknowledge signal for HOLD. It indicates whether the HOLD signal is received or not.
HOLD and HLDA are used as the control signal for DMA operations.
******
How many number of times the instruction sequence below will loop before coming out of the loop?
INC AL
JNZ A1
(A) 1
(B) 255
(C) 256
(D) Will not come out of the loop
Answer: (C)
Explanation:
INC AL // INCREMENT AL
AL = 0000 0000
Next step is for increment the value of AL. So, AL will keep on incrementing and after 255th iteration the value will
become 1111 1111, again the condition is checked and incremented, now in 256th iteration AL = 1 0000 0000.
As AL is an 8-bit register, 1 is discarded and the value becomes 0000 0000 and conditional jump to A1 occurs.
So, total 256 iterations.
********
Answer: (C)
Explanation: In 8085 microprocessor 16 bits are used for address bus and 65,536(216 = 65,536) different memory
location are possible.
So, option (C) is correct.
******
The contents of Register (BL) and Register (AL) of 8085 microprocessor are 49H and 3AH respectively. The contents
of AL, the status of carry flag (CF) and sign flag (SF) after executing ‘SUB AL, BL’ assembly language instruction, are
(A) AL = 0FH; CF = 1; SF = 1
(B) AL = F0H; CF = 0; SF = 0
(C) AL = F1H; CF = 1; SF = 1
(D) AL = 1FH; CF = 1; SF = 1
Answer: (C)
****