PROGRAMS FOR TRAINEES
Ø Add parity bit to 7-bit ASCII
characters
characters
Ø Find the number of negative, zero and
positive numbers
positive numbers
Ø Inserting string in a given array of
characters
characters
Ø Deleting string in a given array of
characters
characters
Ø Divide 16-bit number with 8-bit number
using shifting technique
using shifting technique
Ø Sub routine to perform the task
of DAA
of DAA
Ø Program to test RAM
Ø Program to generate Fibonacci number
Ø Generate a delay of 0.4 seconds
Ø Arrange in Descending Order
Ø Data transfer from one memory block to other memory block.
Ø Find the factorial of a number
Ø Find the Square Root of a given number
Ø Split a HEX data into two nibbles and
store it
store it
Ø Add two 4-digit BCD numbers
Ø Subtraction of two BCD numbers
Ø Multiply two 2-digit BCD
numbers
numbers
Add parity bit to 7-bit ASCII characters
Statement: Add even parity
to a string of 7-bit ASCII characters. The length of the string is in memory
location 2040H and the string itself begins in memory location 2041H. Place
even parity in the most significant bit of each character.
to a string of 7-bit ASCII characters. The length of the string is in memory
location 2040H and the string itself begins in memory location 2041H. Place
even parity in the most significant bit of each character.
|
Find the number of negative, zero and positive numbers
Statement: A list of 50
numbers is stored in memory, starting at 6000H. Find number of negative, zero
and positive numbers from this list and store these results in memory locations
7000H, 7001H, and 7002H respectively.
numbers is stored in memory, starting at 6000H. Find number of negative, zero
and positive numbers from this list and store these results in memory locations
7000H, 7001H, and 7002H respectively.
|
Inserting string in a given array of characters
Statement: Write an 8085
assembly language program to insert a string of four characters from the tenth
location in the given array of 50 characters.
assembly language program to insert a string of four characters from the tenth
location in the given array of 50 characters.
Solution: Step 1: Move bytes from location 10 till the end of array by four bytes downwards. Step 2: Insert four bytes at locations 10, 11, 12 and 13. Source program : v LXI H, 2l31H : Initialize pointer at the last location of array. v LXI D, 2l35H : Initialize another pointer to point the last location of array after insertion. v AGAIN: MOV A, M : Get the character v STAX D : Store at the new location v DCX D : Decrement destination pointer v DCX H : Decrement source pointer v MOV A, L : [check whether desired v CPI 05H bytes are shifted or not] v JNZ AGAIN : if not repeat the process v INX H : adjust the memory pointer v LXI D, 2200H : Initialize the memory pointer to point the string to be inserted v REPE: LDAX D : Get the character v MOV M, A : Store it in the array v INX D : Increment source pointer v INX H : Increment destination pointer v MOV A, E : [Check whether the 4 bytes v CPI 04 are inserted] v JNZ REPE : if not repeat the process v HLT : stop |
Deleting string in a given array of characters
Statement: Write an 8085
assembly language program to delete a string of 4 characters from the tenth
location in the given array of 50 characters.
assembly language program to delete a string of 4 characters from the tenth
location in the given array of 50 characters.
Solution: Shift bytes from location 14 till the end of array upwards by 4 characters i.e. from location 10 onwards. Source program : v LXI H, 2l0DH :Initialize source memory pointer at the 14thlocation of the array. v LXI D, 2l09H : Initialize destination memory pointer at the 10th location of the array. v MOV A, M : Get the character v STAX D : Store character at new location v INX D : Increment destination pointer v INX H : Increment source pointer v MOV A, L : [check whether desired v CPI 32H bytes are shifted or not] v JNZ REPE : if not repeat the process v HLT : stop |
Multiply two eight bit numbers with shift and add method
Statement: Multiply the
8-bit unsigned number in memory location 2200H by the 8-bit unsigned number in
memory location 2201H. Store the 8 least significant bits of the result in
memory location 2300H and the 8 most significant bits in memory location 2301H.
8-bit unsigned number in memory location 2200H by the 8-bit unsigned number in
memory location 2201H. Store the 8 least significant bits of the result in
memory location 2300H and the 8 most significant bits in memory location 2301H.
Sample problem: (2200) = 1100 (0CH) (2201) = 0101 (05H) Multiplicand = 1100 (1210) Multiplier = 0101 (510) Result = 12 x 5 = (6010)
|
Divide 16-bit number with 8-bit number using shifting
technique
technique
Statement: Divide the
16-bit unsigned number in memory locations 2200H and 2201H (most significant
bits in 2201H) by the B-bit unsigned number in memory location 2300H store the
quotient in memory location 2400H and remainder in 2401H.
16-bit unsigned number in memory locations 2200H and 2201H (most significant
bits in 2201H) by the B-bit unsigned number in memory location 2300H store the
quotient in memory location 2400H and remainder in 2401H.
Assumption: The most significant bits of both the divisor and dividend are zero.
|
Sub routine to perform the task of DAA
Statement: Assume the DAA
instruction is not present. Write a sub routine which will perform the same
task as DAA.
instruction is not present. Write a sub routine which will perform the same
task as DAA.
Sample Problem: Execution of DAA instruction: 1. If the value of the low order four bits (03-00) in the accumulator is greater than 9 or if auxiliary carry flag is set, the instruction adds 6 '(06) to the low-order four bits. 2. If the value of the high-order four bits (07-04) in the accumulator is greater than 9 or if carry flag is set, the instruction adds 6(06) to the high-order four bits.
|
Program to test RAM
Statement: To test RAM by
writing '1' and reading it back and later writing '0' (zero) and reading it
back. RAM addresses to be checked are 40FFH to 40FFH. In case of any error, it
is indicated by writing 01H at port 10H.
writing '1' and reading it back and later writing '0' (zero) and reading it
back. RAM addresses to be checked are 40FFH to 40FFH. In case of any error, it
is indicated by writing 01H at port 10H.
Source program : v LXI H, 4000H : Initialize memory pointer v BACK: MVI M, FFH : Writing '1' into RAM v MOV A, M : Reading data from RAM v CPI FFH : Check for ERROR v JNZ ERROR : If yes go to ERROR v INX H : Increment memory pointer v MOV A, H v CPI SOH : Check for last check v JNZ BACK : If not last, repeat v LXI H, 4000H : Initialize memory pointer v BACKl: MVI M, OOH : Writing '0' into RAM v MOV A, M : Reading data from RAM v CPI OOH : Check for ERROR v INX H : Increment memory pointer v MOV A, H v CPI SOH : Check for last check v JNZ BACKl : If not last, repeat v HLT : Stop Execution |
Program to generate Fibonacci number
Statement: Write an
assembly language program to generate fibonacci
number.
assembly language program to generate fibonacci
number.
Source program : v MVI D, COUNT : Initialize counter v MVI B, 00 : Initialize variable to store previous number v MVI C, 01 : Initialize variable to store current number v MOV A, B :[Add two numbers] v BACK: ADD C :[Add two numbers] v MOV B, C : Current number is now previous number v MOV C, A : Save result as a new current number v DCR D : Decrement count v JNZ BACK : if count 0 go to BACK v HLT : Stop. |
Generate a delay of 0.4 seconds
Statement: Write a program
to generate a delay of 0.4 sec if the crystal frequency is 5 MHz.
to generate a delay of 0.4 sec if the crystal frequency is 5 MHz.
Calculation: In 8085, the operating frequency is half of the crystal frequency, ie.Operating frequency = 5/2 = 2.5 MHz Time for one T -state = Number of T-states required = 1 x 106 Source program : v LXI B, count : 16 - bit count v BACK: DCX B : Decrement count v MOV A, C v ORA B : Logically OR Band C v JNZ BACK : If result is not zero repeat |
Arrange in Descending order
Statement: Arrange an
array of 8 bit unsigned no in descending order
array of 8 bit unsigned no in descending order
v START:MVI B, 00 ; Flag = 0 v LXI H, 4150 ; Count = length of array v MOV C, M v DCR C ; No. of pair = count -1 v INX H ; Point to start of array v LOOP:MOV A, M ; Get kth element v INX H v CMP M ; Compare to (K+1) th element v JNC LOOP 1 ; No interchange if kth >= (k+1) th v MOV D, M ; Interchange if out of order v MOV M, A ; v DCR H v MOV M, D v INX H v MVI B, 01H ; Flag=1 v LOOP 1:DCR C ; count down v JNZ LOOP ; v DCR B ; is flag = 1? v JZ START ; do another sort, if yes v HLT ; If flag = 0, step execution |
Data transfer from one memory block to other memory block.
Statement: Transfer ten
bytes of data from one memory to another memory block. Source memory block
starts from memory location 2200H where as destination memory block starts from
memory location 2300H.
bytes of data from one memory to another memory block. Source memory block
starts from memory location 2200H where as destination memory block starts from
memory location 2300H.
v LXI H, 4150 : Initialize memory pointer v MVI B, 08 : count for 8-bit v MVI A, 54 v LOOP : RRC v JC LOOP1 v MVI M, 00 : store zero it no carry v JMP COMMON v LOOP2: MVI M, 01 : store one if there is a carry v COMMON: INX H v DCR B : check for carry v JNZ LOOP v HLT : Terminate the program |
Find the factorial of a number
Statement: Program to
calculate the factorial of a number between 0 to 8
calculate the factorial of a number between 0 to 8
|
Find the Square Root of a given number
Statement: Write a program
to find the Square Root of an 8 bit binary number. The binary number is stored
in memory location 4200H and store the square root in 4201H.
to find the Square Root of an 8 bit binary number. The binary number is stored
in memory location 4200H and store the square root in 4201H.
Note: The square root can be taken by an iterative technique. First, an initial value is assumed. Here, the initial value of square root is taken as half the value of given number. The new value of square root is computed by using an expression XNEW = (X + Y/X)/2 where, X is the initial value of square root and Y is the given number. Then, XNEW is compared with initial value. If they are not equal then the above process is repeated until X is equal to XNEW after taking XNEW as initial value. (i.e., X ←XNEW) |
Split a HEX data into two nibbles and store it
Statement: Write a simple
program to Split a HEX data into two nibbles and store it in memory
program to Split a HEX data into two nibbles and store it in memory
Source program : v LXI H, 4200H : Set pointer data for array v MOV B,M : Get the data in B-reg v MOV A,B : Copy the data to A-reg v ANI OFH : Mask the upper nibble v INX H : Increment address as 4201 v MOV M,A : Store the lower nibble in memory v MOV A,B : Get the data in A-reg v ANI FOH : Bring the upper nibble to lower nibble position v RRC v RRC v RRC v RRC v INX H v MOV M,A : Store the upper nibble in memory v HLT : Terminate program execution |
Add two 4-digit BCD numbers
Statement: Add two 4 digit BCD numbers in HL and DE register pairs and store
result in memory locations, 2300H and 2301H. Ignore carry after 16 bit.
result in memory locations, 2300H and 2301H. Ignore carry after 16 bit.
|
Subtraction of two BCD numbers
Statement: Subtract the
BCD number stored in E register from the number stored in the D register.
BCD number stored in E register from the number stored in the D register.
Source Program: v MVI A,99H v SUB E : Find the 99's complement of subtrahend v INR A : Find 100's complement of subtrahend v ADD D : Add minuend to 100's complement of subtrahend v DAA : Adjust for BCD v HLT : Terminate program execution Note: When two BCD numbers are subtracted, we can use DAA instruction for ajusting the result to BCD. Therefore, the subtraction of BCD number is carried out 10's complement or 100's complement. The 10's complement of a decimal number is equal to the 99's complement plus 1. The 99's complement of a number can be found by subtracting the number from 99. The steps for finding 100's complement BCD subtraction are :
|
Multiply two 2-digit BCD numbers
Statement: Write an
assembly language program to multiply 2 BCD numbers
assembly language program to multiply 2 BCD numbers
Source Program: v MVI C, Multiplier : Load BCD multiplier v MVI B, 00 : Initialize counter v LXI H, 0000H : Result = 0000 v MVI E, multiplicand : Load multiplicand v MVI D, 00H : Extend to 16-bits v BACK: DAD D : Result Result + Multiplicand v MOV A, L : Get the lower byte of the result v ADI, 00H v DAA : Adjust the lower byte of result to BCD. v MOV L, A : Store the lower byte of result v MOV A, H : Get the higher byte of the result v ACI, 00H v DAA : Adjust the higher byte of the result to BCD v MOV H, A : Store the higher byte of result. v MOV A, B : [Increment v ADI 01H : counter v DAA : adjust it to BCD and v MOV B,A : store it] v CMP C : Compare if count = multiplier v JNZ BACK : if not equal repeat v HLT : Stop |