Feedjit

Articles for you

Showing posts with label Assembly Language. Show all posts
Showing posts with label Assembly Language. Show all posts

Tuesday, September 22, 2015

Display Analog Clock of System Time in Assembly Language Sir Asim Munir





Please find source code on below url:
Download the source:  asm-clock-source-code.asm






Saturday, June 1, 2013

Generate a beautiful Sound from the System Internal Speaker in Assembly language

.model small
.stack
.data
array dw 262,400,262,400,294,800,262,800,349,800,330,1000
;tne db 20
.code
main:
mov ax,@data
mov ds,ax
in al,61h                ;Read Port B
jmp $+2                    ;Wait
or al,3                    ;Set timer bits on 1 and 2
out 61h,al                ;Send to Port B
mov al,0B6h                ;Configuration word for sound
out 43h,al                ;Sned to Command register
;mov cl,5
;repead:
;call happy_bday
;dec cl
;cmp cl,0
;jne repead
;jmp finish


happy_bday:
mov dx,12                ;Number of Frequencies
mov si, offset array    ;SI points to array
next:
mov bx,[si]                ;Get first value from array
call play                ;Call play function
dec dx                   ; Decrement repeat routine count
cmp dx, 0                 ; Is DX (repeat count) = to 0
jnz  next               ; If not zero jump to NEXT
jmp stop                ;Jump to stop

play:
mov ax,0                ;Clear ax values
mov ax,bx                ;Copy frequency from bx to ax
out 42h,al                ;Send lower byte
mov al,ah                ;Copy higher byte from ah to al
out 42h,al                ;Send higher byte
inc si                    ;Increment to point to next value
inc si

Delay_time_to_play:
mov cx,1000                 ; Repeat loop 1000 times
Outer_Loop:           
mov bx,cx                ;Save cx to bx
mov cx,1000            ;Inner loop to be repeated 10000 times
Inner_Loop:
jmp $+2                  ;Wait
loop Inner_Loop            ;Loops to inner loop
jmp $+2                    ;Wait
mov cx,bx                ;Restore outer cx value
LOOP Outer_Loop            ; Jump repeatedly to Outer loop until cx=0
ret                        ;return

stop:
mov bl,0FCh                ;Set 1 and 2 bit of timer to zero again
in al,61h                ;Read port B
jmp $+2                    ;Wait
and al,bl                ;Change 1 and 2 bit ingnoring the rest
out 61h,al                ;Send to port B

finish:                   
mov ah,4ch                ;Service # to end program
int 21h                    ;Call OS to do the job
end main   

Display Clock of System Time in Assembly Language Sir Asim Munir

.model small
.stack 100h
.data
    hr dw ?
    min dw ?
    sec dw ?
    am_time db " AM$";
    pm_time db " PM$";
    time_is db "Your System Current time is  $" ;
   
.code
main:
   
    mov ax,@data
    mov ds,ax
    mov es,ax                ; Put it in ES  For valid string to be displayed
    call PrintColorString
    mov ah,2ch                ;2ch returns time hours in ch,minutes in cl,sec in dh
    int 21h
store_hours:
    mov ax,0
    mov al,ch
    mov hr,ax
store_minutes:
    mov ax,0
    mov al,cl
    mov min,ax
store_seconds:
    mov ax,0
    mov al,dh
    mov sec,ax
Calculate_hrs:
    mov ax,0
    mov cx,0
    mov ax,hr
    cmp ax,11
    jg pm_1digit
rest_time:
    cmp al,0
    jg am_2digit
    mov dl,al
    add dl,12
    mov dh,0
    mov ax,dx
    call two_digits_handle
    mov dl,':'
    mov ah,2h
    int 21h
    jmp calc_mins
am_2digit:
    call two_digits_handle
    mov dl,':'
    mov ah,2h
    int 21h
calc_mins:
    mov ax,min
    call two_digits_handle
    mov dl,':'
    mov ah,2h
    int 21h
calc_secs:
    mov ax,sec   
    call two_digits_handle
    cmp hr,12
    jnl  pmdisp
    lea dx,am_time
    mov ah,9h
    int 21h
    jmp end_lbl
pmdisp:
    lea dx,pm_time
    mov ah,9h
    int 21h
    jmp end_lbl
pm_1digit:
    sub ax,12  
    cmp ax,0
    jg  pm_2digit
    mov dl,al
    add dl,12
    mov dh,0
    mov ax,dx
    call two_digits_handle
    mov dl,':'
    mov ah,2h
    int 21h
    jmp calc_mins
