Skip to main content

Posts

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"