Write the program to generate the following series
800, 802, 806, 812, 820,830, 842, 856, 872, 890, 910, 932, 956,
982 ... 'N
Add the sum of digits of each number in the above series. Display
each sum number.
Ex. 900 = 8 + 0 + 0 = 8
806 = 8 + 0 + 6 = 14
Display how many of these sum numbers start with the digit 1.
If N is 900, the output of the program should be as follows:
800 802 806 812 820 830 842 856 872 890
8 10 14 11 10 11 14 19 17 17
The count of sum numbers which start with 1 = 9
Answers
Assumptions –
Assume that size “n” is stored at offset 500 and the first number(a) is stored at offset 501 and the common difference is stored at offset 502. Store the series into memory address offset 600.
Algorithm –
Store 500 to SI and 600 to DI Load data from offset 500 to register CL and set register CH to 00 (for count).
Increase the value of SI by 1.
Load first number(value) from next offset (i.e 501) to register AL.
Store the value of register AL to memory offset DI.
Increase DI by 1.
Decrease the CL by 1.
Load second number(common difference) from next offset (i.e 502) to register BL.
Add register AL and BL.
Store the result (value of register AL ) to memory offset DI.
Increase the value of SI by 1.
Loop above 3 till register CX gets 0.
Program –
MEMORY ADDRESS MNEMONICS COMMENT
400 MOV SI, 500 SI<-500
403 MOV CL, [SI] CL<-[SI]
405 MOV CH, 00 CH<-00
407 INC SI SI<-SI+1
408 MOV AL, [SI] AL<-[SI]
40A INC SI SI<-SI+1
40B MOV DI, 600 DI<-600
40E MOV [DI], AL [DI]<-AL
410 INC DI DI<-DI+1
411 DEC CL CL<-CL-1
412 MOV BL, [SI] BL<-[SI]
414 ADD AL, BL AL<-AL+BL
416 MOV [DI], AL [DI]<-AL
418 INC DI DI<-DI+1
419 LOOP 414 JUMP TO 414 IF CX!=0 and CX=CX-1
41B HLT end
Explanation –
MOV SI, 500: set the value of SI to 500.
MOV CL, [SI]: load data from offset SI to register CL.
MOV CH, 00: set value of register CH to 00.
INC SI: increase value of SI by 1.
MOV AL, [SI]: load value from offset SI to register AL
INC SI: increase value of SI by 1.
MOV DI, 500: set the value of DI to 600.
MOV [DI], AL: store value of register AL at offset DI.
INC DI: increase value of DI by 1.
DEC CL: decrease value of register CL by 1.
MOV BL, [SI]: load value from offset SI to register BL.
MUL BL: add value of register AL by BL.
MOV [DI], AL: store value of register AL at offset DI.
INC DI: increase value of DI by 1.
LOOP 414: jump to address 414 if CX not 0 and CX=CX-1.
HLT: stop.
Explanation:
write the program to generate the following sum 800,802,806,812,820,830,842,856,872,890,910,932,956,982....N add the sum of digits each number in the above series display the each sum number to write java program