0% found this document useful (0 votes)
23 views

Ss MP Print

Uploaded by

nishanathpathatt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Ss MP Print

Uploaded by

nishanathpathatt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

SUM OF 2 8-BIT NOS

ADDRESS MNEMONICS COMMENTS


1000 MOV AL, [2000] Load the first number into AL
1004 MOV BL, [2001] Load the second number into BL
1008 ADD AL, BL Add the number in BL to AL
100A MOV [2002], AL Store the result to location 2002
100E HLT Stop the program

INPUT:
0000 : 2000 02 03 FF
FF FF FF FF FF

OUTPUT:
0000 : 2000 02 03 05
FF FF FF FF FF

SUM OF N 8 BIT NOS

ADDRESS MNEMONICS COMMENTS


1000 MOV CL, [2000] Read the count into CL
1004 MOV SI, 2001 Load the starting address 2001 into SI
1007 MOV AL, 00 Initialize AL with 00
1009 (loop) ADD AL, [SI] Add the content at address SI to AL
100B INC SI Move to the next memory location
100C DEC CL Decrement the count in CL
100E JNZ 1009 (loop) Repeat the process until the count in CL is
zero
1010 MOV [2500], AL Store the result to location 2500
1014 HLT Stop the program

INPUT:
0000 : 2000 05 01 02
03 04 05 FF FF

OUTPUT:
0000 : 2500 0F FF FF
FF FF FF FF FF
SUM OF N 16 BIT NOS

ADDRESS MNEMONICS COMMENTS


1000 MOV CX, [2000] Load the count into CX
1004 (loop) MOV SI, 2002 Load the starting address 2002 into SI
1007 MOV AX, 0000 Initialize AX with 0000
100A ADD AX, [SI] Add the content at the address pointed by SI
to AX
100C INC SI Move to the next memory location
100D INC SI Move to the next memory location again
100E DEC CX Decrement the count in CX
100F JNZ 1004 (loop) Repeat the process until the count in CX is
zero
1011 MOV [2500], AX Store the result to location 2500
1015 HLT Stop the program

INPUT:
0000 : 2000 03 00 01
00 02 00 03 00

OUTPUT:
0000 : 2500 06 00 FF
FF FF FF FF FF
LARGEST FROM N 8 BIT NOS

ADDRESS MNEMONICS COMMENTS


1000 MOV CL, [2000] Load count into CL
1004 MOV SI, 2001 Load 2001 into SI
1007 MOV BL, [SI] Load value from SI into BL
1009 DEC CL Decrease CL by 1
100B (loop) INC SI Increase SI by 1
100C CMP [SI], BL Compare value at SI with BL
100E JBE 1012 (skip) Skip if value is below or equal
1010 MOV BL, [SI] Load next value into BL (if larger than
previous)
1012 (skip) DEC CL Decrease CL by 1
1014 JNZ 100B (loop) Repeat the loop until count is zero
1016 MOV [2500], BL Store result at location 2500
101A HLT Stop the program

INPUT:
0000 : 2000 05 0A 11
02 03 07 FF FF

OUTPUT:
0000 : 2500 11 FF FF
FF FF FF FF FF
FIBONACCI

ADDRESS MNEMONICS COMMENTS


1000 MOV CL, [2000] Load count into CL
1004 MOV AL, 00 Initialize AL with 0
1006 MOV BL, 01 Initialize BL with 1
1008 MOV DI, 3000 DI points to start of memory location
where sequence will be stored
100B MOV [DI], AL Store the first Fibonacci number
100D INC DI Proceed to next address
100E DEC CL Reduce count
1010 MOV [DI], BL Store the second Fibonacci number
1012 INC DI Point to next location
1013 DEC CL Reduce count
1015 (fibo) MOV AH, AL AH ← previous Fibonacci number
1017 ADD AH, BL AH ← AL + BL (next Fibonacci number)
1019 MOV AL, BL AL ← BL
101B MOV BL, AH BL ← AH
101D MOV [DI], BL Store next Fibonacci number
101F INC DI Move to next memory location
1020 DEC CL Reduce count
1022 JZ 1027 (done) If count = 0, stop the process
1024 JMP 1015 (fibo) Repeat the process if count ≠ 0
1027 (done) HLT Stop the program

INPUT:
0000 : 2000 09 FF FF
FF FF FF FF FF

OUTPUT:
0000 : 3000 00 01 01
02 03 05 08 0D
0000 : 3008 15 FF FF
FF FF FF FF FF
PRIME OR NOT

To check whether a number is prime or not (calling function):

ADDRESS MNEMONICS COMMENTS


