Skip to content

Instantly share code, notes, and snippets.

@hasinur1997
Last active December 9, 2018 18:35
Show Gist options
  • Save hasinur1997/7ed698bf39cf5ada63fc19d26a6b274e to your computer and use it in GitHub Desktop.
Save hasinur1997/7ed698bf39cf5ada63fc19d26a6b274e to your computer and use it in GitHub Desktop.

Assembly program for fibonacci series

proc getFibo
        mov al,f1
        mov bl,f2

    ;mov cl,count
    ;cmp cl,num
    ;je exitFibo

    mov dl,al
    add dl,48
    mov ah,02h
    int 21h

    mov cl,count
    add cl,1
    mov count,cl

    mov dl,bl
    add dl,48
    mov ah,02h
    int 21h

    mov cl,count
    add cl,1
    mov count,cl

    calcFibo:
        mov al,f1
        add al,f2
        mov f1,al

        mov dl,f1
        add dl,48
        mov ah,02h
        int 21h

        mov cl,count
        add cl,1
        mov count,cl

        mov cl,count
        cmp cl,num
        je exitFibo

        mov bl,f2
        add bl,f1
        mov f2,bl

        mov dl,f2
        add dl,48
        mov ah,02h
        int 21h

        mov cl,count
        add cl,1
        mov count,cl

        mov cl,count
        cmp cl,num
        je exitFibo

        jmp calcFibo

    exitFibo:
    ret
endp

Assembly program for Swapping to numbers

DATA SEGMENT
NUM1 DB 9H
NUM2 DB 7H
ENDS

CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX

MOV AL,NUM1
MOV BL,NUM2

XCHG AL,NUM2
XCHG BL,NUM1

MOV AH,4CH
INT 21H
ENDS
END START

Assembly program for print "Hello World"

.model small                            ;defines the memory model to be used for the ALP
.data                                   ;data segment begins here
        msg db 10d,13d,"Hello World$"   ;String Hello World gets stored in msg

.code                                   ;code segment begins here
        mov ax,@data                    ;moving base address of data to ax
        mov ds,ax                       ;moving contents of ax into ds
                                        ;data section now gets initialized
        lea dx,msg                      ;load the offset address of msg
        mov ah,09h                      ;to display contents at dx
        int 21h                         ;call the kernel

        mov ah,4ch                      ;to terminate the program
        int 21h                         ;call the kernel
end                                     ;end of program

Assembly program for taking an input and show the output

.model small

            .stack 100h

            .data

buff        db  26        ;MAX NUMBER OF CHARACTERS ALLOWED (25).
            db  ?         ;NUMBER OF CHARACTERS ENTERED BY USER.
            db  26 dup(0) ;CHARACTERS ENTERED BY USER.

            .code
main:
            mov ax, @data
            mov ds, ax              

;CAPTURE STRING FROM KEYBOARD.                                    
            mov ah, 0Ah ;SERVICE TO CAPTURE STRING FROM KEYBOARD.
            mov dx, offset buff
            int 21h                 

;CHANGE CHR(13) BY '$'.
            mov si, offset buff + 1 ;NUMBER OF CHARACTERS ENTERED.
            mov cl, [ si ] ;MOVE LENGTH TO CL.
            mov ch, 0      ;CLEAR CH TO USE CX. 
            inc cx ;TO REACH CHR(13).
            add si, cx ;NOW SI POINTS TO CHR(13).
            mov al, '$'
            mov [ si ], al ;REPLACE CHR(13) BY '$'.            

;DISPLAY STRING.                   
            mov ah, 9 ;SERVICE TO DISPLAY STRING.
            mov dx, offset buff + 2 ;MUST END WITH '$'.
            int 21h

            mov ah, 4ch
            int 21h

            end main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment