1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | #include <stdio.h>
#include <stdlib.h>
void swap(int *x,int *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}
void selection_sort(int list[], int n)
{
int i, j, min;
for (i = 0; i < n - 1; i++)
{
min = i;
for (j = i+1; j < n; j++)
{
if (list[j] < list[min])
{
min = j;
}
}
swap(&list[i], &list[min]);
}
}
void printlist(int list[],int n)
{
int i;
for(i=0;i<n;i++)
printf("%d\t",list[i]);
}
void main()
{
const int MAX_ELEMENTS = 10;
int list[MAX_ELEMENTS];
int i = 0;
// generate random numbers and fill them to the list
for(i = 0; i < MAX_ELEMENTS; i++ ){
list[i] = rand();
}
printf("The list before sorting is:\n");
printlist(list,MAX_ELEMENTS);
// sort the list
selection_sort(list,MAX_ELEMENTS);
// print the result
printf("The list after sorting:\n");
printlist(list,MAX_ELEMENTS);
}
|
This blog is about my daily programming technologies I explore and work on. It contains data from my University learning materials to my Profession as Software Engineer. Programming in Asp.net, Windows Forms, JavaScript, HTML, OpenGL, Assembly Language, Dynamics CRM 2011.
Feedjit
Articles for you
Showing posts with label Hardware Programming. Show all posts
Showing posts with label Hardware Programming. Show all posts
Tuesday, December 31, 2013
C++ Program of Implementation of Selection Sort in C++, C Plus Plus,
By
Saqib Khan
at
December 31, 2013
C++ Program of Implementation of Selection Sort in C++, C Plus Plus,
2013-12-31T01:46:00-08:00
Saqib Khan
C++|Computer Science|F09B|Hardware Programming|Islamic University|Programming|
Comments
Labels:
C++,
Computer Science,
F09B,
Hardware Programming,
Islamic University,
Programming
Simplest and Easiest Inheritance in C++: Easy Implementation of Inheritance in C++ Student/Teacher Program in C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | #include<iostream.h>
#include<conio.h>
#define size 20
class person
{
protected:
char name[size];
int id;
public:
person():id(0) {name[size]=' ';}
virtual void getd();
virtual void putd();
virtual int isoutstanding()=0;
};
class student : public person
{
protected:
float gpa;
public:
student():person(){gpa=0;}
void getd();
void putd();
int isoutstanding();
};
class teacher : public person
{
protected:
int publish;
public:
teacher():person(){publish=0;}
void getd();
void putd();
int isoutstanding();
};
//defineing functions for student class
void student::getd()
{
cout<<"Enter the name of student\n";
cin.get(name,size);
cout<<"Enter ID or REG\n";
cin>>id;
cout<<"Enter gpa\n";
cin>>gpa;
}
void student::putd()
{
int i=0;
cout<<"Name of student is\n";
while(name[i]!='\0')
{
cout<<name[i];
i++;
}
cout<<"Reg or ID is\n";
cout<<id;
cout<<"gpa is\n";
cout<<gpa;
}
int student::isoutstanding()
{
if(gpa>=3.5)
return 1;
else
return 0;
}
//defineing methods of teacher
void teacher::getd()
{
cout<<"Enter the name of teacher\n";
cin.get(name,size);
cout<<"Enter ID or REG\n";
cin>>id;
cout<<"Enter number of publishes\n";
cin>>publish;
}void teacher::putd()
{
int i=0;
cout<<"Name of teacher is\n";
while(name[i]!='\0')
{
cout<<name[i];
i++;
}
cout<<"Reg or ID is\n";
cout<<id;
cout<<"Number of publish is\n";
cout<<publish;
}
int teacher::isoutstanding()
{
if(publish>=5)
return 1;
else
return 0;
}
int main()
{
person *pptr[20];
int n=0;
char choice,reply;
do
{
cout<<"Enter your choice";
cin>>choice;
if(choice=='s')
{
pptr[n] = new student;
}
else
{
pptr[n] = new teacher;
}
pptr[n]->getd();
n++;
cout<<"Do you want to run it again\n";
cin>>reply;
}
while(reply=='y');
getche();
return 0;
}
|
By
Saqib Khan
at
December 31, 2013
Simplest and Easiest Inheritance in C++: Easy Implementation of Inheritance in C++ Student/Teacher Program in C++
2013-12-31T01:32:00-08:00
Saqib Khan
C++|Computer Science|F09B|Hardware Programming|Islamic University|MASM|nasm|Programming|System Programming|Visual Studio 2012|
Comments
Labels:
C++,
Computer Science,
F09B,
Hardware Programming,
Islamic University,
MASM,
nasm,
Programming,
System Programming,
Visual Studio 2012
.asm, ASM, MASM, NASM, Assembly Language, To Display Floppy,MAth,Game-IO,DMA information when caps lock is on ; Else : Display Video Mode and No.of Drives installed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | ;Programmed by Saqib khan
;Purpose: To Display Floppy,MAth,Game-IO,DMA information when caps lock is on
; Else : Display Video Mode and No.of Drives installed.
;Dated: 22nd/May/2012
.model small
.stack 100h
.data
str_floppy_n db 10,"Floppy disk drive not installed.$"
str_floppy_y db 10,"Floppy disk drive installed. $"
str_math_n db 10,"Math coprocessor not installed. $"
str_math_y db 10,"Math coprocessor installed.$"
str_game_y db 10,"Game IO is installed:$"
str_game_n db 10,"Game IO is not installed:$"
str_vid0 db 10,"Video Mode None $"
str_vid1 db 10,"Video Mode:40*25 color $"
str_vid2 db 10,"Video Mode:80*25 color $"
str_vid3 db 10,"Video Mode:80*25 Monochrome $"
str_dma_ok db 10,"DMA is Present $"
str_dma_not db 10,"DMA is not Present $"
str_drives db 10,"No.of drives are: $"
.code
main:
mov ax,@data
mov ds,ax
int 11h ;Interrupt for Equipment installed
mov bx,ax ;Store original Copy
mov ah,2 ;Interrup for Keyboard Special Keys
int 16h ;Call OS to do the job
mov cl,2 ;Offset value for shifting
shl al,cl ;Shift Left al by the value of cl
jc video_mode ;Jump if carry flag is on
floppy_y:
mov ax,bx
and ax, 1 ;Masking value for Floppy disk drive
jz floppy_n ;Jump if zero flag
lea dx,str_floppy_y ;Load address of string
mov ah,9h ;Service # to display string
int 21h ;Call OS to do the job
jmp math_ok ;jmp next block
floppy_n:
lea dx,str_floppy_n ;Load address of string
mov ah,9h ;Service # to display string
int 21h ;Call OS to do the job
math_ok:
mov ax,bx ;Restore the original value
and ax,2 ;Masking value for
jz math_no
lea dx,str_math_y
mov ah,9h
int 21h
jmp dma_ok
math_no:
lea dx,str_math_n
mov ah,9h
int 21h
dma_ok:
mov ax,bx
and ax,256
jz no_dma
lea dx,str_dma_ok
mov ah,9h
int 21h
jmp Game_IO
no_dma:
lea dx,str_dma_not
mov ah,9h
int 21h
Game_IO:
mov ax,bx
and ax,4096
jz no_game_io
lea dx,str_game_y
mov ah,9h
int 21h
no_game_io:
lea dx,str_game_n
mov ah,9h
int 21h
jmp end_lbl
video_mode:
mov ax,bx
mov cl,4
and ax,48
shr al,cl
add al,30h
cmp al,30h
je str0_disp
cmp al,31h
je str1_disp
cmp al,32h
je str2_disp
lea dx,str_vid3
mov ah,9h
int 21h
jmp chk_drives
str0_disp:
lea dx,str_vid0
mov ah,9h
int 21h
jmp chk_drives
str1_disp:
lea dx,str_vid1
mov ah,9h
int 21h
jmp chk_drives
str2_disp:
lea dx,str_vid2
mov ah,9h
int 21h
chk_drives:
lea dx,str_drives
mov ah,9h
int 21h
mov cl,6
mov ax,bx
and ax,192
shr al,cl
inc al
mov dl,al
add dl,30h
mov ah,2h
int 21h
end_lbl:
mov ah,4ch
int 21h
end main
|
By
Saqib Khan
at
December 31, 2013
.asm, ASM, MASM, NASM, Assembly Language, To Display Floppy,MAth,Game-IO,DMA information when caps lock is on ; Else : Display Video Mode and No.of Drives installed.
2013-12-31T01:06:00-08:00
Saqib Khan
.ASM|Computer Science|F09B|Hardware Programming|Islamic University|MASM|nasm|Programming|Sir Asim|System Programming|
Comments
Labels:
.ASM,
Computer Science,
F09B,
Hardware Programming,
Islamic University,
MASM,
nasm,
Programming,
Sir Asim,
System Programming
Switch Case Implementation, Easiest Implementation, Choice Assembly Language, ASM, MASM, NASM Switch CASE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | ;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
|
By
Saqib Khan
at
December 31, 2013
Switch Case Implementation, Easiest Implementation, Choice Assembly Language, ASM, MASM, NASM Switch CASE
2013-12-31T00:22:00-08:00
Saqib Khan
.ASM|F09B|Hardware Programming|MASM|nasm|Programming|Sir Asim|Swith Case|System Programming|
Comments
Labels:
.ASM,
F09B,
Hardware Programming,
MASM,
nasm,
Programming,
Sir Asim,
Swith Case,
System Programming
.asm Assembly Language MASM, ASM, To Display Clock Timing COAL Sir Asim CS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | .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
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
end_lbl:
mov ah,4ch
int 21h
end main
|
By
Saqib Khan
at
December 31, 2013
.asm Assembly Language MASM, ASM, To Display Clock Timing COAL Sir Asim CS
2013-12-31T00:20:00-08:00
Saqib Khan
Computer Science|F09B|Hardware Programming|Programming|Sir Asim|System Programming|
Comments
.asm Coal ASM File Assembly Language: To display 4 items of my personal information Assembly Langugae Sir Asim
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | ; 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
|
By
Saqib Khan
at
December 31, 2013
.asm Coal ASM File Assembly Language: To display 4 items of my personal information Assembly Langugae Sir Asim
2013-12-31T00:16:00-08:00
Saqib Khan
.ASM|Computer Science|F09B|Hardware Programming|Islamic University|MASM|Sir Asim|System Programming|
Comments
Labels:
.ASM,
Computer Science,
F09B,
Hardware Programming,
Islamic University,
MASM,
Sir Asim,
System Programming
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
.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
By
Saqib Khan
at
June 01, 2013
Generate a beautiful Sound from the System Internal Speaker in Assembly language
2013-06-01T01:52:00-07:00
Saqib Khan
.ASM|5th Semester|61h Read Port B|Assembly Language|Command Register|F09B|Hardware Programming|in al|Islamic University|MASM|Sir Asim|System Speaker|
Comments
Labels:
.ASM,
5th Semester,
61h Read Port B,
Assembly Language,
Command Register,
F09B,
Hardware Programming,
in al,
Islamic University,
MASM,
Sir Asim,
System Speaker
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
.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
By
Saqib Khan
at
June 01, 2013
System Info Display Int 11h
2013-06-01T01:50:00-07:00
Saqib Khan
.ASM|Assembly Language|Computer Science|F09B|Hardware Programming|int 11h|Islamic University|MASM|Sir Asim|
Comments
Labels:
.ASM,
Assembly Language,
Computer Science,
F09B,
Hardware Programming,
int 11h,
Islamic University,
MASM,
Sir Asim
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
;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
By
Saqib Khan
at
June 01, 2013
Simplest Implementaion of Switch Case in Assembly Language .asm file MASM file 32-bit/64bit
2013-06-01T01:49:00-07:00
Saqib Khan
.ASM|.NET|5th Semester|Add|Add with Carry|Assembly Language|Computer Science|F09B|Hardware Programming|Islamic University|Sir Asim|Subtract|Swith Case|System Programming|
Comments
Labels:
.ASM,
.NET,
5th Semester,
Add,
Add with Carry,
Assembly Language,
Computer Science,
F09B,
Hardware Programming,
Islamic University,
Sir Asim,
Subtract,
Swith Case,
System Programming
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
; 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
By
Saqib Khan
at
June 01, 2013
Display Personal Information in Assembly Language .asm file Coal
2013-06-01T01:48:00-07:00
Saqib Khan
.ASM|Assembly Language|F09B|Hardware Programming|Islamic University|MASM|Programming|Sir Asim|
Comments
Labels:
.ASM,
Assembly Language,
F09B,
Hardware Programming,
Islamic University,
MASM,
Programming,
Sir Asim
Subscribe to:
Posts (Atom)