First INTEL-4004 Microprocessor |
Assembly Language |
Q1. Write an assembly language program for 8085 to add a 16 bit number stored from F900H onwards to another 16 bit number stored from F910H onwards. Store the result from FA00H onwards without ignoring the end-carry.
=>
Source program:
LHLD F900H : Get first I6-bit number in HL
XCHG : Save first I6-bit number in DE
LHLD F910H : Get second I6-bit number in HL
MOV A, E : Get lower byte of the first number
ADD L : Add lower byte of the second number
MOV L, A : Store result in L register
MOV A, D : Get higher byte of the first number
ADC H : Add higher byte of the second number with CARRY
MOV H, A : Store result in H register
SHLD FA00H : Store I6-bit result in memory locations FA00H.
HLT : Terminate program execution
OR
LHLD F900H : Get first I6-bit number
XCHG : Save first I6-bit number in DE
LHLD F910H : Get second I6-bit number in HL
DAD D : Add DE and HL
SHLD FA00H: Store I6-bit result in memory location FA00H.
HLT : Terminate program execution
|-----------------------------------------------------------------------------------------------------------------------------------|
Q2. Subtract the 16-bit number in memory locations 4002H and 4003H from the 16-bit number in memory locations 4000H and 4001H. The most significant eight bits of the two numbers are in memory locations 4001H and 4003H. Store the result in memory locations 4004H and 4005H with the most significant byte in memory location 4005H.
=>
Source program:
LHLD 4000H : Get first 16-bit number in HL
XCHG : Save first 16-bit number in DE
LHLD 4002H : Get second 16-bit number in HL
MOV A, E : Get lower byte of the first number
SUB L : Subtract lower byte of the second number
MOV L, A : Store the result in L register
MOV A, D : Get higher byte of the first number
SBB H : Subtract higher byte of second number with borrow
MOV H, A : Store l6-bit result in memory locations 4004H and 4005H.
SHLD 4004H : Store l6-bit result in memory locations 4004H and 4005H.
HLT : Terminate program execution
Q3: Find the l's complement of the number stored at memory location 4400H and store the complemented number at memory location 4300H.
Source program:
LDA 4400H : Get the number
CMA : Complement number
STA 4300H : Store the result
HLT : Terminate program execution
|-----------------------------------------------------------------------------------------------------------------------------------|
Q4: Find the 2's complement of the number stored at memory location 4200H and store the complemented number at memory location 4300H.
(4200H) = 55H
Result = (4300H) = AAH + 1 = ABH
Source program:
LDA 4200H : Get the number
CMA : Complement the number
ADI, 01 H : Add one in the number
STA 4300H : Store the result
HLT : Terminate program execution
Q5: Write a program to sort given 10 numbers from memory location 2200H in the ascending order.
MVI B, 09H : Initialize counter
START : LXI H, 2200H : 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
Q6: Find the largest number in a block of data. The length of the block is in memory location 2200H and the block itself starts from memory location 2201H.
Store the maximum number in memory location 2300H. Assume that the numbers in the block are all 8 bit unsigned binary numbers.
Sample problem 1:
(2200H) = 04
(2201H) = 34H
(2202H) = A9H
(2203H) = 78H
(2204H) =56H
Result = (2202H) = A9H
LDA 2200H
MOV C, A : Initialize counter
XRA A : Maximum = Minimum possible value = 0
LXI H, 2201H : Initialize pointer
BACK: CMP M : Is number> maximum
JNC SKIP : Yes, replace maximum
MOV A, M
SKIP: INX H
DCR C
JNZ BACK
STA 2300H : Store maximum number
HLT : Terminate program execution
Q7: Calculate the sum of series of numbers. The length of the series is in memory location 4200H and the series begins from memory location 4201H.
Consider the sum to be 8 bit number. So, ignore carries. Store the sum at memory location 4300H.
Source program
LDA 4200H
MOV C, A : Initialize counter
SUB A : sum = 0
LXI H, 420lH : Initialize pointer
BACK: ADD M : SUM = SUM + data
INX H : increment pointer
DCR C : Decrement counter
JNZ BACK : if counter 0 repeat
STA 4300H : Store sum
HLT : Terminate program execution
|-----------------------------------------------------------------------------------------------------------------------------------|
Q8: Calculate the sum of series of numbers. The length of the series is in memory location 4200H and the series begins from memory location 4201H.
Consider the sum to be 16 bit number. Store the sum at memory locations 4300H and 4301H.
Sample problem 2:
4200H = 04H
420lH = 9AH
4202H = 52H
4203H = 89H
4204H = 3EH
Result = 9AH + 52H + 89H + 3EH = H
4300H = B3H Lower byte
4301H = 0lH Higher byte
Source program
LDA 4200H
MOV C, A : Initialize counter
LXI H, 4201H : Initialize pointer
SUB A :Sum low = 0
MOV B, A : Sum high = 0
BACK: ADD M : Sum = sum + data
JNC SKIP
INR B : Add carry to MSB of SUM
SKIP: INX H : Increment pointer
DCR C : Decrement counter
JNZ BACK : Check if counter 0 repeat
STA 4300H : Store lower byte
MOV A, B
STA 4301H : Store higher byte
HLT :Terminate program execution
Thank U... :-P
ReplyDelete