Page 1 of 1
Programmable Interrupt Timer
Posted: Wed Nov 03, 2004 12:00 am
by cipek
I don't know how reprogramable PIT to 100Hz frequency. Please help me !!!
I've got this code in C but i don't know how change it into asembly
Code: Select all
void ChangePITfrequency(unsigned long hz)
{
unsigned long val=1193180/hz;
outb(0x36,0x43);
outb(val&0xff,0x40);
outb((val>>8)&0xff,0x40);
}
Re: Programmable Interrupt Timer
Posted: Thu Nov 04, 2004 12:00 am
by Daidalos
The "outb function" above is just a macro that emits inline assembly. Translate them directly into OUT assembly language instructions with an 8-bit data operand.
Re: Programmable Interrupt Timer
Posted: Thu Nov 04, 2004 12:00 am
by cipek
yes i know what is outb. It's asembly out istruction. but i don't know how trenslate it into asembly:
Code: Select all
outb(val&0xff,0x40);
outb((val>>8)&0xff,0x40);
Re: Programmable Interrupt Timer
Posted: Thu Nov 04, 2004 12:00 am
by Anton
cipek wrote:I don't know how reprogramable PIT to 100Hz frequency. Please help me !!!
I've got this code in C but i don't know how change it into asembly
Code: Select all
void ChangePITfrequency(unsigned long hz)
{
unsigned long val=1193180/hz;
outb(0x36,0x43);
outb(val&0xff,0x40);
outb((val>>8)&0xff,0x40);
}
I havent programed in asm for a long time, so i am trying my best:
mov eax,1193180
mov edx,0
div hz;
mov ebx,eax;//saving-it better be 2 bytes!
mov dx,0x43;
mov al,0x36;
out dx,al;
mov dx,0x40;
mov al,bl;
out dx,al;
mov al,bh;
out dx,al;
Re: Programmable Interrupt Timer
Posted: Thu Nov 04, 2004 12:00 am
by chase
Instead of converting the code to assembly you could also do the assembly inside of the C code with inline assembly. We've got a quick tutorial for doing this type of thing located at
http://www.osdev.org/howtos/2/index.html
Re: Programmable Interrupt Timer
Posted: Thu Nov 04, 2004 12:00 am
by rexlunae
chase wrote:Instead of converting the code to assembly you could also do the assembly inside of the C code with inline assembly. We've got a quick tutorial for doing this type of thing located at
http://www.osdev.org/howtos/2/index.html
I agree. It would be much better in most cases to use inline assembly where necessary rather than converting entire functions to assembly. However if you are dead-set on converting the code to assembly, you could just use the -S option to gcc to do it.
gcc -S foo.c
will make a file called foo.s which is the assembly for your file.
Re: Programmable Interrupt Timer
Posted: Fri Nov 05, 2004 12:00 am
by cipek
Thank's everybody! I do that
Code: Select all
mov al,0b6h
out 42h,al
mov ax,11930
out 40h,al
mov al,ah
out 40h,al
ret
I don't testing it but i think it's work
Re: Programmable Interrupt Timer
Posted: Mon Nov 08, 2004 12:00 am
by pepito
I use this code:
mov al, 0x36 ; Couter-0, LSB-MSB, Onda-4, n-Binary
out 0x43, al
mov ax, 11931 ; Divisor for 100MHz
out 0x40, al ; Send LSB
shr ax, 8
out 0x40, al ; Send MSB
Re: Programmable Interrupt Timer
Posted: Tue Nov 09, 2004 12:00 am
by Anton
pepito wrote:
shr ax, 8
out 0x40, al ; Send MSB
=
out 0x40,ah
(I think
)
Re: Programmable Interrupt Timer
Posted: Tue Nov 09, 2004 12:00 am
by Da_Maestro
Anton wrote:pepito wrote:
shr ax, 8
out 0x40, al ; Send MSB
=
out 0x40,ah
(I think
)
That instruction is an invalid combination of opcodes and operands. The out instruction uses only AL or an immediate operand. It cannot use a memory location or any other registers either.
Re: Programmable Interrupt Timer
Posted: Fri Nov 19, 2004 12:00 am
by dr_watts
Could always use the Local APIC if you have one...