Skip to main content

Posts

Showing posts from January, 2020

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
Q. Clothes are normally hung outside to dry in the sun. There are possibilities of clothes being wet when there is a rainfall. The system as shown below is used to put clothes inside the house when there is a rain. The rain detector sends a high signal to the pin D0 of the input port 30H when there is rainfall. The microprocessor then rotates the string on which the clothes are hung. The string is rotated by sending a ‘10’ to pins D0 and D1 of the output port 40H to which a DC motor is connected. The string is rotated until the limit switch1 sends a high signal to pin D7 of the input port 30H. Also if the rainfall stops the cloth is send out by rotating the DC motor in the other direction. ‘01’ is to be send to pins D0 and D1 of output port 40H for this operation. The motor is rotated until the limit switch2 send a high signal to pin D6 of the input port 30H. Write a program for the proper operation of the system. soln The Program gets input from the input port dep
Q. A digital IC tester is designed using Intel 8085 to check Quad-NAND gates. Write a program to test the IC and turn on the green LED if the IC is working properly else turn on the red LED. The pin diagram of a NAND gate (7400) is shown below. The input pins (1A, 1B, 2A, 2B, 3A, 3B, 4A and 4B) of the gate are connected to output port 40H and the output pins (1Y, 2Y, 3Y and 4Y) are connected to input port 30H. Also the green and red LEDs are connected to port 41H as shown below. soln As per the 4 NAND gate input and output connections, the combination of inputs and their desired output for the 4 gates would be as follows: The outputs at port 41H are: 01H to turn on the green LED 02H to turn on the red LED LXI H, D000H ; assign memory location for input data MVI M, 00H ; store inputs 00H, 55H, AAH and FFH INX H MVI M, 55H INX H MVI M, AAH INX MVI M, FFH INX H ; assign memory location for output data MVI M, 0FH ; store outputs 0FH, 0FH, 0FH and 00H INX H MV
Q. Write a program for division of two numbers. Assume that the numbers are in memory location C000H and C001H, and the quotient and remainder is to be displayed at output devices 50H and 51H. Solution: LXI H, C000H MOV A, M ; dividend in A from C000H INX H MOV B, M ; divisor in B from C001H MVI C, 00H ; quotient in C LABEL1: CMP B JC LABEL2 ; if dividend<divisor, no division INR C SUB B JNZ LABEL1 LABEL2: OUT 51H ; display remainder MOV A, C OUT 50H ; display quotient HLT
Q. A seven segment display is connected to output port 30H for an Intel 8085 based system. Write a program to convert the content of memory location C000H to seven segment display. Assume that the memory location contains any number from 0 to 9. If the number is greater than 9 all the LEDs of the display should be off. ( Hint: store the bit pattern for numbers from 0 to 9 in memory locations D000H-D009H(say) and then the program should find the pattern according to the number in C000H and display that to output port 30H) soln The table below shows the seven segment display requirement for numbers 0 to 9 LXI H, D000H ; store the bit pattern of the numbers from 0 to 9 MVI M, 3FH INX H MVI M, 06H INX H MVI M, 5BH INX H MVI M, 4FH INX H MVI M, 66H INX H MVI M, 6DH INX H MVI M, 7DH INX H MVI M, 07H INX H MVI M, 7FH INX H MVI M, 6FH MVI H, D0H LDA C000H CPI 0AH ; check for number > 9 JC LABEL1 MOV L, A MOV A, M JMP LABEL2 LABEL1: MVI A, 00H LA
Q. A bar code scanner scans the boxes being shipped from the loading dock and records all the codes in memory starting from AB00H; the end of the data is indicated by the byte 00H. The code 0010 0001 is assigned to 21 inches television sets. Write a program to count the number of 21 inches television sets that were shipped from the loading dock. Solution: LXI H, AB00H MVI C, 00H LABEL1: MOV A, M CPI 00H ; check for the end of the data 00H JZ END CPI 21H ; check for code 0010 0001 (21H) JNZ LABEL2 INR C LABEL2: INX H JMP LABEL1 END: MOV A, C ; store the count at BB00H (not mentioned in the question) STA BB00H HLT
Q. A set of ten bytes are stored in memory locations starting with address C000H. Write a program to check each byte and save the bytes that are higher than 40H and lower than 64H in memory locations starting from C200H. Solution: LXI H, C000H LXI D, C200H MVI C, 0AH LABEL1: MVI A, 40H CMP M JNC LABEL2 ; reject less than or equal to 40H MOV A, M CPI 64H JNC LABEL2 ; reject greater than 64H STAX D INX D LABEL2: INX H DCR C JNZ LABLE1 HLT
Q. A system is designed to monitor the temperature of a furnace. Ten temperature readings are recorded in 16 bits and stored in memory locations starting at D050H. The higher order byte is stored first and the low order byte is stored in the next consecutive memory location. The high-order byte of all the temperature readings is constant. Write a program to transfer the low-order readings to the consecutive memory locations starting at E060H and discard the high-order bytes. Solution: LXI H, D051H ; the lower reading is at higher address as per the question LXI D, E060H ; new location for lower reading MVI C, 0AH ; count for ten readings LABEL1: MOV A, M STAX D INX H ; skip the higher reading by increasing the address twice INX H INX D DCR C JNZ LABEL1 HLT
Q. The figure below uses an 8085 based system to track the sun, and position the Solar Photovoltaic module in the direction of the sun. The solar module is attached to a DC motor and the sun is tracked by two light sensors at two sides of the solar photovoltaic module. If both the sensor sends ‘1’ the motor is to be stopped. If only sensor1 sends ‘1’ the motor is to be rotated in one direction and if only sensor2 sends ‘1’ the motor is to be rotated in the other direction. For a DC motor “10” at the supply pins rotates the motor in one direction and “01” rotates the motor in the other direction. As per the connection shown on the right, write a program for the proper operation of the system. soln The Program gets input from the input port depending on the incident solar radiation, compares with the predefined data for different solar radiation, and sends the corresponding data out as shown in the above table. START: IN 30H ANI A0H MOV B, A SUI 80H JNZ LABEL1 M
Q. A microprocessor based temperature control system is shown below. The light detectors receive the light when reflected by the mercury level in the thermometer and sends ‘1’ to the input port (30H). Depending on the input signal the microprocessor is to operate the fan, heater or the indicators. The fan is to operate for temperature above 20 degree, with different speed, depending upon the temperature level. The microprocessor is to operate the resistances accordingly. The heater is to be operated below 16 degree with the heating coils being on depending on temperature. If the temperature is in the range of 16 to 20 degrees both the fan and heater is to be put off and the Green LED is turned ON. If the temperature is below 4 degree or above 28 degree the Red LED is to be turned ON with fan or heater. Write a program for the proper operation of the system and explain the execution flow. soln The Program gets input from the input port depending on the temperature, c