• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
projectsgeek

ProjectsGeek

Download Mini projects with Source Code, Java projects with Source Codes

  • Home
  • Java Projects
  • C++ Projects
  • VB Projects
  • PHP projects
  • .Net Projects
  • NodeJs Projects
  • Android Projects
    • Project Ideas
      • Final Year Project Ideas
      • JSP Projects
  • Assignment Codes
    • Fundamentals of Programming Language
    • Software Design Laboratory
    • Data Structure and Files Lab
    • Computer Graphics Lab
    • Object Oriented Programming Lab
    • Assembly Codes
  • School Projects
  • Forum

Assembly Codes

GCD of Two Numbers program in Assembly Language

April 26, 2011 by ProjectsGeek Leave a Comment

GCD of Two Numbers program in Assembly Language

Write  a Program to find the GCD of Two Numbers  in Assembly Language . Program should load two registers with two Numbers  and then apply the logic for GCD of two Numbers . GCD of two numbers is performed by dividing the greater number by the smaller number till the remainder is zero. If it is zero, the divisor is the GCD if not the remainder and the divisor of the previous division are the new set of two numbers. The process is repeated by dividing greater of the two numbers by the smaller number till the remainder is zero and GCD is found.

 

Algorithm for  GCD of Two Numbers

 

Step I            :     Initialize the data segment.
Step II          :     Load AX and BX registers with the operands.
Step III        :     Check if the two numbers are equal. If yes goto step X, else goto step IV.
Step IV         :     Is number 1 > number 2 ? If yes goto step VI else goto step V.
Step V          :     Exchange the contents of AX and BX register, such that AX contains the bigger number.
Step VI         :     Initialize DX register with 00H.
Step VII       :     Perform the division operation (contents of AX / contents of BX).
Step VIII     :     Check if there is remainder. If yes goto step IX, else goto step X.
Step IX        :     Move the remainder into AX register and goto step IV.
Step X          :     Save the contents of BX as GCD.
Step XI        :     Display the result.
Step XII       :     Stop.

GCD of Two Numbers  Algorithm Snapshot

GCD of Two Numbers

Program code for GCD of Two Numbers 

 

.model small  
 .stack 100  
 .data  
 no1  dw 0120  
 no2  dw 0090  
 gcd dw 0h  
 .code  
      mov      ax,@data          ; initialize DS  
      mov      ds, ax       
      mov      ax, no1           ; get the first number  
      mov      bx, no2           ; get the second number  
 again:      cmp      ax, bx     ; check if nos are equal  
          je      endd           ; if equal, save the GCD  
      jb      exchg              ; if no,   
                                 ; is AX                                 ; if yes interchange   
 l2:     mov      dx, 0  
      div      bx                ; check if ax is   
                                 ; divisible by bx  
      cmp      dx, 0     ;  
      je      endd  
      mov      ax, dx            ; mov the remainder   
                                 ; as no1 data  
      jmp      again  
 exchg :      xchg      ax, bx jmp l2  
 endd :      mov      gcd, bx  
      mov      ch, 04h           ; Count of digits to be   
                ; displayed  
      mov      cl, 04h           ; Count to roll by 4 bits  
 l12:     rol      bx, cl        ; roll bl so that msb   
                ; comes to lsb   
         mov      dl, bl         ; load dl with data   
                ; to be displayed  
         and      dl, 0fH        ; get only lsb  
         cmp      dl, 09         ; check if digit is 0-9   
                ; or letter A-F  
         jbe      l4  
         add      dl, 07         ; if letter add 37H else   
                ; only add 30H  
 l4:       add      dl, 30H  
         mov      ah, 02         ; INT 21H   
                ; (Display character)  
         int      21H  
         dec      ch             ; Decrement Count  
         jnz      l12                                
      mov      ah, 4ch  
      int      21h  
 end

How to Run this Program

 

For Running this program you should have installed Tasm on you computer . If you have not installed Tasm  yet please install from Here .

C:\programs>tasm gcd.asm
Turbo Assembler  Version 3.0  Copyright (c) 1988, 1991 Borland International
Assembling file:   gcd.asm
Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  437k
C:\programs>tlink gcd
Turbo Link  Version 3.0 Copyright (c) 1987, 1990 Borland International
C:\programs>gcd
001E

Other Projects to Try:

  1. 2s Complement of a Numbers Assembly Code
  2. Add 8 Bit BCD Numbers
  3. Program to Add Two 16 Bit Numbers Assembly Code
  4. Mask Upper Nibble in Assembly Language Program code
  5. Multiply Two 8 Bit Numbers in Assembly Language

Filed Under: Assembly Codes Tagged With: Assembly Codes

Operation on Strings in Assembly Language

April 26, 2011 by ProjectsGeek Leave a Comment

Operation on Strings in Assembly Language

Write a Program for Operation on Strings in Assembly Language. Using Macro display the Menu for entering string, calculate length, reverse, palindrome and exit. Accept the choice from user using INT 21H function 01H. 
Choice = 1: Call procedure for accepting string. Using interrupt INT 21H, function 0AH accept the string and end procedure. Return back to display Menu.
Choice = 2: Call procedure for finding length of the string. Display length and return  back to display Menu.
Choice = 3: Call procedure to reverse the string. Display the reverse string and return back to display Menu.
Choice = 4: Call procedure to check if entered string is palindrome. If palindrome displays, the string is a palindrome, otherwise display String is not a palindrome.
Choice = 5: Terminate the program. If any other key is pressed display invalid choice. 

Algorithm for Operation on Strings

Step I    :    Initialize the data and stack memory.
Step II    :    Using Macro display Menu.
        1.    Accept
        2.    Length
        3.    Reverse
        4.    Palindrome
        5.    Exit.
Step III    :    Accept choice from user using INT 21H, function 01H.
Step IV    :    IS choice = 1  jump to step XI else goto step V.
Step V    :    IS choice = 2 jump to step XIV else goto step VI.
Step VI    :    IS choice = 3 jump to step XVII else goto step VII.
Step VII    :    IS choice = 4 jump to step XX else goto step VIII.
Step VIII    :    IS choice = 5 jump to step XXIII else goto step IX.
Step IX    :    Display Wrong choice.
Step X    :    Jump to step II.
Step XI    :    Call procedure accept.
Step XII    :    Accept string using INT 21H, function 0AH.
Step XIII    :    Return to main program and goto step II.
Step XIV    :    Call procedure length.
Step XV    :    Calculate the length of string and display it using INT 21H, function 02H.
Step XVI    :    Return back to main program and jump to step II.
Step XVII    :    Call procedure reverse.
Step XVIII    :    Reverse the string and display it.
Step XIX    :    Return back to main program and jump to step II.
Step XX    :    Call procedure palindrome.
Step XXI    :    Check if string is palindrome. If yes display string is palindrome else string is not a palindrome.
Step XXII    :        Return back to main program and jump to step II.
Step XXIII    :    Terminate the program and stop.