pm_2digit:
    call two_digits_handle
    mov dl,':'
    mov ah,2h
    int 21h
    jmp calc_mins
;;;;;;;;;;;;;;;;;;;;;;;;;   
two_digits_handle proc
     mov  dl,10
    div dl
    mov bl,ah
    mov dl,al
    add dl,30h
    mov ah,2h
    int 21h
    mov dl,bl
    add dl,30h
    mov ah,2h
    int 21h
    ret
two_digits_handle endp
;;;;;;;;;;;;;;;;;;;;;;;;;
PrintColorString proc            ; Print a String in Color at ROW,COLUMN on Screen
        mov ah,13h                ; setup for function 13H of INT 10h API
        mov al, 1                ; Color Attr in BL
        mov bh, 0                ; Page 0
        mov bl, 00000010        ; Color
        mov cx, 28                ; Length of String
        mov dh, 10                ; Row
        mov dl, 20                ; Column
        mov bp, OFFSET time_is    ;Pointer to text
        INT 10h                    ; Execute INT 10H API
        RET
    PrintColorString ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;
end_lbl:   
mov ah,4ch
int 21h
end main

System Info Display Int 11h

.model small
.stack 100h
.data
         str db "flopy is enable $"   ; A string to display1
        str1 db "floppy is disable $"   ; A string to display2
        str2 db "math co processor is enable $"   ; A string to display2
        str3 db "math co processor is disbale $"   ; A string to display2
        str4 db "dma is enable $"   ; A string to display2
        str5 db "dma is disable $"   ; A string to display1
        str6 db "number of video mode $"   ; A string to display2
        str7 db "number of disk in a system $"   ; A string to display2
        str8 db "capslock is off $"   ; A string to display2
        str9 db "capslock is onn$"   ; A string to display2
       

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

        mov ah,2
        int 16h                    ;keyword services
        mov cl,7                   ;mov value
        shr al,cl                   ;shift right function
        jc  to_jmp_long             ;check capslock if on then jump otherwise continuee
    mov dl,10                  ;newline
    mov ah,2h
    int 21h

 lea dx,str8                ;show output
 mov ah,9h
 int 21h

        int 11h                    ;checking intrrupt
        mov bx,ax                  ;for tempry store
        mov cl,1                   ;mov value
        shr ax,cl                  ;shift right function

        jc floppydiskon            ; check floppy

        mov dl,10                  ;newline
 mov ah,2h
 int 21h

 lea dx,str1                ;show output
 mov ah,9h
 int 21h

      
mathcop:
         mov ax,bx
         mov cl,2
         shr ax,cl
         jc mathcoproceesor_on
       
         mov dl,10                  ;newline
   mov ah,2h
  int 21h


 lea dx,str3                ;show output
 mov ah,9h
 int 21h
       
dma:
       
         mov ax,bx
         mov cl,9
         shr ax,cl
         jc dma_on

         mov dl,10                  ;newline
   mov ah,2h
  int 21h


 lea dx,str5                ;show output
 mov ah,9h
 int 21h
to_jmp_long:
    jmp capslockon
jmp ending

dma_on:
   
         mov dl,10                  ;newline
   mov ah,2h
  int 21h


 lea dx,str4                ;show output
 mov ah,9h
 int 21h
 jmp ending
       


mathcoproceesor_on:

         mov dl,10                  ;newline
   mov ah,2h
  int 21h


 lea dx,str2                ;show output
 mov ah,9h
 int 21h
       
       jmp dma

floppydiskon:

        mov dl,10                  ;newline
 mov ah,2h
 int 21h


 lea dx,str                ;show output
 mov ah,9h
 int 21h
        jmp mathcop


capslockon:
       
        mov dl,10                  ;newline
 mov ah,2h
 int 21h

 lea dx,str9                ;show output
 mov ah,9h
 int 21h




ending:
        mov ah, 4ch             ; Service # to terminate a program normally
        int 21h                 ;
        end main

Simplest Implementaion of Switch Case in Assembly Language .asm file MASM file 32-bit/64bit

;Programmed by SAQIB KHAN
;Purpose: Obtain Choice from user/Implement case
;Dated: 15th-MAY-2012

.model small
.stack 100h
.data
        num1 db 97
        num2 db 2
    msg_add db 10,  "Press 0 for  Addition $"
        msg_sub db 10,  "Press 1 for  Subtraction $"
    msg_adc db 10,  "Press 2 to add with carry $"
    message db 10,  "Enter your choice: $"
