Skip to main content

Posts

Showing posts with the label Microprocessor(8085)

Arrange in ascending order

Write a program to sort given 10 numbers from memory location 2200H in the ascending order. MVI B , 09 : "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"

Separate even numbers from given numbers

Separate even numbers from given numbers LXI H, 2500H        :  "Initialize memory pointer 1"    LXI D, 2600H        :  "Initialize memory pointer2"    MVI C, 32H          :  "Initialize counter"    BACK:MOV A, M       :  "Get the number"    ANI 01H             :  "Check for even number"    JNZ SKIP            :  "If ODD, don't store"    MOV A, M            :  "Get the number"    STAX D              :  "Store the number in result list"    INX D               :  "Increment pointer 2"    SKIP: INX H         :  "Increment pointer 1"    DCR C               :  "Decrement counter"    JNZ BACK            :  "If not zero, repeat"    HLT                     :  "Stop"   

Find the square of given number

Find the square of given number LDA 2500H   :  "Get data in accumulator"    MOV L, A    :  "Get data in register L"    MVI H, 26H  :  "Get 26 in register H"    MOV A, M    :  "Square of data in accumulator"    STA 2501 H  :  "Store Square in 2501 H"    HLT :  "Stop"

Calculate the sum of series of odd numbers

Calculate the sum of series of odd numbers LDA 2500H   MOV C, A            :  "Initialize counter"    LXI H, 2501H        :  "Initialize pointer"    MVI E, 00           :  "Sum low = 0"    MOV D, E            :  "Sum high = 0"    BACK: MOV A, M      :  "Get the number"    ANI 01H             :  "Mask Bit 1 to Bit-7"    JZ SKIP             :  "Don't add if number is even"    MOV A, E            :  "Get the lower byte of sum"    ADD M               :  "Sum = sum + data"    MOV E, A            :  "Store result in E register"    JNC SKIP   INR D               :  "Add carry to MSB of SUM"    SKIP: INX H         :  "Increment pointer"   

Calculate the sum of series of even numbers

Calculate the sum of series of even numbers LDA 2500H   MOV C, A            :  "Initialize counter"    MVI B, 00H          :  "sum = 0"    LXI H, 2501H        :  "Initialize pointer"    BACK: MOV A, M      :  "Get the number"    ANI 01H             :  "Mask Bit l to Bit7"    JNZ SKIP            :  "Don't add if number is ODD"    MOV A, B            :  "Get the sum"    ADD M               :  "SUM = SUM + data"    MOV B, A            :  "Store result in B register"    SKIP: INX H         :  "increment pointer"    DCR C               :  "Decrement counter"    JNZ BACK            :  "if counter 0 repeat"    STA 2505H           :  "store sum"    HLT                 :  "Stop"  

Find smaller of two numbers

Find smaller of two numbers LXI H, 2501H : "Address of first number in H-L pair" MOV A, M : "1stt number in accumulator" INX H : "Address of 2 nd number in H-L pair" CMP M : "compare 2 nd number with 1st number" JC AHEAD : "Yes, smaller number is in accumulator. Go to AHEAD" MOV A, M : "No, get 2 nd number in the accumulator" STA 2503 H : "Store smaller number in 2503H" HLT : "Stop"

Find larger of two numbers

Find larger of two numbers LXI H, 2501H : "Address of first number in H-L pair" MOV A, M : "1stt number in accumulator" INX H : "Address of 2 nd number in H-L pair" CMP M : "compare 2 nd number with 1 st number" JNC AHEAD : "No, larger is in accumulator. Go to AHEAD" MOV A, M : "Yes, get 2 nd number in the accumulator" STA 2503 H : "Store larger number in 2503H" HLT : "Stop"

Finding 2's complement of a number

Finding 2's complement of a number LDA 2501 H  :  "Get data in accumulator"    CMA         :  "Take its 1's complement"    ADI, 01 H   :  "Add one in the number"    STA 2502 H  :  "Store the result in 2502 H"    HLT         :  "Stop"  

Add contents of two memory locations

Add contents of two memory locations LXI H, 2500H    :  "HL Points 2500H"    MOV A, M        :  "Get first operand"    INX H           :  "HL Points 2501H"    ADD M           :  "Add second operand"    INX H           :  "HL Points 2502H"    MOV M, A        :  "Store the lower byte of result at 2502H"    MVI A, 00        :  "Initialize higher byte result with 00H"    ADC A           :  "Add carry in the high byte result"    INX H           :  "HL Points 2503H"    MOV M, A        :  "Store the higher byte of result at 2503H"    HLT             :  "Terminate program execution"  

Subtract two 16-bit numbers

Subtract two 16-bit numbers LHLD 2500H      :  "Get first 16-bit number in HL"    XCHG            :  "Save first 16-bit number in DE"    LHLD 2502H      :  "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 2504H and 2505H"    SHLD 2504H      :  "Store l6-bit result in memory locations 2504H and 2505H"    HLT             :  "Terminate program execution"  

Add two 16-bits numbers with DAD instruction

Add two 16-bits numbers with DAD instruction LHLD 2501H  :  "Get 1st 16-bit number"    XCHG        :  "Save 1st 16-bit number in DE"    LHLD 2503H  :  "Get 2nd 16-bit number in H-L"    DAD D       :  "Add DE and HL"    SHLD 2505H  :  "Store 16-bit result in memory locations 2505H and 2506H" .   HLT         :  "Stop"

