Showing posts with label TASM. Show all posts
Showing posts with label TASM. Show all posts

Saturday, September 10, 2011

TASM Program Source Code to Find Factorial of a Number

The TASM Assembly Program given below can be used to find the factorial of a number.The Complete Source Code is given below.Check it out and do respond to the post if you have any doubts.
 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  
 printstring macro msg  
     mov ah,09h  
     mov dx,offset msg  
     int 21h  
     endm  
 data segment  
     cr equ 0dh  
     lf equ 0ah  
     msg1 db 'enter the number',cr,lf,'$'  
     msg2 db 'the factorial is','$'  
     num db ?  
     result db 20 dup('$')  
     data ends  
 code segment  
     assume cs:code,ds:data  
 start:  
        mov ax,data  
        mov ds,ax  
        printstring msg1  
        readnum num  
        mov ax,01h  
        mov ch,00h  
        mov cl,num  
        cmp cx,00  
        je skip  
 rpt1:  
       mov dx,00  
       mul cx  
       loop rpt1  
 skip:  
       mov si,offset result  
       mov bl,[si]  
       call hex2asc  
       printstring msg2  
       printstring result  
       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  
 rpt2:  
       mov dx,00  
       div bx  
       add dl,'0'  
       push dx  
       inc cx  
       cmp ax,0ah  
       jge rpt2  
       add al,'0'  
       mov [si],al  
 rpt3:pop ax  
       inc si  
       mov [si],al  
       loop rpt3  
       inc si  
       mov al,'$'  
       mov [si],al  
       pop si  
       pop dx  
       pop cx  
       pop bx  
       pop ax  
       ret  
       hex2asc endp  
       code ends  
 end start  

Monday, September 5, 2011

TASM Assembly Program to Find the Largest of N Numbers

The TASM Assembly program given can be used to find the largest number among the numbers entered to an array.The Complete Source Code is given Below.
 print macro msg  
  mov ah,09h  
  mov dx,offset msg  
  int 21h  
 endm  
 read 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  
 data segment  
  cr equ 0dh  
  lf equ 0ah  
  msg1 db 'Enter the limit ',cr,lf,'$'  
  msg2 db cr,lf,'Enter the no:',cr,lf,'$'  
  msg3 db cr,lf,'$'  
  msg4 db cr,lf,'largest no is',cr,lf,'$'  
  num db ?  
  n db ?  
  arr db 100 dup(0)  
  larg db 8 dup('$')  
 data ends  
 code segment  
 assume cs:code,ds:data  
  start:mov ax,data  
     mov ds,ax  
     print msg1  
     read n  
     mov ch,00h  
     mov cl,n  
     mov si,00h  
     print msg2  
  rept1:read num  
     mov bl,num  
     mov arr[si],bl  
     inc si  
     print msg3  
     loop rept1  
     mov si,00h  
     mov ch,00h  
     mov cl,n-1  
     mov al,arr[si]  
  rept2:inc si  
     mov bl,arr[si]  
     cmp bl,al  
     jb exit  
     mov al,bl  
  exit:loop rept2  
     mov ah,00h  
     mov si,offset larg  
     call hextoasc  
     print msg4  
     print larg  
     mov ah,4ch  
     mov al,00h  
     int 21h  
 hextoasc proc near  
  push ax  
  push bx  
  push cx  
  push dx  
  push si  
  mov cx,00h  
  mov bx,0ah  
 rept3:mov dx,00  
    div bx  
    add dl,'0'  
    push dx  
    inc cx  
    cmp ax,0ah  
    jge rept3  
    add al,'0'  
    mov [si],al  
 rept4:pop ax  
    inc si  
    mov [si],al  
    loop rept4  
    inc si  
    mov al,'$'  
    mov [si],al  
    pop si  
    pop dx  
    pop cx  
    pop bx  
    pop ax  
    ret  
  hextoasc endp  
  code ends  
 end start  

Friday, August 5, 2011

TASM Program Source Code to Check Whether a Number is Prime


The Program given below can be used to check whether a 2 digit number is prime or not.

  print macro msg  
  mov ah,09h  
  mov dx,offset msg  
  int 21h  
 endm  
 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  
 data segment  
  cr equ 0dh  
  lf equ 0ah  
  msg1 db 'Enter the no:','$'  
  num1 db ?  
  msg2 db cr,lf,'prime no','$'  
  msg3 db cr,lf,'not a prime no','$'  
 data ends  
 code segment  
  assume cs:code,ds:data  
  start:mov ax,data  
     mov ds,ax  
     print msg1  
     readnum num1  
     mov al,num1  
     cmp al,02h  
     je go3  
     mov ah,00h  
     mov bl,02h  
     mov bh,00h  
     mov cl,al  
   go2:  
     mov ah,00h  
     div bl  
     cmp ah,00h  
     je go  
     inc bx  
     mov al,num1  
     cmp bl,cl  
     jne go2  
  go3: print msg2  
     jmp exit  
  go:print msg3  
  exit:mov ah,4ch  
     mov al,00h  
     int 21h  
  code ends  
  end start  

TASM Program to find the Sum of N numbers

 
The Program given below receives N numbers from console,computes the sum of those numbers and prints the result.
 print macro msg  
   mov ah,09h  
   mov dx,offset msg  
   int 21h  
 endm  
 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  
 data segment  
   cr equ 0dh  
   lf equ 0ah  
   msg1 db 'Enter the limit:','$'  
   msg3 db cr,lf,'Enter the no:','$'  
   msg2 db cr,lf,'sum=','$'  
   lmt db ?  
   temp db ?  
   arr db 15 dup(0)  
   rslt db 2 dup(0)  
 data ends  
 code segment  
   assume cs:code,ds:data  
  start:mov ax,data  
      mov ds,ax  
      print msg1  
      readnum lmt  
      mov ch,00h  
      mov cl,lmt  
      mov si,00h  
   l1:print msg3  
      readnum temp  
      mov al,temp  
      mov arr[si],al  
      inc si  
      loop l1  
      mov ch,00h  
      mov cl,lmt  
      mov bx,00h  
      mov si,00h  
      mov ax,0000h  
   l2: mov bh,00h  
      mov bl,arr[si]  
      add ax,bx  
      mov rslt,al  
      inc si  
      loop l2  
      mov si,offset rslt   
      call hexa2asc  
      print msg2  
      print rslt  
      mov ah,4ch  
      mov al,00h  
      int 21h  
  hexa2asc proc near  
     push ax  
     push bx  
     push cx  
     push dx  
     push si  
     mov cx,00h  
     mov bx,0ah  
 rpt1:  mov dx,00h  
     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  
  hexa2asc endp  
  code ends  
 end start  

TASM:Turbo Assembler Tutorial


Assembler is a System Software which translates the Source Program,which is a set of assembly language statements into Machine Code.Turbo Assembler,commonly known as TASM is a widely used assembler.The assembly Program in  given to the Assembler as Input.The Assembler processes the input and converts the code to Object Code(Machine Code) and Produces an Assembly Listing of the generated Code.

For More Understanding of the Assembler Check out these sample Assembly Programs


http://c-madeeasy.blogspot.com/2011/09/tasm-program-source-code-to-find.html
http://c-madeeasy.blogspot.com/2011/09/tasm-assembly-program-to-find-largest.html
http://c-madeeasy.blogspot.com/2011/08/tasm-program-to-find-sum-of-n-numbers.html

Which is the Best Photo Watermarking Software

Photo Theft is becoming more and more common in the web with the outburst of social websites like Facebook,Google Plus and Image sharing se...