msg_wrong db 10,  "Please enter correct choice $"
msg_verify db 10, "First operand sholud be greater than 2nd,Please change input values $"
.code
main: 
        mov ax,@data
        mov ds,ax
                       
    lea dx,msg_add    ;Display add message
    mov ah,9h
    int 21h
   
    lea dx,msg_sub    ;Display subtract message
    mov ah,9h
    int 21h

    lea dx,msg_adc    ;Display add message
    mov ah,9h
    int 21h
   
    lea dx,message  ;Display choice message
    mov ah,9h
    int 21h
;;;;;;;;;;;;;;;;;;;;   
   
    mov ah,1                 ;read key from user
    int 21h
    mov ah,0                 ;empty the ah ,upper part of ax
   
    sub al,30h              ; subtract 30h to get exact value from ascii
   
    shl al,1                ; multiply number by 2 to get to the case
    cmp al,4                ;compare for validity
    jg check                ;jump if al,greater than 4
    mov bx,ax               ;mov value of ax to bx for offset
    jmp cs:jmptble [bx]          ;jumptable

jmptble dw case0,case1,case2 ;cases   
   

check:
    lea dx,msg_wrong        ;Display wrong choice
    mov ah,9h           
    int 21h
    mov dl,10            ;Move to new line
    mov ah,2h
    int 21h
    jmp main            ;Loop again to get correct choice
case0:                    ;Case0- Addition
    mov dl,10            ;move to new line
    mov ah,2h
    int 21h
   
    mov al,num1            ;copy num1 to al
    xor ah,ah            ;empty ah to zero   
    add al,num2             ; add num2 to al
    call display   
    jmp endlabel            ;jum to endlabel
case1:                    ;Case1 for subtraction
    mov dl,10            ;;Move to new line
    mov ah,2h
    int 21h

    mov cl,num1            ;Copy number1 to cl
    cmp cl,num2            ;check if first numbr is smaller than second
    jl  verify            ;jump if num1 is less than num2
   
    mov al,num1            ;copy num1 to al
        xor ah,ah            ;empty the uper portion of ax
        sub al,num2             ;subtract two nmbers
   
    call display   
    jmp endlabel
case2:
    mov dl,10
    mov ah,2h
    int 21h
   
        mov al,num1
        xor ah,ah   
        adc al,num2     ;adc add 1 value to the sum (if carry flag is 1)
   
        call display
        jmp endlabel

verify:   
        lea dx,msg_verify
    mov ah,9
    int 21h
display:
mov dl,10            ;mov dl,10 to divide result in ax
        div dl                ;Dvide ax by 10
        mov dl,al            ;copy quotient to dl
        mov bl,ah            ;copy remainder to bl
        add dl,30h                ;add 30h to get actual number
        mov ah,2h            ;Service # to display character
    int 21h                ;Call OS to do the job
    add bl,30h            ;add 30h to remainder
    mov dl,bl            ;move to dl to display
        mov ah,2h            ;Service # to display character
        int 21h             ;Call OS to do the job
        ret
   

endlabel:
    mov ah,4ch
    int 21h

end main

Display Personal Information in Assembly Language .asm file Coal

; Programmed by: SAQIB KHAN
; Purpose: To display 4 items of my personal information
; Date: 27th/april/2012

.model small
.stack 100h
.data
        str db "Name : Saqib Khan $"   ; A string to display
        chr db 65               ; ASCII code of A
        val dw ?                ; Unintialized data item
.code
main:   mov ax, @data           ; Obtain address of data segment
        mov ds, ax              ; Initialize data segment

        lea dx, str             ; Obtain offset address of str
        mov ah, 9h              ; Service # to display a string
        int 21h                 ; Call OS to do the job

        mov dl, 13              ; Place ASCII code of Enter key
        mov ah, 2h              ; Service # to display a char
        int 21h                 ; Call OS to do the operation

        mov dl, 10              ; Place ASCII code of Line feed
        mov ah, 2h              ; Service # to display a char
        int 21h                 ; Call OS to do the operation
       
        mov dl, chr             ; Place ASCII code of char to display
        mov ah, 2h              ; Service # to display a char
        int 21h                 ; Call OS to do the operation

        mov ah, 4ch             ; Service # to terminate a program normally
        int 21h                 ; Call OS to do it
end main

Read More

Articles for you