Skip to content
Why GitHub? 
Team
Enterprise
Explore 
Marketplace
Pricing 
Search

Sign in
Sign up
narzullaev
/
Assembly
12
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Assembly/STIK1014 - Computer System Organization/src/Fibonacci Sequence.asm
@narzullaev
narzullaev source code placed inside src folderr
Latest commit 3f55f57 on Feb 22, 2018
 History
 1 contributor
199 lines (164 sloc)  2.87 KB
  
;******************************************
;*Aim of this code to generate a Fibonacci* 
;*Sequence up to n numbers.               *
;*Author : Sardor Narzullaev              * 
;*IDE    : emu8086                        *
;******************************************
name "fibonacci Series"
.model small

.data

    tittle db 0ah,"Fibonacci Series", 0ah,0dh,"$"
    line   db     " -------- ---------", 0ah,0ah,0dh,"$"
    message1 db "Plese enter the targetted number: ", "$"
    message2 db 0ah,0ah,0dh,"Enter any key to continue: ", "$"
    can db 5 dup (?)
    term dw 0 
    term1 dw 0
    term2 dw 1
    term3 dw 0 
    fact dw 1
    sum dw 0
    fil db 06
    col db 18h
    mit db 0
    num db 9 
    .code
otra: 
 mov fil,06 ;row position 06
 mov col,18h ;18h column positions
 mov mit,0;;
 mov ax,0;load to all zero 
 mov bx,0
 mov dx,0
 mov fact,1
 mov sum,0 
 mov term,0 
 mov term1,0;
 mov term2,1
 mov term3,0 
 call clean;
 mov ax,@data
 mov ds,ax
 mov dx,offset tittle
 mov ah,09 ;title
 int 21h

 mov dx,offset message1
 int 21h
;now the amount of inheritance is entered
 mov dx,offset can
 mov si,dx
 mov byte ptr[si],5
 mov ah,0ah
 int 21h   
 mov ah,02;jump line
 mov dl,0ah
 int 21h
 int 21h
 mov dl,0dh;return
 int 21h            
 mov ch,0h;
 mov cl,byte ptr[si+1]; 
 add si,cx;
 mov bx,0ah; 

loop1:
mov al,byte ptr[si+1];
and ax,0fh 
mul fact
add sum,ax
mov ax,fact
mul bx
mov fact,ax
dec si

loop loop1

    ; sum is the number of elements in hexadecimal 

 mov ax,sum;we have the sum in hexadecimal
 mov bl,2;divided by 2
 div bl
 mov mit,al;We spent the quotient 
 add mit,1;adding 1
 call locate;positioned

 mov ax,term1 
 mov bx,term2
 mov dx,term3 

while: 

mov cx,sum;we again sum 
add ax,bx;
mov term,ax;
mov bx,dx
mov dx,ax; 

mov term1,ax
mov term2,bx
mov term3,dx

cmp mit,cl;comparison
jz movement;if so moves next

salto:

call decimal;printed in decimal

inc fil
call locate

mov ax,term1
mov bx,term2
mov dx,term3

cmp sum,01
jz sigue   
dec sum
jmp while

movement:  

add col,18h
mov fil,05
jmp salto   

sigue:

mov dx,offset message2
mov ah,09
int 21h
mov ah,01
int 21h

cmp al,"n"
jz finish
jmp otra

finish:
mov ah,4ch
int 21h 

locate proc near

mov ah,02
mov bh,00
mov dh,fil
mov dl,col
int 10h

ret

locate endp 

decimal proc near

lea si,num+5
mov cx,0ah
mov bx,5        

vuelta:
cmp ax,cx;if less
jb menor
xor dx,dx
div cx;
add dl,30h;sum of 30
mov byte ptr[si],dl;placed in last number
dec si;decrement
dec bx
      ;decrease when not less than number given 
jmp vuelta 
    menor:
add al,30h
mov byte ptr[si],al
mov byte ptr[si+6],"$";placed at the end
mov ah,09
lea dx,num+bx;adding bx
int 21h

ret

decimal endp

clean proc near

mov ah,06h   ; moves to begining 
mov al,0     ; from the screen
mov cx,0     ; row ch=0, column cl=0
mov dx,184fh ; 
mov bh,07h   ; 
int 10h         
mov ah,02    ; place the cursor in
mov dx,0     ; begining
mov bh,0     ; new window 
int 10h 
ret

© 2021 GitHub, Inc.
Terms
Privacy
Security
Status
Docs
Contact GitHub
Pricing
API
Training
Blog
About
Loading complete 

Assembly Online Compiler

Write, Run & Share Assembly code online using OneCompiler's Assembly online compiler for free. It's one of the robust, feature-rich online compilers for Assembly language. Getting started with the OneCompiler's Assembly compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as Assembly and start coding.

About Assembly

Assembly language(asm) is a low-level programming language, where the language instructions will be more similar to machine code instructions.

Every assembler may have it's own assembly language designed for a specific computers or an operating system.

Assembly language requires less execution time and memory. It is more helful for direct hardware manipulation, real-time critical applications. It is used in device drivers, low-level embedded systems etc.

Syntax help

Assembly language usually consists of three sections,

  1. Data section

    To initialize variables and constants, buffer size these values doesn't change at runtime.

  2. bss section

    To declare variables

  3. text section

    _start specifies the starting of this section where the actually code is written.

Variables

There are various define directives to allocate space for variables for both initialized and uninitialized data.

1. To allocate storage space to Initialized data

Syntax

variable-name    define-directive    initial-value 
Define DirectiveDescriptionAllocated Space
DBDefine Byte1 byte
DWDefine Word2 bytes
DDDefine Doubleword4 bytes
DQDefine Quadword8 bytes
DTDefine Ten Bytes10 bytes

2. To allocate storage space to un-initialized data

Define DirectiveDescription
RESBReserve a Byte
RESWReserve a Word
RESDReserve a Doubleword
RESQReserve a Quadword
RESTReserve a Ten Bytes

Constants

Constants can be defined using

1. equ

  • To define numeric constants
CONSTANT_NAME EQU regular-exp or value

2. %assign

  • To define numeric constants.
%assign constant_name value

3. %define

  • To define numeric or string constants.
%define constant_name value

Loops

Loops are used to iterate a set of statements for a specific number of times.

mov ECX,n
L1:
;<loop body>
loop L1

where n specifies the no of times loops should iterate.

Procedures

Procedure is a sub-routine which contains set of statements. Usually procedures are written when multiple calls are required to same set of statements which increases re-usuability and modularity.

procedure_name:
   ;procedure body
   ret