Assembly. Stop system time
I have a task for my Assembly course t开发者_Go百科o stop system time while pressing Alt-button. I do it by disabling the 8th interrupt. As I understand system time is saved in the 40:6ch cell of memory, so by reading this data we can achieve current system time, but also we can achieve current system time by using the second function of 1ah interrupt. Are they equal?
I check my program in DosBox. When i check system time in 40:6ch it doesn't change while pushing Alt button, if i check system time via 1ah interrupt - the time keeps changing though the 8th interrupt was disabled(it increments 40:6ch 18 times per second, as i understand). So what time should i really check? Or is there any other way to stop system time?
Here is the program for checking time via 40:6ch:
OutStr macro str ;макрос вывода строки
push dx
push ax
mov ah,09h
lea dx,str
int 21h
pop ax
pop dx
endm
;----------------------------------------
OutChar macro char ;макрос вывода символа
push ax
push dx
mov ah,06h
mov dl,char
add dl,'0'
int 21h
pop dx
pop ax
endm
;---------------------------------------
;---------------------------------------
.386
ASSUME CS:CODE, DS:DATA
DATA SEGMENT USE16
M1 DB 13,10,':$'
M2 DB 13,10,'Current time',13,10,'$'
M3 DB 13,10,'Equal times',10,13,'$'
M4 DB 13,10,'Alt is not pushed',10,13,'$'
M5 DB 13,10,'Alt is pushed',10,13,'$'
DATA ENDS
CODE SEGMENT USE16
begin:
mov ax,DATA ;initialization
mov ds,ax
beg:
in al, 60h
cmp al,38h ; is Alt pressed?
jne beg ;No
OutStr M5 ; Alt is pressed
cur:
mov ax, 40h
mov es, ax
mov ebx, dword ptr es:[6ch] ; current time
mov al,00000001b ;disable interrupts of the system timer
out 21h, al
thisl:
mov ecx, dword ptr es:[6ch]
cmp ebx, dword ptr es:[6ch]
je outputTrue
jmp next
outputTrue:
OutStr M3
next:
in al,60h
cmp al,38h ; is Alt pressed?
je thisl ; Yes
tt:
OutStr M4 ; Alt is not pressed
mov al,0h ; enable interrupts of the system timer
out 21h, al
jmp beg
CODE ENDS
end Begin
You are experiencing the difference between the RTC and the PIT.
The PIT is usually used for timing purposes in an OS, such as wait(10);
for wait 10 seconds. The RTC on the otherhand is used for keeping time, such as knowing the time is 12:53pm.
The PIT's interrupt is IRQ0, or interrupt 0x08. The RTC's interrupt is IRQ8, or interrupt 0x70. For a bit more information see this OSDev wiki and wikipedia
Also, it should be noted that probably even if you disable interrupt 0x70, the interrupt 0x1A will still report the timer as being incremented. This is because it doesn't need to send interrupts to the processor to keep time. It keeps time internally, which you can read through the input and output port commands.
精彩评论