Operation on Strings Assembly Language code
 TITLE  STRING OPERATIONS  
 MESS  MACRO MSG     ; DEFINITION OF MACRO MESS         
      MOV      AH, 09H  
      LEA      DX, MSG  
      INT      21H  
      ENDM  
 .MODEL SMALL   
 .STACK 100H  
 .DATA  
      STR1      DB 25 , ? , 25 DUP('$')   
      STR3      DB 25 , ? , 25 DUP('$')   
      MSG1      DB 0AH, 0DH, 'MENU $'  
      MSG21      DB 0AH, 0DH, '1.ACCEPT $'  
      MSG22      DB 0AH, 0DH, '2.LENGTH $'  
      MSG23      DB 0AH, 0DH, '3.REVERSE $'  
      MSG24      DB 0AH, 0DH, '4.PALINDROME $'  
      MSG25      DB 0AH, 0DH, '5.EXIT $'  
      MSG3      DB 0AH, 0DH, 'ENTER YOUR CHOICE : $'  
      MSG4      DB 0AH, 0DH, 'WRONG CHOICE $'  
      MSG5      DB 0AH, 0DH, 'ENTER THE STRING : $'  
      MSG6      DB 0AH, 0DH, 'STRING IS : $'  
      MSG7      DB 0AH, 0DH, 'LENGTH IS : $'  
      MSG8      DB 0AH, 0DH, 'THE STRING IS A PALINDROME  $'  
      MSG9      DB 0AH, 0DH, 'THE STRING IS NOT A PALINDROME  $'  
 .CODE   
 mov     ax,           @data     ; Intialize data and extra segment  
      mov           ds, ax  
      mov           es, ax  
 ak :     mess           msg1     ; display menu  
      mess           msg21  
      mess           msg22  
      mess           msg23  
      mess           msg24  
      mess           msg25  
      mess           msg3     ; accept choice  
      mov           ah, 01h  
      int           21h  
      mov           bl, al     ; Choice BL  
      cmp          bl, 31h     ; if choice=1  
      je           acc          ; Accept string  
      cmp           bl, 32h     ; if choice=2  
      je           len          ; Find lenth   
                                    ; of string  
      cmp           bl, 33h     ; if choice=3  
      je           rev          ; Reverse string  
      cmp           bl, 34h     ; if choice=4  
      je           pal          ; Check if string is   
                                    ; palindrome  
      cmp           bl, 35h     ; if choice=5  
      je           endd     ; exit  
      mess           msg4     ; Wrong Choice  
      jmp           ak  
 acc :     call           accept  
      jmp           ak  
 len :     call           lent  
      jmp           ak  
 rev :     call           reverse  
      jmp           ak  
 pal:     call           pall  
      jmp           ak  
 endd:     mov           ah, 4ch  
      int           21h  
 ;      accept      procedure                                            
      accept proc near  
      mess      msg5  
      mov      ah, 0ah     ; Accept String  
      lea           dx, str1  
      int           21h  
      RET  
 accept endp  
 ; length procedure    
 lent proc near     
      mess           msg7   
      mov           dl, str1+1     ; Dl contains length of String  
      or           dl, 30h  
      mov           ah, 02h          ; Display Length                           
      int           21h  
      ret   
 lent endp  
 ; reverse procedure    
 reverse proc near  
      mess           msg6  
      mov           ch, 00h  
      mov           cl, str1+1     ; Cl has length of string  
      sub           cl, 01h  
      lea           si, str1+2     ; DESTINATION STRING  
      lea           di, str1+2     ; DESTINATION STRING  
      repz           movsb          ; COPY TO TRAVERSE TILL END OF FIRST STR  
      mov           cl, str1+1         
      lea           di, str3+2     ; DESTINATION STRING  
 loop1:      mov           dx, [si]          ; dx contains rightmost character  
      mov           ah, 02h  
      int           21h          ; display character  
      mov           [di], dx          ; copy character to destination  
      dec           si  
      inc           di  
      dec           cl  
      cmp           cl, 00h  
      jne           loop1  
      ret  
 reverse endp  
 ; palindrome procedure    
 pall      proc           near  
      mess           msg6  
      mov           ah, 09h  
      lea           dx, str1+2     ; str1 contains original string  
      int           21h  
      call           reverse               ; str3 has reversed string   
      lea           di, str3+2  
      mov           ah, 00h  
      mov           dh, 00h  
      lea           si , str1+2  
      mov           cl, str1+1          ; CL contains Length of string  
 loop 2 :     mov           al, byte ptr[si]  
      mov           bl, byte ptr[di]  
      dec           cl                    ; Decrement count  
      cmp           cl, 00h  
      je           loopa  
      cmp           al, bl               ; Compare characters  
      je           loop3               ; if same goto loop3  
 loopa : cmp           cl, 00h               ; if checked all characters  
      je           loop4  
      mess           msg9               ; the strings are not same  
      jmp           loop5  
 loop4 : mess           msg8               ; the strings are same  
 loop5: ret  
 loop3 : inc           si  
      inc           di  
      jmp           loop2               ; now check next character  
      pall           endp  
 end

How to Run this Program 

For Running this program you should have installed Tasm on you computer . If you have not installed Tasm  yet please install from Here .

C:\programs>tasm str
Turbo Assembler  Version 3.0  Copyright (c) 1988, 1991 Borland International
Assembling file:   str.ASM
Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  434k
C:\programs>tlink str
Turbo Link  Version 3.0 Copyright (c) 1987, 1990 Borland International
C:\programs>str
MENU
1. ACCEPT
2. LENGTH
3. REVERSE
4. PALINDROME
5. EXIT
ENTER YOUR CHOICE :  1
ENTER THE STRING :  college
MENU
1. ACCEPT
2. LENGTH
3. REVERSE
4. PALINDROME
5. EXIT
ENTER YOUR CHOICE :  2
LENGTH IS :  7
MENU
1. ACCEPT
2. LENGTH
3. REVERSE
4. PALINDROME
5. EXIT
ENTER YOUR CHOICE :  3
STRING IS :  egelloc
MENU
1. ACCEPT
2. LENGTH
3. REVERSE
4. PALINDROME
5. EXIT
ENTER YOUR CHOICE :  4
STRING IS :  college
STRING IS :  egelloc
THE STRING IS NOT A PALINDROME
MENU
1. ACCEPT
2. LENGTH
3. REVERSE
4. PALINDROME
5. EXIT
ENTER YOUR CHOICE : 1
ENTER THE STRING :  madam
MENU
1. ACCEPT
2. LENGTH
3. REVERSE
4. PALINDROME
5. EXIT
ENTER YOUR CHOICE :  4
STRING IS :  madam
STRING IS :  madam
THE STRING IS A PALINDROME

