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 System Programming. Show all posts
Showing posts with label System Programming. Show all posts
Tuesday, September 22, 2015
Display Analog Clock of System Time in Assembly Language Sir Asim Munir
By
Saqib Khan
at
September 22, 2015
Display Analog Clock of System Time in Assembly Language Sir Asim Munir
2015-09-22T01:24:00-07:00
Saqib Khan
.ASM|Assembly Language|F09B|Islamic University|MASM|nasm|Programming|Sir Asim|System Programming|
Comments
Labels:
.ASM,
Assembly Language,
F09B,
Islamic University,
MASM,
nasm,
Programming,
Sir Asim,
System Programming
Tuesday, December 31, 2013
Switch/Case in C++ easiest Implementation, C++ Burger Stand Program
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 | #include<iostream>
using namespace std;
void ast();
class stand
{
private:
int bun,shami,b,s;
public:
void init()
{
cout<<"Enter the total No. of burgers "<<endl;
cin>>bun;
cout<<endl;
cout<<"Enter the total No. of shami "<<endl;
cin>>shami;
cout<<endl;
}
void sale()
{
if(bun<=0)
cout<<"Sorry, no stock for burger"<<endl;
else
{cout<<"No. of burgers sold "<<endl;
cin>>b;
cout<<endl;
bun=bun-b;
}
if(shami<=0)
cout<<"Sorry, no stock for shami"<<endl;
else
{
cout<<"No. of shami sold "<<endl;
cin>>s;
cout<<endl;
shami=shami-s;
}
}
void disp()
{
if(bun<=0)
cout<<"There is no stock for burger"<<endl;
else
cout<<"No. of burgers left "<<bun<<endl;
if(shami<=0)
cout<<"There is no stock for shami"<<endl;
else
cout<<"No. of shami left "<<shami<<endl;}
};
void ast()
{
for(int i=1;i<=9;i++)
{cout<<"*";}
}
void main()
{
stand s1,s2,s3,s4;
int ch,sl;
char c;
cout<<endl;
cout<<"welcome to the burger shop"<<endl;
ast();
do{cout<<endl;
cout<<"Press 1 for stand# 01."<<endl;
cout<<"Press 2 for stand# 02."<<endl;
cout<<"Press 3 for stand# 03."<<endl;
cout<<"Press 4 for stand# 04."<<endl;
cout<<"Press 5 for exit"<<endl;
cin>>ch;
switch(ch)
{
case 1:
cout<<"Stand no 1"<<endl;
cout<<"Press 1 for initialization"<<endl;
cout<<"Press 2 for sale"<<endl;
cout<<"Press 3 for display"<<endl;
cout<<"Press 4 for main menu"<<endl;
cin>>sl;
switch(sl)
{
case 1:
s1.init();
break;
case 2:
s1.sale();break;
case 3:
s1.disp();break;
default:
cout<<"Sorry! You have enterd an Invalid Choice"<<endl;break;
}
break;
case 2:
cout<<"Stand no 2"<<endl;
cout<<"Press 1 for initialization"<<endl;
cout<<"Press 2 for sale"<<endl;
cout<<"Press 3 for display"<<endl;
cout<<"Press 4 for main menu"<<endl;
cin>>sl;
switch(sl)
{
case 1:
s2.init();break;
case 2:
s2.sale();break;
case 3:
s2.disp();break;
default:
cout<<"Sorry! You have enterd an Invalid Choice"<<endl;break;
}
break;
case 3:
cout<<"Stand no 3"<<endl;
cout<<"Press 1 for initialization"<<endl;
cout<<"Press 2 for sale"<<endl;
cout<<"Press 3 for display"<<endl;
cout<<"Press 4 for main menu"<<endl;
cin>>sl;
switch(sl)
{
case 1:
s3.init();break;
case 2:
s3.sale();break;
case 3:
s3.disp();break;
default:
cout<<"Sorry! You have enterd an Invalid Choice"<<endl;break;
}
break;
case 4:
cout<<"Stand no 4"<<endl;
cout<<"Press 1 for initialization"<<endl;
cout<<"Press 2 for sale"<<endl;
cout<<"Press 3 for display"<<endl;
cout<<"Press 4 for main menu"<<endl;
cin>>sl;
switch(sl)
{
case 1:
s4.init();break;
case 2:
s4.sale();break;
case 3:
s4.disp();break;
}
break;
case 5:
exit(0);break;
default:
{cout<<endl<<"Sorry! You have enterd an Invalid Choice";break;}
}
cout<<endl;
cout<<"Do you want to continue: (Y/N)"<<endl;
cin>>c;
}while(c!='n' && c!='N');
}
|
By
Saqib Khan
at
December 31, 2013
Switch/Case in C++ easiest Implementation, C++ Burger Stand Program
2013-12-31T01:40:00-08:00
Saqib Khan
C++|Computer Science|F09B|Islamic University|Programming|System Programming|
Comments
Labels:
C++,
Computer Science,
F09B,
Islamic University,
Programming,
System 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 22, 2013
Easiest Implementation of Analog Clock in Opengl C++ Source Code. Computer Graphics
- // GLclock.c
- // By Saqib Khan(International Islamic University Islamabad)
- // A openGL example program, displays a 3D clock face
- //
- // Keyboard inputs: [ESC] = quit
- // 'L' = enables/disables lighting
- // 'V' = toggle ortho/prespective view
- #include <GL/glut.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <time.h>
- // define glu objects
- GLUquadricObj *Cylinder;
- GLUquadricObj *Disk;
- struct tm *newtime;
- time_t ltime;
- GLfloat rx, ry, rz, angle;
- // lighting
- GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f };
- GLfloat LightDiffuse[]= { 0.5f, 0.5f, 0.5f, 1.0f };
- GLfloat LightPosition[]= { 5.0f, 25.0f, 15.0f, 1.0f };
- GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
- static int light_state = 1; // light on = 1, light off = 0
- static int view_state = 1; // Ortho view = 1, Perspective = 0
- void Sprint( int x, int y, char *st)
- {
- int l,i;
- l=strlen( st );
- glRasterPos3i( x, y, -1);
- for( i=0; i < l; i++)
- {
- glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, st[i]);
- }
- }
- static void TimeEvent(int te)
- {
- int timent;
- int i;
- rx = 30 * cos( angle );
- ry = 30 * sin( angle );
- rz = 30 * cos( angle );
- angle += 0.01;
- if (angle > M_TWOPI) angle = 0;
- glutPostRedisplay();
- glutTimerFunc( 100, TimeEvent, 1);
- }
- void init(void)
- {
- glClearColor (0.0, 0.0, 0.0, 0.0);
- glShadeModel (GL_SMOOTH);
- glEnable(GL_DEPTH_TEST);
- // Lighting is added to scene
- glLightfv(GL_LIGHT1 ,GL_AMBIENT, LightAmbient);
- glLightfv(GL_LIGHT1 ,GL_DIFFUSE, LightDiffuse);
- glLightfv(GL_LIGHT1 ,GL_POSITION, LightPosition);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT1);
- Cylinder = gluNewQuadric();
- gluQuadricDrawStyle( Cylinder, GLU_FILL);
- gluQuadricNormals( Cylinder, GLU_SMOOTH);
- gluQuadricOrientation( Cylinder, GLU_OUTSIDE);
- gluQuadricTexture( Cylinder, GL_TRUE);
- Disk = gluNewQuadric();
- gluQuadricDrawStyle( Disk, GLU_FILL);
- gluQuadricNormals( Disk, GLU_SMOOTH);
- gluQuadricOrientation( Disk, GLU_OUTSIDE);
- gluQuadricTexture( Disk, GL_TRUE);
- }
- void Draw_gear( void )
- {
- int i;
- glPushMatrix();
- gluCylinder(Cylinder, 2.5, 2.5, 1, 16, 16);
- gluDisk(Disk, 0, 2.5, 32, 16);
- glTranslatef(0,0,1);
- gluDisk(Disk, 0, 2.5, 32, 16);
- glPopMatrix();
- for( i = 0; i < 8; i++)
- {
- glPushMatrix();
- glTranslatef( 0.0, 0.0, 0.50);
- glRotatef( (360/8) * i, 0.0, 0.0, 1.0);
- glTranslatef( 3.0, 0.0, 0.0);
- glutSolidCube( 1.0 );
- glPopMatrix();
- }
- }
- void Draw_clock( GLfloat cx, GLfloat cy, GLfloat cz )
- {
- int hour_ticks , sec_ticks;
- glPushMatrix();
- glTranslatef(cx,cy,cz);
- glRotatef( 180, 1.0, 0.0, 0.0);
- glPushMatrix(); // Draw large wire cube
- glColor3f(1.0, 1.0, 1.0);
- glTranslatef( 0.0, 0.0, 6.0);
- glutWireCube(14.0);
- glPopMatrix();
- glPushMatrix(); // Draw clock face
- glTranslatef( 0, 0, 1.0);
- gluDisk(Disk, 0, 6.75, 32, 16);
- glPopMatrix();
- glPushMatrix();// Draw hour hand
- glColor3f(1.0, 0.5, 0.5);
- glTranslatef( 0, 0, 0.0);
- glRotatef( (360/12) * newtime->tm_hour + (360/60) * (60 / (newtime->tm_min+1)), 0.0, 0.0, 1.0);
- glPushMatrix();
- glTranslatef(0.0, 0.0, 2.0);
- Draw_gear();
- glPopMatrix();
- glRotatef( 90, 1.0, 0.0, 0.0);
- gluCylinder(Cylinder, 0.75, 0, 4, 16, 16);
- glPopMatrix();
- glPushMatrix();// Draw minute hand
- glColor3f(1.0, 0.5, 1.0);
- glTranslatef( 0, 0, 0.0);
- glRotatef( (360/60) * newtime->tm_min, 0.0, 0.0, 1.0);
- glPushMatrix();
- glTranslatef(0.0, 0.0, 3.0);
- glScalef(0.5, 0.5, 1.0);
- Draw_gear();
- glPopMatrix();
- glRotatef( 90, 1.0, 0.0, 0.0);
- gluCylinder(Cylinder, 0.5, 0, 6, 16, 16);
- glPopMatrix();
- glPushMatrix();// Draw second hand
- glColor3f(1.0, 0.0, 0.5);
- glTranslatef( 0, 0, -0.0);
- glRotatef( (360/60) * newtime->tm_sec, 0.0, 0.0, 1.0);
- glPushMatrix();
- glTranslatef(0.0, 0.0, 4.0);
- glScalef(0.25, 0.25, 1.0);
- Draw_gear();
- glPopMatrix();
- glRotatef( 90, 1.0, 0.0, 0.0);
- gluCylinder(Cylinder, 0.25, 0, 6, 16, 16);
- glPopMatrix();
- for(hour_ticks = 0; hour_ticks < 12; hour_ticks++)
- {
- glPushMatrix();// Draw next arm axis.
- glColor3f(0.0, 1.0, 1.0); // give it a color
- glTranslatef(0.0, 0.0, 0.0);
- glRotatef( (360/12) * hour_ticks, 0.0, 0.0, 1.0);
- glTranslatef( 6.0, 0.0, 0.0);
- glutSolidCube(1.0);
- glPopMatrix();
- }
- for(sec_ticks = 0; sec_ticks < 60; sec_ticks++)
- {
- glPushMatrix();
- glTranslatef(0.0, 0.0, 0.0);
- glRotatef( (360/60) * sec_ticks, 0.0, 0.0, 1.0);
- glTranslatef(6.0, 0.0, 0.0);
- glutSolidCube(0.25);
- glPopMatrix();
- }
- glPopMatrix();
- }
- void display(void)
- {
- time(<ime); // Get time
- newtime = localtime(<ime); // Convert to local time
- glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- // easy way to put text on the screen.
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity();
- glOrtho(-8.0, 8.0, -8.0, 8.0, 1.0, 60.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glDisable(GL_LIGHTING);
- glDisable(GL_COLOR_MATERIAL);
- // Put view state on screen
- glColor3f( 1.0, 1.0, 1.0);
- if (view_state == 0)
- {
- Sprint(-3, -4, "Perspective view");
- }else Sprint(-2, -4, "Ortho view");
- Sprint(-4,-8, asctime(newtime));
- // Turn Perspective mode on/off
- if (view_state == 0)
- {
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(60.0, 1, 1.0, 60.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt( rx, 0.0, rz, 0.0, 0.0, -14.0, 0, 1, 0);
- }
- if (light_state == 1)
- {
- glEnable(GL_LIGHTING);
- glEnable(GL_COLOR_MATERIAL); // Enable for lighing
- }else
- {
- glDisable(GL_LIGHTING);
- glDisable(GL_COLOR_MATERIAL); // Disable for no lighing
- }
- Draw_clock( 0.0, 0.0, -14.0);
- glutSwapBuffers();
- }
- void reshape (int w, int h)
- {
- glViewport (0, 0, (GLsizei) w, (GLsizei) h);
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity ();
- }
- void keyboard (unsigned char key, int x, int y)
- {
- switch (key)
- {
- case 'L':
- light_state = abs(light_state - 1);
- break;
- case 'V':
- view_state = abs(view_state - 1);
- break;
- case 27:
- exit(0); // exit program when [ESC] key presseed
- break;
- default:
- break;
- }
- }
- int main(int argc, char** argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowSize (500, 500);
- glutInitWindowPosition (10, 10);
- glutCreateWindow (argv[0]);
- glutSetWindowTitle("GLclock");
- init ();
- glutDisplayFunc(display);
- glutReshapeFunc(reshape);
- glutKeyboardFunc(keyboard);
- glutTimerFunc( 10, TimeEvent, 1);
- glutMainLoop();
- return 0;
- }
By
Saqib Khan
at
June 22, 2013
Easiest Implementation of Analog Clock in Opengl C++ Source Code. Computer Graphics
2013-06-22T00:35:00-07:00
Saqib Khan
C++|Computer Science|F09B|Islamic University|Opengl|Programming|System Programming|Visual Studio 2012|
Comments
Labels:
C++,
Computer Science,
F09B,
Islamic University,
Opengl,
Programming,
System Programming,
Visual Studio 2012
Saturday, June 1, 2013
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
.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
By
Saqib Khan
at
June 01, 2013
Display Clock of System Time in Assembly Language Sir Asim Munir
2013-06-01T01:51:00-07:00
Saqib Khan
.ASM|5th Semester|Assembly Language|Digital CLock|int 2Ch|Islamic University|MASM|Sir Asim|System Clock|System Programming|
Comments
Labels:
.ASM,
5th Semester,
Assembly Language,
Digital CLock,
int 2Ch,
Islamic University,
MASM,
Sir Asim,
System Clock,
System Programming
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
Subscribe to:
Posts (Atom)
