Assembly Language Programs 1) PROGRAM TO EXCHANGE TWO 16 BIT NUMBERS Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 2A,00,F0 LHLD F000 Load memory from specified locations. 2 8003 EB XCHG Exchange contents of HL & DE pairs. 3 8004 2A,00,F1 LHLD F100 Load memory from specified locations. 4 8007 22,00,F0 SHLD F000 Store memory to specified locations. 5 800A EB XCHG Exchange contents of HL & DE pairs. 6 800B 22,00,F1 SHLD F200 Store memory to specified locations. 7 800E CF RST 1 Restart INPUT (Before execution) F001 ; F000 F101 ; F100 12 ; AB 3C ; DE OUTPUT(After execution) F001 ; F000 F101 ; F100 3C ; DE 12 ; AB K. Adisesha 1
Assembly Language Programs 2) PROGRAM TO ADD OR SUBTRACT TWO 8 BIT NUMBERS Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 3E, XX MVI A, XX Move immediately to [A] the data XX 2 8002 06, YY MVI B, YY Move immediately to [B] the data YY 3 8004 80/(90) ADD B/SUB B Add(or subtract) [B] with [A] 4 8005 32,00,F0 STA F000 Store contents of [A] in specified location 5 8008 D2,10,80 JNC (Ahead 1) Jump on no carry to specified location 6 800B 3E,01 MVIA, 01 Move immediately to [A] the data(01)H 7 800D C3,12,80 JMP(Ahead 2) Jump unconditionally ahead 8 8010 3E,00 Ahead 1 MVIA, 00 Move immediately to [A] the data(00)H 9 8012 32,01,F0 Ahead 2 STA F001 Store contents of [A] in specified location 10 8015 CF RST1 Restart INPUT : XX, YY 1) 2B, 1A 2) 2B, FA OUTPUT TRIAL Addition (XX+YY) Subtraction (XX-YY) ADDRESS F001: F000 F001: F000 1 00 : 45 00 : 25 2 01 : 25 01 : 31 K. Adisesha 2
Assembly Language Programs 3) PROGRAM TO ADD TWO 16 BIT NUMBERS Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 AF XRA A Clear accumulator and Flag 2 8001 2A, 00, F0 LHLD F000 Load memory from specified locations 3 8004 EB XCHG Exchange contents of HL & DE pairs 4 8005 2A,00,F1 LHLD F100 Load memory from specified locations 5 8008 19 DAD D Add HL & DE pairs 6 8009 22,00,F2 SHLD F200 Store memory to specified locations 7 800C D2,10,80 JNC (Ahead) Jump on no carry to ahead address 8 800F 3C INR A Increment contents of accumulator by one 9 8010 32,02,F2 Ahead STA F202 Store contents of [A] in specified location 10 8013 CF RST1 Restart F001: F000 (X) 4A : 2C F101: F100 (Y) ED : 5B F202:F201: F200 (X+Y) 01 : 37 : 87 K. Adisesha 3
Assembly Language Programs 4) PROGRAM TO SUBTRACT TWO 16 BIT NUMBERS (X>Y) Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 2A,00,F0 LHLD F000 Load memory from specified locations 2 8003 EB XCHG Exchange contents of HL & DE pairs 3 8004 2A,00,F1 LHLD F100 Load memory from specified locations 4 8007 7D MOV A, L Move contents of [L] to [A] 5 8008 93 SUB E Subtract [E] from [A] 6 8009 32,00,F2 STA F200 Store result in specified location 7 800C 7C MOV A, H Move contents of [H] to [A] 8 800D 9A SBB D Subtract [D] from [A] with borrow 9 800E 32,01,F2 STA F201 Store result in specified location 10 8011 CF RST 1 Restart F001: F000 (X) FA : 2C F101: F100 (Y) BD : 5B F202:F201: F200 (X-Y) 3C : D1 K. Adisesha 4
Assembly Language Programs 5) PROGRAM TO ADD TWO N BYTE NUMBERS Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 21,00,F0 LXIH F000 Load HL pair with specified data 2 8003 01,00,F1 LXIB F100 Load BC pair with specified data 3 8006 11,00,F2 LXID F200 Load DE pair with specified data 4 8009 3E,(NN) MVI A, (NN) Specify the number of bytes 5 800B 32,00,81 LOOP STA 8100 Save the count 6 800E AF XRA A Clear accumulator and flags 7 800F 0A LDAX B Load [A] indirectly from address specified by BC pair 8 8010 8E ADC M Add memory to [A] with carry 9 8011 12 STAX D Store contents of [A] indirectly in location specified by DE pair 10 8012 23 INX H Update memory 11 8013 03 INX B Update BC register pair 12 8014 13 INX D Update DE register pair 13 8015 3A,00,81 LDA 8100 Load [A] from specified location 14 8018 3D DCR A Decrement count 15 8019 C2,0B,80 JNZ (LOOP) Jump on no zero to perform loop 16 801C D2,24,80 JNC (Ahead 1) Jump on no carry to ahead address 17 801F 3E,01 MVI A, 01 Move immediately to [A] the data(01)H 18 8021 C3,26,80 JMP (Ahead 2) Jump unconditionally to ahead address 19 8024 3E,00 Ahead 1 MVI A, 00 Move immediately to [A] the data(00)H 20 8026 12 Ahead 2 STAX D Store contents of [A] indirectly in address specified by DE pair 21 8027 CF RST 1 Restart K. Adisesha 5
Assembly Language Programs INPUT(X) F103 : F102 : F101 : F100 A4 : E6 : F3 : D7 INPUT(Y) F003 : F002 : F001 : F000 C3 : 54 : A2 : 1B OUTPUT(X+Y) F204:F203 : F202 : F201 : F200 01: 68 : 3B: 95: F2 K. Adisesha 6
Assembly Language Programs 6) PROGRAM FOR BLOCK TRANSFER Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 16,10 MVI D, (10)H Set count in [D] 2 8002 21,00,81 LXIH 8100 Load HL pair with specified address 3 8005 01,00,82 LXIB 8200 Load BC pair with specified address 4 8008 7E LOOP MOV A,M Move contents of memory to [A] 5 8009 02 STAX B Store contents of [A] indirectly to location specified by BC pair 6 800A 23 INX H Update memory 7 800B 03 INX B Update BC pair 8 800C 15 DCR D Decrement count in [D] 9 800D C2,08,80 JNZ (LOOP) Jump on no zero to perform the loop 10 8010 CF RST1 Restart INPUT 8100:810:8102:8103:8104:8105:8106:8107:8108:8109:810A:810B:810C:810D:810E:810F 00 : 01: 02 : 03 : 04 : 05 : 06 : 07 : 08 : 09 : 0A : 0B : 0C : 0D : 0E : 0F OUTPUT 8200:8201:8202:8203:8204:8205:8206:8207:8208:8209:820A:820B:820C:820D:820E:820F 00 : 01: 02 : 03 : 04 : 05 : 06 : 07 : 08 : 09 : 0A : 0B : 0C : 0D : 0E : 0F K. Adisesha 7
Assembly Language Programs 7) PROGRAM TO BLOCK TRANSFER IN REVERSE ORDER Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 16,10 MVI D, (10)H Set count in [D] 2 8002 21,00,81 LXIH 8100 Load HL pair with specified address 3 8005 01,0F,82 LXIB 820F Load BC pair with specified address 4 8008 7E LOOP MOV A,M Move contents of memory to [A] 5 8009 02 STAX B Store contents of [A] indirectly to location specified by BC pair 6 800A 23 INX H Update memory 7 800B 0B DCX B Decrement BC pair by one 8 800C 15 DCR D Decrement count in [D] 9 800D C2,08,80 JNZ (LOOP) Jump on no zero to perform the loop 10 8010 CF RST1 Restart INPUT 8100:810:8102:8103:8104:8105:8106:8107:8108:8109:810A:810B:810C:810D:810E:810F 00 : 01: 02 : 03 : 04 : 05 : 06 : 07 : 08 : 09 : 0A : 0B : 0C : 0D : 0E : 0F OUTPUT 820F:820E:820D:820C:820B:820A:8209:8208:8207:8206:8205:8204:8203:8202:8201:8200 0F : 0E : 0D : 0C : 0B : 0A : 09 : 08 : 07 : 06 : 05 : 04 : 03 : 02 : 01 : 00 K. Adisesha 8
Assembly Language Programs 8) PROGRAM TO ADD N DECIMAL NUMBERS (N= 10) INPUT OUTPUT 8100:810:8102:8103:8104:8105:8106:8107:8108:8109 F201 F200 00 : 01: 02 : 03 : 04 : 05 : 06 : 07 : 08 : 09 00 45 Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 AF XRA A Clear accumulator and flags 2 8001 0E,0A MVI C, (0A)H Set N count in [C] 3 8003 16,00 MVI D , 00 Clear [D] 4 8005 21,00,81 LXIH 8100 Load HL pair with specified data 5 8008 86 LOOP ADD M Add memory to [A] 6 8009 27 DAA Decimal adjust accumulator 7 800A D2,0E,80 JNC(Ahead) Jump on no carry to ahead address 8 800D 14 INR D Increment [D] by one 9 800E 23 Ahead INX H Update memory 10 800F 0D DCR C Decrement count 11 8010 C2,08,80 JNZ(LOOP) Jump on no zero to perform loop 12 8013 6F MOV L,A Move [A] to [L] 13 8014 62 MOV H,D Move [D] to [H] 14 8015 22,00,F2 SHLD F200 Store contents of HL pair to specified consecutive locations 15 8018 CF RST 1 Restart K. Adisesha 9
Assembly Language Programs 9) PROGRAM FOR ADDITION OF HEXA-DECIMAL NUMBERS UNTILL ‘FF’ IS ENCOUNTERED Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 AF XRA A Clear accumulator and flags 2 8001 32,F9,FF LOOP STA FFF9 Store contents of accumulator in specified location 3 8004 F5 PUSH PSW Push [A] and flags to stack 4 8005 CD,D3,06 CALL(UPDDT) Call display subroutine for data field 5 8008 11,FF,FF LXID FFFF Implement a delay of 0.5 s using 6 800B CD,BE,04 CALL(DELAY) monitor delay subroutine 7 800E F1 POP PSW Pop[A] and flags off stack 8 800F 3C INR A Increment contents of [A] by one 9 8010 C2,01,80 JNZ (LOOP) Perform the loop until [A] becomes zero 10 8013 76 HLT Halt OUTPUT: ‘00’ up to ‘FF’ is displayed in data field. K. Adisesha 10
Assembly Language Programs 10) PROGRAM FOR FOUR DIGIT BCD ADDITION Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 21,00,F0 LXIH F000 Load HL pair with specified data 2 8003 01,00,F1 LXIB F100 Load BC pair with specified data 3 8006 11,00,F2 LXID F200 Load DE pair with specified data 4 8009 3E,02 MVI A, (02) Specify the number of bytes 5 800B 32,00,81 LOOP STA 8100 Save the count 6 800E 0A LDAX B Load [A] indirectly from address specified by BC pair 7 800F 8E ADC M Add memory to [A] with carry 8 8010 27 DAA Decimal adjust accumulator 9 8011 12 STAX D Store contents of [A] indirectly in location specified by DE pair 10 8012 23 INX H Update memory 11 8013 03 INX B Update BC register pair 12 8014 13 INX D Update DE register pair 13 8015 3A,00,81 LDA 8100 Load [A] from specified location 14 8018 3D DCR A Decrement count 15 8019 C2,0B,80 JNZ (LOOP) Jump on no zero to perform loop 16 801C D2,24,80 JNC (Ahead 1) Jump on no carry to ahead address Move immediately to [A] the 17 801F 3E,01 MVI A, 01 data(01)H Jump unconditionally to ahead 18 8021 C3,26,80 JMP (Ahead 2) address Move immediately to [A] the 19 8024 3E,00 Ahead 1 MVI A, 00 data(00)H Store contents of [A] indirectly in 20 8026 12 Ahead 2 STAX D address specified by DE pair Restart 21 8027 CF RST 1 K. Adisesha 11
Assembly Language Programs INPUT(X) F101 : F100 57 : 93 INPUT(Y) F001 : F000 64 : 21 OUTPUT(X+Y) F202 : F201 : F200 01: 22 : 14 K. Adisesha 12
Assembly Language Programs 11) PROGRAM TO FIND 2`S COMPLEMENT OF 8 BIT/ 16 BIT NUMBER Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 06,01/(02) MVI B,01/(02) Move to [B] (01) for 8-bit & (02) for 16-bit complement of data 2 8002 11,01,00 LXID 0001 Load DE pair with specified data 3 8005 21,00,F0 LXIH F000 Load HL pair with specified data 4 8008 7E LOOP MOV A,M Copy contents of memory to [A] 5 8009 2F CMA Complement contents of [A] 6 800A 77 MOV M,A Copy contents of [A] to memory 7 800B 05 DCR B Decrement [B] by one 8 800C CA, 13,80 JZ (Ahead) Jump on zero to ahead address 9 800F 23 INX H Update memory 10 8010 C3,08,80 JMP(Loop) Jump unconditionally to perform loop 11 8013 2A,00,F0 Ahead LHLD F000 Load contents of HL pair from specified locations 12 8016 19 DAD D Add HL and DE pair of registers 13 8017 22,00,F1 SHLD F100 Store contents of HL pair to specified locations 14 801A CF RST 1 Restart DATA INPUT OUTPUT(2`s complement) K. Adisesha 13
Assembly Language Programs 8-Bit F000 : 7A F100 : 87 16-Bit F001 : F000 :: 1A: 26 F101 : F100 :: E5: DA 12) PROGRAM FOR SUB TRACTION OF TWO 16-BIT BCD NUMBERS (X>Y) Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 11,86,97 LXID(9786) Load DE pair with specified data 2 8003 01,59,32 LXIB(3259) Load BC pair with specified data 3 8006 CD,20, 80 CALL(Sub-BCD) Call subroutine for BCD subtraction 4 8009 6F MOV L,A Copy contents of [A] to [L] 5 800C 5A MOV E,D Copy contents of [D] to [E] 6 800D 48 MOV C,B Copy contents of [B] to [C] 7 800E CD,20,80 CALL(Sub-BCD) Call subroutine for BCD subtraction 8 800F 67 MOV H,A Copy contents of [A] to [H] 9 8012 22,00,F0 SHLD F000 Store contents of HL pair to specified locations 10 8013 CF RST 1 Restart 12 8020 3E,99 Sub-BCD MVI A,99 Move to [A] the given data to subtract using 99` complement 13 8017 93 SUB E Subtract [E] from [A] 14 8018 3C INR A Increment [A] by 1 15 8019 81 ADD C Add [C] to [A] 16 801A 27 DAA Decimal adjust accumulator 17 801B C9 RET Return from subroutine unconditionally K. Adisesha 14
Assembly Language Programs OUTPUT F001: F000 :: 65 : 27 13) PROGRAM FOR BLOCK EXCHANGE Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 21,00,F0 LXIH F000 Load HL pair with specified address 2 8003 11,00,F1 LXID F100 Load HL pair with specified address 3 8006 0E,10 MVI C,(10)H Set counter in [C] for N counts 4 8008 1A LOOP LDAX D Load [A] indirectly from address indicated by DE pair 5 8009 46 MOV B,M Copy contents of memory to[B] 6 800A 77 MOV M,A Copy contents of [A] to memory 7 800B 78 MOV A,B Copy contents of [B] to [A] 8 800C 12 STAX D Store contents of [A] indirectly onto address in DE pair 9 800D 23 INX H Update memory 10 800E 13 INX D Update DE register pair 11 800F 0D DCR C Decrement [C] by 1 12 8010 C2,08,80 JNZ(Loop) Perform the loop until [C] becomes zero 13 8013 CF RST 1 Restart INPUT F000:F001:F002:F003:F004:F005:F006:F007:F008:F009:F00A:F00B:F00C:F00D:F00E:F00F 00 : 01 : 02 : 03 : 04 : 05 : 06 : 07 : 08 : 09 : 0A : 0B : 0C : 0D : 0E : 0F F100:F101:F102:F103:F104:F105:F106:F107:F108:F109:F10A:F10B:F10C:F10D:F10E:F10F K. Adisesha 15
Assembly Language Programs 10 : 11 : 12 : 13 : 14 : 15 : 16 : 17 : 18 : 19 : 1A : 1B : 1C : 1D : 1E : 1F F000:F001:F002:F003:F004:F005:F006:F007:F008:F009:F00A:F00B:F00C:F00D:F00E:F00F 10 : 11 : 12 : 13 : 14 : 15 : 16 : 17 : 18 : 19 : 1A : 1B : 1C : 1D : 1E : 1F F100:F101:F102:F103:F104:F105:F106:F107:F108:F109:F10A:F10B:F10C:F10D:F10E:F10F 00 : 01 : 02 : 03 : 04 : 05 : 06 : 07 : 08 : 09 : 0A : 0B : 0C : 0D : 0E : 0F OUTPUT K. Adisesha 16
Assembly Language Programs 14) PROGRAM FOR SORTING AN ARRAY OF ‘N-NUMBERS’ IN ASCENDING ORDER K. Adisesha 17
Assembly Language Programs INPUT F100:F101:F102:F103:F104:F105:F106:F107:F108:F109 0A : 01 : 09 : 05 : 03 : 06 : 08 : 07 : 04 : 02 Sl no. ADDRESS HEX CODE LABE MNEMONICS COMMENTS L 1 8000 AF XRA A Clear accumulator & flags 2 8001 06,0B MVI B,0B Move a count (N+1) in [B] 3 8003 48 START MOV C,B Copy contents of [B] to [C] 4 8004 0D DCR C Decrement contents of [C] by one 5 8005 21,00,F1 LXIH F100 Load the specified address in HL pair 6 8008 7E LOOP MOV A,M Copy contents of [M] to [A] 7 8009 23 INX H Update memory 8 800A BE CMP M Compare memory with accumulator 9 800B DA,13,80 JC (AHEAD) Jump on carry to ahead address 10 800E 56 MOV D,M Copy contents of [M] to [D] 11 800F 77 MOV M,A Copy contents of [A] to [M] 12 8010 2B DCX H Decrement HL pair by one 13 8011 72 MOV M,D Copy contents of [D] to [M] 14 8012 23 INX H Increment contents of HL pair by one 15 8013 0D AHEAD DCR C Decrement contents of [C] by one 16 8014 C2,08,80 JNZ (LOOP) Jump on no zero to perform the loop 17 8017 05 DCR B Decrement count in [B] 18 8018 C2,03,80 JNZ (START) Jump on no zero to specified address 19 801B CF RST 1 Restart K. Adisesha 18
Assembly Language Programs OUTPUT F100:F101:F102:F103:F104:F105:F106:F107:F108:F109 01 : 02 : 03 : 04 : 05 : 06 : 07 : 08 : 09 : 0A 15) PROGRAM TO CHECK 2-OUT-OF-5 CODE K. Adisesha 19
Assembly Language Programs Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 3A,00,F0 LDA F000 Load data into accumulator from specified location 2 8003 0E,05 MVI C,05 Move a count (05)H in [C] 3 8005 16,00 MVI D,00 Clear contents of [D] 4 8007 E6,E0 ANI E0 Logical AND (E0) H with [A] 5 8009 C2,23,80 JNZ (AHEAD 1) Jump on no zero to specified address 6 800C 3A,00,F0 LDA F000 Load data into accumulator from specified location 7 800F 0F LOOP RRC Rotate contents of [A] to right 8 8010 D2,14,80 JNC(AHEAD 2) Jump on no carry to ahead address 9 8013 14 INR D Increment count in [D] 10 8014 0D AHEAD 2 DCR C Decrement contents of [C] by one 11 80015 C2,0F,80 JNZ(LOOP) Jump on no zero to perform the loop 12 8018 7A MOV A,D Copy contents of [D] to [A] 13 8019 FE,02 CPI ,02 Compare (02) H immediately with [A] 14 801B C2,23,80 JNZ(AHEAD 1) Jump on no zero to specified address 15 801E 3E,FF MVI A, FF Move ‘FF’ to [A] immediately 16 8020 C2,25,80 JMP(AHEAD 3) Jump to specified location unconditionally 17 8023 3E,00 AHEAD 1 MVI A, 00 Move ‘00’ to [A] immediately 18 8025 32,00,F1 AHEAD 3 STA F100 Store data from accumulator into specified location 19 8028 CF RST 1 Restart INPUT OUTPUT F000: 11 F100: FF F000: 13 F100: 00 16) PROGRAM TO MULTIPLY TWO DIGIT BCD K. Adisesha 20
Assembly Language Programs 1 8000 21,00,00 LXIH (0000 )H Move a count (0000)H in HL pair 2 8003 3A,00,F0 LDA F000 Load data into accumulator from specified location 3 8006 47 MOV B,A Copy contents of [A] to [B] 4 8007 3A,01,F0 LDA F001 Load data into accumulator from specified location 5 800A 4F MOV C,A Copy contents of [A] to [C] 6 800B 79 START MOV A,C Copy contents of [C] to [A] 7 800C 85 ADD L Add [L] to accumulator 8 800D 27 DAA Decimal adjust [A] 9 800E 6F MOV L,A Copy contents of [A] to [L] 10 800F 3E,00 MVI A,00 Clear contents of [A] 11 80011 8C ADC H Add contents of [H] to [A] 12 8012 27 DAA Decimal adjust [A] 13 8013 67 MOV H,A Copy contents of [A] to [H] 14 8014 78 MOV A,B Copy contents of [B] to [A] 15 8015 C6,99 ADI ,99 Add immediately to accumulator 99 16 8017 27 DAA Decimal adjust [A] 17 8018 47 MOV B,A Copy contents of [A] to [B] 18 8019 C2,0B,80 JNZ(START) Jump on no zero to specified address 19 801C 22,00,F1 SHLD(F100) Store data from HL pair onto specified location 20 801F CF RST 1 Restart INPUT OUTPUT F001: F000 F101: F100 11 : 12 01 : 32 K. Adisesha 21

Assembly language programming

  • 1.
    Assembly Language Programs 1) PROGRAM TO EXCHANGE TWO 16 BIT NUMBERS Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 2A,00,F0 LHLD F000 Load memory from specified locations. 2 8003 EB XCHG Exchange contents of HL & DE pairs. 3 8004 2A,00,F1 LHLD F100 Load memory from specified locations. 4 8007 22,00,F0 SHLD F000 Store memory to specified locations. 5 800A EB XCHG Exchange contents of HL & DE pairs. 6 800B 22,00,F1 SHLD F200 Store memory to specified locations. 7 800E CF RST 1 Restart INPUT (Before execution) F001 ; F000 F101 ; F100 12 ; AB 3C ; DE OUTPUT(After execution) F001 ; F000 F101 ; F100 3C ; DE 12 ; AB K. Adisesha 1
  • 2.
    Assembly Language Programs 2) PROGRAM TO ADD OR SUBTRACT TWO 8 BIT NUMBERS Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 3E, XX MVI A, XX Move immediately to [A] the data XX 2 8002 06, YY MVI B, YY Move immediately to [B] the data YY 3 8004 80/(90) ADD B/SUB B Add(or subtract) [B] with [A] 4 8005 32,00,F0 STA F000 Store contents of [A] in specified location 5 8008 D2,10,80 JNC (Ahead 1) Jump on no carry to specified location 6 800B 3E,01 MVIA, 01 Move immediately to [A] the data(01)H 7 800D C3,12,80 JMP(Ahead 2) Jump unconditionally ahead 8 8010 3E,00 Ahead 1 MVIA, 00 Move immediately to [A] the data(00)H 9 8012 32,01,F0 Ahead 2 STA F001 Store contents of [A] in specified location 10 8015 CF RST1 Restart INPUT : XX, YY 1) 2B, 1A 2) 2B, FA OUTPUT TRIAL Addition (XX+YY) Subtraction (XX-YY) ADDRESS F001: F000 F001: F000 1 00 : 45 00 : 25 2 01 : 25 01 : 31 K. Adisesha 2
  • 3.
    Assembly Language Programs 3) PROGRAM TO ADD TWO 16 BIT NUMBERS Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 AF XRA A Clear accumulator and Flag 2 8001 2A, 00, F0 LHLD F000 Load memory from specified locations 3 8004 EB XCHG Exchange contents of HL & DE pairs 4 8005 2A,00,F1 LHLD F100 Load memory from specified locations 5 8008 19 DAD D Add HL & DE pairs 6 8009 22,00,F2 SHLD F200 Store memory to specified locations 7 800C D2,10,80 JNC (Ahead) Jump on no carry to ahead address 8 800F 3C INR A Increment contents of accumulator by one 9 8010 32,02,F2 Ahead STA F202 Store contents of [A] in specified location 10 8013 CF RST1 Restart F001: F000 (X) 4A : 2C F101: F100 (Y) ED : 5B F202:F201: F200 (X+Y) 01 : 37 : 87 K. Adisesha 3
  • 4.
    Assembly Language Programs 4) PROGRAM TO SUBTRACT TWO 16 BIT NUMBERS (X>Y) Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 2A,00,F0 LHLD F000 Load memory from specified locations 2 8003 EB XCHG Exchange contents of HL & DE pairs 3 8004 2A,00,F1 LHLD F100 Load memory from specified locations 4 8007 7D MOV A, L Move contents of [L] to [A] 5 8008 93 SUB E Subtract [E] from [A] 6 8009 32,00,F2 STA F200 Store result in specified location 7 800C 7C MOV A, H Move contents of [H] to [A] 8 800D 9A SBB D Subtract [D] from [A] with borrow 9 800E 32,01,F2 STA F201 Store result in specified location 10 8011 CF RST 1 Restart F001: F000 (X) FA : 2C F101: F100 (Y) BD : 5B F202:F201: F200 (X-Y) 3C : D1 K. Adisesha 4
  • 5.
    Assembly Language Programs 5) PROGRAM TO ADD TWO N BYTE NUMBERS Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 21,00,F0 LXIH F000 Load HL pair with specified data 2 8003 01,00,F1 LXIB F100 Load BC pair with specified data 3 8006 11,00,F2 LXID F200 Load DE pair with specified data 4 8009 3E,(NN) MVI A, (NN) Specify the number of bytes 5 800B 32,00,81 LOOP STA 8100 Save the count 6 800E AF XRA A Clear accumulator and flags 7 800F 0A LDAX B Load [A] indirectly from address specified by BC pair 8 8010 8E ADC M Add memory to [A] with carry 9 8011 12 STAX D Store contents of [A] indirectly in location specified by DE pair 10 8012 23 INX H Update memory 11 8013 03 INX B Update BC register pair 12 8014 13 INX D Update DE register pair 13 8015 3A,00,81 LDA 8100 Load [A] from specified location 14 8018 3D DCR A Decrement count 15 8019 C2,0B,80 JNZ (LOOP) Jump on no zero to perform loop 16 801C D2,24,80 JNC (Ahead 1) Jump on no carry to ahead address 17 801F 3E,01 MVI A, 01 Move immediately to [A] the data(01)H 18 8021 C3,26,80 JMP (Ahead 2) Jump unconditionally to ahead address 19 8024 3E,00 Ahead 1 MVI A, 00 Move immediately to [A] the data(00)H 20 8026 12 Ahead 2 STAX D Store contents of [A] indirectly in address specified by DE pair 21 8027 CF RST 1 Restart K. Adisesha 5
  • 6.
    Assembly Language Programs INPUT(X) F103 : F102 : F101 : F100 A4 : E6 : F3 : D7 INPUT(Y) F003 : F002 : F001 : F000 C3 : 54 : A2 : 1B OUTPUT(X+Y) F204:F203 : F202 : F201 : F200 01: 68 : 3B: 95: F2 K. Adisesha 6
  • 7.
    Assembly Language Programs 6) PROGRAM FOR BLOCK TRANSFER Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 16,10 MVI D, (10)H Set count in [D] 2 8002 21,00,81 LXIH 8100 Load HL pair with specified address 3 8005 01,00,82 LXIB 8200 Load BC pair with specified address 4 8008 7E LOOP MOV A,M Move contents of memory to [A] 5 8009 02 STAX B Store contents of [A] indirectly to location specified by BC pair 6 800A 23 INX H Update memory 7 800B 03 INX B Update BC pair 8 800C 15 DCR D Decrement count in [D] 9 800D C2,08,80 JNZ (LOOP) Jump on no zero to perform the loop 10 8010 CF RST1 Restart INPUT 8100:810:8102:8103:8104:8105:8106:8107:8108:8109:810A:810B:810C:810D:810E:810F 00 : 01: 02 : 03 : 04 : 05 : 06 : 07 : 08 : 09 : 0A : 0B : 0C : 0D : 0E : 0F OUTPUT 8200:8201:8202:8203:8204:8205:8206:8207:8208:8209:820A:820B:820C:820D:820E:820F 00 : 01: 02 : 03 : 04 : 05 : 06 : 07 : 08 : 09 : 0A : 0B : 0C : 0D : 0E : 0F K. Adisesha 7
  • 8.
    Assembly Language Programs 7) PROGRAM TO BLOCK TRANSFER IN REVERSE ORDER Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 16,10 MVI D, (10)H Set count in [D] 2 8002 21,00,81 LXIH 8100 Load HL pair with specified address 3 8005 01,0F,82 LXIB 820F Load BC pair with specified address 4 8008 7E LOOP MOV A,M Move contents of memory to [A] 5 8009 02 STAX B Store contents of [A] indirectly to location specified by BC pair 6 800A 23 INX H Update memory 7 800B 0B DCX B Decrement BC pair by one 8 800C 15 DCR D Decrement count in [D] 9 800D C2,08,80 JNZ (LOOP) Jump on no zero to perform the loop 10 8010 CF RST1 Restart INPUT 8100:810:8102:8103:8104:8105:8106:8107:8108:8109:810A:810B:810C:810D:810E:810F 00 : 01: 02 : 03 : 04 : 05 : 06 : 07 : 08 : 09 : 0A : 0B : 0C : 0D : 0E : 0F OUTPUT 820F:820E:820D:820C:820B:820A:8209:8208:8207:8206:8205:8204:8203:8202:8201:8200 0F : 0E : 0D : 0C : 0B : 0A : 09 : 08 : 07 : 06 : 05 : 04 : 03 : 02 : 01 : 00 K. Adisesha 8
  • 9.
    Assembly Language Programs 8) PROGRAM TO ADD N DECIMAL NUMBERS (N= 10) INPUT OUTPUT 8100:810:8102:8103:8104:8105:8106:8107:8108:8109 F201 F200 00 : 01: 02 : 03 : 04 : 05 : 06 : 07 : 08 : 09 00 45 Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 AF XRA A Clear accumulator and flags 2 8001 0E,0A MVI C, (0A)H Set N count in [C] 3 8003 16,00 MVI D , 00 Clear [D] 4 8005 21,00,81 LXIH 8100 Load HL pair with specified data 5 8008 86 LOOP ADD M Add memory to [A] 6 8009 27 DAA Decimal adjust accumulator 7 800A D2,0E,80 JNC(Ahead) Jump on no carry to ahead address 8 800D 14 INR D Increment [D] by one 9 800E 23 Ahead INX H Update memory 10 800F 0D DCR C Decrement count 11 8010 C2,08,80 JNZ(LOOP) Jump on no zero to perform loop 12 8013 6F MOV L,A Move [A] to [L] 13 8014 62 MOV H,D Move [D] to [H] 14 8015 22,00,F2 SHLD F200 Store contents of HL pair to specified consecutive locations 15 8018 CF RST 1 Restart K. Adisesha 9
  • 10.
    Assembly Language Programs 9) PROGRAM FOR ADDITION OF HEXA-DECIMAL NUMBERS UNTILL ‘FF’ IS ENCOUNTERED Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 AF XRA A Clear accumulator and flags 2 8001 32,F9,FF LOOP STA FFF9 Store contents of accumulator in specified location 3 8004 F5 PUSH PSW Push [A] and flags to stack 4 8005 CD,D3,06 CALL(UPDDT) Call display subroutine for data field 5 8008 11,FF,FF LXID FFFF Implement a delay of 0.5 s using 6 800B CD,BE,04 CALL(DELAY) monitor delay subroutine 7 800E F1 POP PSW Pop[A] and flags off stack 8 800F 3C INR A Increment contents of [A] by one 9 8010 C2,01,80 JNZ (LOOP) Perform the loop until [A] becomes zero 10 8013 76 HLT Halt OUTPUT: ‘00’ up to ‘FF’ is displayed in data field. K. Adisesha 10
  • 11.
    Assembly Language Programs 10) PROGRAM FOR FOUR DIGIT BCD ADDITION Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 21,00,F0 LXIH F000 Load HL pair with specified data 2 8003 01,00,F1 LXIB F100 Load BC pair with specified data 3 8006 11,00,F2 LXID F200 Load DE pair with specified data 4 8009 3E,02 MVI A, (02) Specify the number of bytes 5 800B 32,00,81 LOOP STA 8100 Save the count 6 800E 0A LDAX B Load [A] indirectly from address specified by BC pair 7 800F 8E ADC M Add memory to [A] with carry 8 8010 27 DAA Decimal adjust accumulator 9 8011 12 STAX D Store contents of [A] indirectly in location specified by DE pair 10 8012 23 INX H Update memory 11 8013 03 INX B Update BC register pair 12 8014 13 INX D Update DE register pair 13 8015 3A,00,81 LDA 8100 Load [A] from specified location 14 8018 3D DCR A Decrement count 15 8019 C2,0B,80 JNZ (LOOP) Jump on no zero to perform loop 16 801C D2,24,80 JNC (Ahead 1) Jump on no carry to ahead address Move immediately to [A] the 17 801F 3E,01 MVI A, 01 data(01)H Jump unconditionally to ahead 18 8021 C3,26,80 JMP (Ahead 2) address Move immediately to [A] the 19 8024 3E,00 Ahead 1 MVI A, 00 data(00)H Store contents of [A] indirectly in 20 8026 12 Ahead 2 STAX D address specified by DE pair Restart 21 8027 CF RST 1 K. Adisesha 11
  • 12.
    Assembly Language Programs INPUT(X) F101 : F100 57 : 93 INPUT(Y) F001 : F000 64 : 21 OUTPUT(X+Y) F202 : F201 : F200 01: 22 : 14 K. Adisesha 12
  • 13.
    Assembly Language Programs 11) PROGRAM TO FIND 2`S COMPLEMENT OF 8 BIT/ 16 BIT NUMBER Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 06,01/(02) MVI B,01/(02) Move to [B] (01) for 8-bit & (02) for 16-bit complement of data 2 8002 11,01,00 LXID 0001 Load DE pair with specified data 3 8005 21,00,F0 LXIH F000 Load HL pair with specified data 4 8008 7E LOOP MOV A,M Copy contents of memory to [A] 5 8009 2F CMA Complement contents of [A] 6 800A 77 MOV M,A Copy contents of [A] to memory 7 800B 05 DCR B Decrement [B] by one 8 800C CA, 13,80 JZ (Ahead) Jump on zero to ahead address 9 800F 23 INX H Update memory 10 8010 C3,08,80 JMP(Loop) Jump unconditionally to perform loop 11 8013 2A,00,F0 Ahead LHLD F000 Load contents of HL pair from specified locations 12 8016 19 DAD D Add HL and DE pair of registers 13 8017 22,00,F1 SHLD F100 Store contents of HL pair to specified locations 14 801A CF RST 1 Restart DATA INPUT OUTPUT(2`s complement) K. Adisesha 13
  • 14.
    Assembly Language Programs 8-Bit F000 : 7A F100 : 87 16-Bit F001 : F000 :: 1A: 26 F101 : F100 :: E5: DA 12) PROGRAM FOR SUB TRACTION OF TWO 16-BIT BCD NUMBERS (X>Y) Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 11,86,97 LXID(9786) Load DE pair with specified data 2 8003 01,59,32 LXIB(3259) Load BC pair with specified data 3 8006 CD,20, 80 CALL(Sub-BCD) Call subroutine for BCD subtraction 4 8009 6F MOV L,A Copy contents of [A] to [L] 5 800C 5A MOV E,D Copy contents of [D] to [E] 6 800D 48 MOV C,B Copy contents of [B] to [C] 7 800E CD,20,80 CALL(Sub-BCD) Call subroutine for BCD subtraction 8 800F 67 MOV H,A Copy contents of [A] to [H] 9 8012 22,00,F0 SHLD F000 Store contents of HL pair to specified locations 10 8013 CF RST 1 Restart 12 8020 3E,99 Sub-BCD MVI A,99 Move to [A] the given data to subtract using 99` complement 13 8017 93 SUB E Subtract [E] from [A] 14 8018 3C INR A Increment [A] by 1 15 8019 81 ADD C Add [C] to [A] 16 801A 27 DAA Decimal adjust accumulator 17 801B C9 RET Return from subroutine unconditionally K. Adisesha 14
  • 15.
    Assembly Language Programs OUTPUT F001: F000 :: 65 : 27 13) PROGRAM FOR BLOCK EXCHANGE Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 21,00,F0 LXIH F000 Load HL pair with specified address 2 8003 11,00,F1 LXID F100 Load HL pair with specified address 3 8006 0E,10 MVI C,(10)H Set counter in [C] for N counts 4 8008 1A LOOP LDAX D Load [A] indirectly from address indicated by DE pair 5 8009 46 MOV B,M Copy contents of memory to[B] 6 800A 77 MOV M,A Copy contents of [A] to memory 7 800B 78 MOV A,B Copy contents of [B] to [A] 8 800C 12 STAX D Store contents of [A] indirectly onto address in DE pair 9 800D 23 INX H Update memory 10 800E 13 INX D Update DE register pair 11 800F 0D DCR C Decrement [C] by 1 12 8010 C2,08,80 JNZ(Loop) Perform the loop until [C] becomes zero 13 8013 CF RST 1 Restart INPUT F000:F001:F002:F003:F004:F005:F006:F007:F008:F009:F00A:F00B:F00C:F00D:F00E:F00F 00 : 01 : 02 : 03 : 04 : 05 : 06 : 07 : 08 : 09 : 0A : 0B : 0C : 0D : 0E : 0F F100:F101:F102:F103:F104:F105:F106:F107:F108:F109:F10A:F10B:F10C:F10D:F10E:F10F K. Adisesha 15
  • 16.
    Assembly Language Programs 10 : 11 : 12 : 13 : 14 : 15 : 16 : 17 : 18 : 19 : 1A : 1B : 1C : 1D : 1E : 1F F000:F001:F002:F003:F004:F005:F006:F007:F008:F009:F00A:F00B:F00C:F00D:F00E:F00F 10 : 11 : 12 : 13 : 14 : 15 : 16 : 17 : 18 : 19 : 1A : 1B : 1C : 1D : 1E : 1F F100:F101:F102:F103:F104:F105:F106:F107:F108:F109:F10A:F10B:F10C:F10D:F10E:F10F 00 : 01 : 02 : 03 : 04 : 05 : 06 : 07 : 08 : 09 : 0A : 0B : 0C : 0D : 0E : 0F OUTPUT K. Adisesha 16
  • 17.
    Assembly Language Programs 14) PROGRAM FOR SORTING AN ARRAY OF ‘N-NUMBERS’ IN ASCENDING ORDER K. Adisesha 17
  • 18.
    Assembly Language Programs INPUT F100:F101:F102:F103:F104:F105:F106:F107:F108:F109 0A : 01 : 09 : 05 : 03 : 06 : 08 : 07 : 04 : 02 Sl no. ADDRESS HEX CODE LABE MNEMONICS COMMENTS L 1 8000 AF XRA A Clear accumulator & flags 2 8001 06,0B MVI B,0B Move a count (N+1) in [B] 3 8003 48 START MOV C,B Copy contents of [B] to [C] 4 8004 0D DCR C Decrement contents of [C] by one 5 8005 21,00,F1 LXIH F100 Load the specified address in HL pair 6 8008 7E LOOP MOV A,M Copy contents of [M] to [A] 7 8009 23 INX H Update memory 8 800A BE CMP M Compare memory with accumulator 9 800B DA,13,80 JC (AHEAD) Jump on carry to ahead address 10 800E 56 MOV D,M Copy contents of [M] to [D] 11 800F 77 MOV M,A Copy contents of [A] to [M] 12 8010 2B DCX H Decrement HL pair by one 13 8011 72 MOV M,D Copy contents of [D] to [M] 14 8012 23 INX H Increment contents of HL pair by one 15 8013 0D AHEAD DCR C Decrement contents of [C] by one 16 8014 C2,08,80 JNZ (LOOP) Jump on no zero to perform the loop 17 8017 05 DCR B Decrement count in [B] 18 8018 C2,03,80 JNZ (START) Jump on no zero to specified address 19 801B CF RST 1 Restart K. Adisesha 18
  • 19.
    Assembly Language Programs OUTPUT F100:F101:F102:F103:F104:F105:F106:F107:F108:F109 01 : 02 : 03 : 04 : 05 : 06 : 07 : 08 : 09 : 0A 15) PROGRAM TO CHECK 2-OUT-OF-5 CODE K. Adisesha 19
  • 20.
    Assembly Language Programs Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS Sl no. ADDRESS HEX CODE LABEL MNEMONICS COMMENTS 1 8000 3A,00,F0 LDA F000 Load data into accumulator from specified location 2 8003 0E,05 MVI C,05 Move a count (05)H in [C] 3 8005 16,00 MVI D,00 Clear contents of [D] 4 8007 E6,E0 ANI E0 Logical AND (E0) H with [A] 5 8009 C2,23,80 JNZ (AHEAD 1) Jump on no zero to specified address 6 800C 3A,00,F0 LDA F000 Load data into accumulator from specified location 7 800F 0F LOOP RRC Rotate contents of [A] to right 8 8010 D2,14,80 JNC(AHEAD 2) Jump on no carry to ahead address 9 8013 14 INR D Increment count in [D] 10 8014 0D AHEAD 2 DCR C Decrement contents of [C] by one 11 80015 C2,0F,80 JNZ(LOOP) Jump on no zero to perform the loop 12 8018 7A MOV A,D Copy contents of [D] to [A] 13 8019 FE,02 CPI ,02 Compare (02) H immediately with [A] 14 801B C2,23,80 JNZ(AHEAD 1) Jump on no zero to specified address 15 801E 3E,FF MVI A, FF Move ‘FF’ to [A] immediately 16 8020 C2,25,80 JMP(AHEAD 3) Jump to specified location unconditionally 17 8023 3E,00 AHEAD 1 MVI A, 00 Move ‘00’ to [A] immediately 18 8025 32,00,F1 AHEAD 3 STA F100 Store data from accumulator into specified location 19 8028 CF RST 1 Restart INPUT OUTPUT F000: 11 F100: FF F000: 13 F100: 00 16) PROGRAM TO MULTIPLY TWO DIGIT BCD K. Adisesha 20
  • 21.
    Assembly Language Programs 1 8000 21,00,00 LXIH (0000 )H Move a count (0000)H in HL pair 2 8003 3A,00,F0 LDA F000 Load data into accumulator from specified location 3 8006 47 MOV B,A Copy contents of [A] to [B] 4 8007 3A,01,F0 LDA F001 Load data into accumulator from specified location 5 800A 4F MOV C,A Copy contents of [A] to [C] 6 800B 79 START MOV A,C Copy contents of [C] to [A] 7 800C 85 ADD L Add [L] to accumulator 8 800D 27 DAA Decimal adjust [A] 9 800E 6F MOV L,A Copy contents of [A] to [L] 10 800F 3E,00 MVI A,00 Clear contents of [A] 11 80011 8C ADC H Add contents of [H] to [A] 12 8012 27 DAA Decimal adjust [A] 13 8013 67 MOV H,A Copy contents of [A] to [H] 14 8014 78 MOV A,B Copy contents of [B] to [A] 15 8015 C6,99 ADI ,99 Add immediately to accumulator 99 16 8017 27 DAA Decimal adjust [A] 17 8018 47 MOV B,A Copy contents of [A] to [B] 18 8019 C2,0B,80 JNZ(START) Jump on no zero to specified address 19 801C 22,00,F1 SHLD(F100) Store data from HL pair onto specified location 20 801F CF RST 1 Restart INPUT OUTPUT F001: F000 F101: F100 11 : 12 01 : 32 K. Adisesha 21