Other Projects to Try:

  1. String Operations with Pointers
  2. To Perform various String Operation in Java
  3. string operations such as Copy, Length, Reversing, Palindrome, Concatenation
  4. BCD to decimal Conversion in Assembly Language
  5. Multiply Two 8 Bit Numbers in Assembly Language

Filed Under: Assembly Codes Tagged With: Assembly Codes

Mask Lower Nibble in Assembly Language Code

April 13, 2011 by ProjectsGeek Leave a Comment

Mask Lower Nibble in Assembly Language Code

Write a program to mask lower nibble for that number should be loaded into the register and operation should be implemented on that loaded number . Calculated result should be displayed in the output .
 

Algorithm for Masking Lower Nibble

 
Step I            :   Load the number in AL.
Step II           :   Mask tower  nibble i.e. AND AL, 0F0 H.
Step III          :   Display result.
Step IV          :   Stop.  

Mask Lower Nibble Algorithm Snapshot

Mask Lower Nibble in Assembly Language

Masking Lower Nibble Code

.model small                                                                 
 .data  
 a dw 0012H  
 .code  
      mov      ax, @data          ; Initialize data section  
      mov      ds, ax  
      mov      ax, a              ; Load number1 in ax  
      and      al, 0f0h           ; mask lower nibble.Result in al  
      mov      ch, 02h            ; Count of digits to be displayed  
      mov      cl, 04h            ; Count to roll by 4 bits  
      mov      bh, al             ; Result in reg bh  
 l2:     rol      bh, cl          ; roll bl so that msb comes to lsb   
      mov      dl, bh             ; load dl with data to be displayed  
      and      dl, 0fH            ; get only lsb  
      cmp      dl, 09             ; check if digit is 0-9 or letter A-F  
      jbe      l4  
      add      dl, 07             ; if letter add 37H else only add 30H  
 l4:      add      dl, 30H       
      mov     ah, 02              ; Function 2 under INT 21H (Display character)  
      int      21H  
      dec      ch                 ; Decrement Count  
      jnz      l2     
      mov      ah, 4ch  
      int      21h  
      end

How to Run this Program

For Running this program you should have installed Tasm on you computer . If you have not installed Tasm  yet please install from Here .

C:\programs>tasm lownib.asm
Turbo Assembler  Version 3.0  Copyright (c) 1988,  1991 Borland International
Assembling file:   lownib.asm
Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  438k
C:\programs>tlink lownib.obj
Turbo Link  Version 3.0 Copyright (c) 1987, 1990 Borland International
Warning: No stack
C:\programs>lownib
10

Other Projects to Try:

  1. 2s Complement of a Numbers Assembly Code
  2. Unpack the Packed BCD Number code
  3. Add 8 Bit BCD Numbers
  4. Mask Upper Nibble in Assembly Language Program code
  5. Hex to BCD Conversion in Assembly Language Code

Filed Under: Assembly Codes Tagged With: Assembly Codes

  • « Go to Previous Page
  • Page 1
  • Interim pages omitted …
  • Page 4
  • Page 5
  • Page 6

Primary Sidebar

Tags

.Net Projects Download Android Project Ideas Android Projects Angular 2 Assembly Codes C # Projects C & C++ Projects C++ Projects Class Diagrams Computer Graphics Database Project Data Mining Projects DataScience Projects Datastructure Assignments Download Visual Basic Projects Electronics project Hadoop Projects Installation Guides Internet of Things Project IOS Projects Java Java Interview Questions Java Projects JavaScript JavaScript Projects java tutorial JSON JSP Projects Mechanical Projects Mongodb Networking Projects Node JS Projects OS Problems php Projects Placement Papers Project Ideas Python Projects seminar and presentation Struts

Search this Website


Footer

Download Java Project
Download Visual Basic Projects
Download .Net Projects
Download VB Projects
Download C++ Projects
Download NodeJs Projects
Download School Projects
Download School Projects
Ask Questions - Forum
Latest Projects Ideas
Assembly Codes
Datastructure Assignments
Computer Graphics Lab
Operating system Lab
australia-and-India-flag
  • Home
  • About me
  • Contact Form
  • Submit Your Work
  • Site Map
  • Privacy Policy