1000 MOV AL, [2000] Read the value to AL
1002 CALL 1500 Call the subroutine located at address 1500
1004 MOV DL, BL Move the value in BL register into the DL
register
1006 HLT Stop the program

Subroutine to check prime or not:

ADDRESS MNEMONICS COMMENTS


1500 PUSH AX Save the current value of AX
1501 PUSH CX Save the current value of CX
1502 PUSH DX Save the current value of DX
1503 CMP AL, 01 Compare AL with 1
1505 JLE 1525 (n_prm) If AL ≤ 1, jump to location: 1525 (0 & 1
are non-prime)
1507 CMP AL, 02 Compare AL with 2
1509 JE 1520 (prm) If AL = 2, Jump to location: 1520 (2 is
prime)
150B MOV CL, 02 Initialize CL with 2
150D MOV AH, 00 Clear AH to 0 for division
150F (loop) MOV DX, AX Save AX in DX
1511 DIV CL Divide AX by CL & Store quotient in AL
while remainder in AH
1513 CMP AH, 00 Compare remainder with 0
1516 JE 1525 (n_prm) If remainder is 0, jump to 1525 (non-
prime)
1518 MOV AX, DX Retrieve AX from DX
151A INC CL Increment CL
151C CMP CL, AL Compare CL with AL
151E JB 150F (loop) If CL < AL, repeat the loop
1520 (prm) MOV BL, 01 Set BL to 1
1522 JMP 1527 (last) Jump to last section (location: 1523)
1525 MOV BL, 00 Set BL to 0
(n_prm)
1527 (last) POP DX Restore previous value to DX
1528 POP CX Restore previous value to CX
1529 POP AX Restore previous value to AX
152A RET Return to subroutine
i) INPUT:
0000 : 2000 09 FF FF
FF FF FF FF FF

OUTPUT:
0000 : 3000 00 FF FF
FF FF FF FF FF

ii)INPUT:
0000 : 2000 0D FF FF
FF FF FF FF FF

OUTPUT:
0000 : 3000 01 FF FF
FF FF FF FF FF
SUM OF N PRIME NOS

ADDRESS MNEMONICS COMMENTS


1000 MOV CL, [2000] Read count
1004 MOV SI, 2001 Initialize SI to point to first digit of list at
address 2001
1007 MOV AH, 00 Clear AH to 0
1009 (loop) MOV AL, [SI] Read the current list element to AL
100B CALL 1500 Call the subroutine at address 1500 to
check if AL is prime
100E CMP BL, 01 Compare BL with 1
1011 JNE 1015 (skip) If BL is not 1, Jump to location 1015
1013 ADD AH, AL Add the current element (if prime) to sum
1015 (skip) INC SI Increment SI
1016 DEC CL Decrement CL
1018 JNZ 1009 (loop) If CL is not zero, repeat
101A MOV [2500], AH Store the result location 2500
101E HLT Stop the program

INPUT:
0000 : 2000 05 01 0D
02 04 05 FF FF

OUTPUT:
0000 : 3000 14 FF FF
FF FF FF FF FF
FIRST N PRIME NUMBERS

ADDRESS MNEMONICS COMMENTS


1000 MOV CL, [2000H] Read count into CL
1004 MOV AL, 02 Source index start
1006 MOV Destination index start
DI,3000H

1009 (loop) CALL 1500H Call subroutine


100C CMP BL, 01H Compare if BL equals 01
100F JNE 1016 (skip) If not equal, skip
1011 MOV [DI], AL Else, write to destination
1013 INC DI Increment DI
1014 DEC CL Reduce count, decrement
CL
1016 (skip) INC AL Increment SI
1018 CMP CL, 00 Compare if CL is zero
101B JNE 1009 (loop) Repeat loop if CL is not
zero
101D HLT Stop the program

INPUT:
0000 : 2000 05 FF FF
FF FF FF FF FF

OUTPUT:
0000 : 3000 02 03 05
07 0B FF FF FF
SUM OF DIGITS OF AN 16- BIT NUMBER

ADDRESS MNEMONICS COMMENTS


1000 MOV AX, [2000] Read number into AX
1004 MOV CX, 00H Initialize sum = 0 (CX)
1007 (loop) MOV DX, 00H Clear DX
100A MOV BX, 10 Set divisor to 10
100D DIV BX Divide AX by BX
100F ADD CX, DX Add digit to sum
1011 CMP AX, 00H Check if AX is 0
1014 JNE 1007 (loop) Repeat if AX is not 0

1016 MOV [3000], CX Store sum


101A HLT Stop the program

INPUT:
0000 : 2000 34 12 FF
FF FF FF FF FF

OUTPUT:
0000 : 3000 0A FF FF
FF FF FF FF FF

You might also like