Add two 16-bits number with ADD and ADC instruction

Add two 16-bits number with ADD and ADC instruction LHLD 2501H   :  "Get 1st 16-bit number in H-L pair"    XCHG         :  "Save 1st 16-bit number in DE"    LHLD 2503H   :  "Get 2nd 16-bit number in H-L pair"    MOV A, E     :  "Get lower byte of the 1st number"    ADD L        :  "Add lower byte of the 2nd number"    MOV L, A     :  "Store result in L-register"    MOV A, D     :  "Get higher byte of the 1st number"    ADC H        :  "Add higher byte of the 2nd number with CARRY"    MOV H, A     :  "Store result in H-register"    SHLD 4004H   :  "Store 16-bit result in memory locations 2505H and 2506H"    HLT          :  "Stop"  

Subtract two 8-bit numbers

Subtract two 8-bit numbers LXI H, 2501H   :   "Get address of first number in H-L pair. Now H-L points to 2501H"    MOV A, M       :   "Get first operand in accumulator"    INX H          :   "Increment content of H-L pair. Now, H-L points 2502H"    SUB M          :   "Subtract first to second operand"    INX H          :   "H-L points 4002H"    MOV M, A       :   "Store result at 2503H"    HLT            :   "Stop"  

Add two 8-bit numbers

Add two 8-bit numbers LXI H, 2501H  :  "Get address of first number in H-L pair. Now H-L points to 2501H"    MOV A, M      :  "Get first operand in accumulator"    INX H         :  "Increment content of H-L pair. Now, H-L points 2502H"    ADD M         :  "Add first and second operand"    INX H         :  "H-L points 4002H"    MOV M, A      :  "Store result at 2503H"    HLT           :  "Stop"   
Q. The limit switches in the system in question 1 is removed. The string is to be rotated for 1 minute to put all the clothes inside the house if there is rain or send the clothes out when there is no rain. Write a program for the proper operation of the system. Solution: Main Program START: IN 30H ; get input from rain detector ANI 01H ; mask the other bits than sensor position JZ END ; check if the cloth is in the rain MVI A, 02H ; if yes put the clothes inside OUT 40H CALL DELAY ; time required to put the clothes inside LABEL1: MVI A, 00H ; turn off the motor OUT 40H IN 30H ; check if it’s still raining ANI 01H JNZ LABEL1 ; if yes put the motor off MVI A, 01H ; else rotate the string and put clothes out OUT 40H CALL DELAY ; time required to put clothes outside END: MVI A, 00H ; turn off the motor OUT 40H JMP START ; repeat the task Delay Subroutine DELAY: MVI B, 78H ; factor to multiply to make 1 minute delay LABEL2: LXI H, F69AH ; count for 0.5 second del
Q. Two set of ten data bytes are stored at memory location staring from C000H to C009H and memory location D000H to D009H. Write a program to add the data bytes of corresponding locations and store the result at memory locations E000H to E009H. (Hint: add the data of C000H with D000H and store the result at E000H, similarly C001H with D001H and store the result at E001H and so on…) Solution: LXI H, C000H LXI D, D000H LXI B, E000H LABEL1: LDAX D ADD M STAX D INX H INX D INX B MOV A, L CPI 0AH JNZ LABEL1 HLT
Q. To provide preference to the pedestrians, for the system in question 3, push button as shown below is also placed at the two sides of the road. If the push button is pressed 50 times the green light for pedestrians is turned on immediately for 4 seconds, and then the operation continues as before. Assume D0 pin of input port 35H to be connected to the push button and then to the microprocessor. Modify the program of question 3 to accommodate the changes.  Solution: Main Program START: MVI B, 00H ; allocation for count LABEL0: MVI A, 01H ; turn the green light on OUT 66H MVI C, 08h ; time required to turn on green light LABEL1: CALL DELAY1 DCR C JNZ LABEL1 MVI A, 80H ; turn the red light on OUT 66H MVI C, 64H ; time required to turn on red light LABEL2: CALL DELAY2 DCR C JNZ LABEL2 JMP START ; repeat the task Delay Subroutine1 DELAY1: LXI H, F69AH ; count for 0.5 second delay LABEL3: DCX H MOV A, L ORA H JNZ LABEL3 RET Delay Subroutine2 DELAY2:
Q. Pedestrian crossing lights are installed at the zebra crossing as shown in the figure below. The system is controlled by an 8085 microprocessor. Write an assembly language program for 8085 to operate the lights continuously with one light on while the other is off. The green light is turned on for 4 seconds and red light for 10 seconds. Use subroutine for the delay, during each light operation. Assume the clock frequency of 8085 is 3MHz. Solution: Main Program START: MVI A, 01H ; turn the green light on OUT 66H MVI C, 08h ; time required to turn on green light LABEL1: CALL DELAY DCR C JNZ LABEL1 MVI A, 80H ; turn the red light on OUT 66H MVI C, 14H ; time required to turn on red light LABEL2: CALL DELAY DCR C JNZ LABEL2 JMP START ; repeat the task Delay Subroutine DELAY: LXI H, F69AH ; count for 0.5 second delay LABEL3: DCX H MOV A, L ORA H JNZ LABEL3 RET