Source program :
LXI H, XXXXH :Memory location to store the series MOV M, 00H :Store first number of series INX H :Go to next location MOV M, 01H :Store second number of series INX H :Go to next location MVI D, COUNT :Initialize counter MVI B, 00H :Initialize variable to store previous number MVI C, 01H :Initialize variable to store current number Back : MOV A, B :Load first number in accumulator ADD C :Add two numbers MOV B, C :Current number is now previous number MOV C, A :Save result as a new current number MOV M, A :Store next number in memory INX H :Go to next memory location DCR D :Decrement count JNZ Back :If count=0 go to Back HLT :Stop.
I made this program in C for you:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <conio.h>
typedef unsigned long int ulong;
ulong fibonacci( ulong );
int main( void ){
int iNumber, iExit = 0;
char iChoice;
do{
system("cls");
printf( "Fibonacci serie:\n\nEnter number: " );
scanf( "%d", &iNumber );
printf("\nFIB(%d) = \n", iNumber);
for( int i=1; i<=iNumber; i++ ){
// These square brackets highlight
// the last number in the sequence.
if(i==iNumber){ printf("["); }
printf( "%#5d", fibonacci(i) );
if(i==iNumber){ printf("]"); }
if(i<iNumber){ printf(" "); } // Number separator
// Go to next line every 10 numbers
if(i % 10 0 !strchr( "yYnN", (char)iChoice ) );
if( strchr( "nN", (char)iChoice ) ){
iExit = 1;
}
} while ( !iExit );
system( "cls" );
system( "pause" );
return 0;
}
/*
Sequence:
1 1 2 3 5 8 13 21 34 55 89 ...
Definition:
FIB(0) = 0;
FIB(1) = 1;
FIB(2) =
FIB(1) + FIB(0) =
1 + 0 = 1
FIB(3) =
FIB(2) + FIB(1) =
FIB(1) + FIB(0) + FIB(1) =
1 + 0 + 1 = 2
FIB(4) =
FIB(3) + FIB(2) =
FIB(2) + FIB(1) + FIB(2) =
FIB(1) + FIB(0) + FIB(1) + FIB(1) + FIB(0) =
1 + 0 + 1 + 1 + 0 = 3
FIB(5) =
FIB(4) + FIB(3) =
FIB(3) + FIB(2) + FIB(3) =
...
... = 5
And so on...
*/
ulong fibonacci(ulong n){
if( n==0 n==1 ){
return n;
} else {
return fibonacci(n-1) + fibonacci(n-2);
}
}
I added a Pastebin link as a related link, there you'll see the code highlighted and indented.
Readnum macro num
mov ah,01h
int 21h
sub al,'0'
mov bh,0ah
mul bh
mov num,al
mov ah,01h
int 21h
sub al,'0'
add num,al
endm
print macro msg
mov ah,09h
mov dx,offset msg
int 21h
endm
data segment
msg db 'program for generating fibonacci series ..$'
msg1 db 0dh,0ah,'enter the limit of the series..$'
msg2 db 0dh,0ah,'the series is..$'
fib dw 100 dup(0)
num db ?
Newline db 0dh,0ah,'$'
result db 20 dup('$')
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
print msg1
readnum num
mov si,offset fib
mov bx,00
mov word ptr[si],bx
add si,02
inc bx
mov word ptr[si],bx
mov ch,00
mov cl,num
nextfib:
sub si,02
mov ax,word ptr[si]
add si,02
mov dx,word ptr[si]
add ax,dx
add si,02
mov word ptr[si],ax
inc bx
cmp bx,cx
jl nextfib
print msg2
mov bx,00
mov si,offset result
nextprn:
mov ax,word ptr fib[bx]
call hex2asc
print newline
print result
add bx,02
loop nextprn
mov ah,4ch
mov al,00h
int 21h
hex2asc proc near
push ax
push bx
push cx
push dx
push si
mov cx,00h
mov bx,0ah
rpt1:
mov dx,00
div bx
add dl,'0'
push dx
inc cx
cmp ax,0ah
jge rpt1
add al,'0'
mov [si],al
rpt2:
pop ax
inc si
mov [si],al
loop rpt2
inc si
mov al,'$'
mov [si],al
pop si
pop dx
pop cx
pop bx
pop ax
ret
hex2asc endp
code ends
end start
Writing a C program that uses dynamic memory allocation to sort names in ascending order is a typical computer science assignment. To write this program, you must be in UNIX.
To write a C++ program to display the student details using class and array of object.
No. They can be sorted either ways. Ascending or Descending.
In Maths, we often talk about ascending and descending order. Ascending order is writing numbers from smallest to largest. Descending order is writing numbers from largest to smallest.
Any data that is keyed to a numeric or text field may be sorted in ascending or descending order. Data that is keyed to a date may be sorted in chronological order (ascending with oldest first) or reverse-chronological order (descending order with newest first). Data that is keyed to a price may be sorted with most-expensive first (descending order) or least-expensive first (ascending order). Data that is keyed to a weight may be sorted in ascending or descending order of weight. And so on.
One many find this answer on YouTube. One also may find out how to write ascending order programs using an 8086 microprocessor by looking at the owners manual.
Writing a C program that uses dynamic memory allocation to sort names in ascending order is a typical computer science assignment. To write this program, you must be in UNIX.
To write a C++ program to display the student details using class and array of object.
I know how to do this and you need to know how to do this. Why don't you do your best at writing this program and if it does not work then ask for help. You will not learn anything if I give you the answer.
sorry
before and after use an conpair the results
das
0.01, 0.09, 0.1, 0.9
Data can be stored in ascending order, descending order or no particular order.
The multiples of 18 in ascending order are 12345678
Data can be stored in ascending order, descending order or no particular order.
No, it can be sorted either in ascending or descending order.