x86 assembly--RTC Interrupt (time display)

Source: Internet
Author: User
Tags clear screen

You can display the time by loading the RTC Interrupt program with the loader of the previous operating system kernel loader (x86 assembler).

; user.asm; The header file of the program, the information table of the whole program;--------Header-----------------------------------section header align=16 vstart= 0program_length DD program_endprogram_entry DW start DD section.code.startsection_count DW (sectio N_end-section_begin)/4section_begin:section_code DD section.code.startsection_data DD Section.data.startsection_ Stack dd section.stack.startsection_int dd section.interupt.start Section_end:;header end; Additional application for a segment for interrupt handling;----------- ---interupt-------------------------section interupt align=16 vstart=0rtc_int:push AX push BX push CX push Dxpush Espush D s; time to wait for the RTC to be read. Waits:mov DX, 0x70mov al, 0xaor al, 0x80; block nmiout DX, Almov DX, 0x71in al, DX Test al, 0x80jnz. WA  Itsmov CX, 3xor al, AL, read RTC seconds, read RTC, read RTC Read_time:or al, 0x80out 0x70, Almov bl, AL in Al, 0x71push Ax mov al, BL add al, 2loop read_time; Read Register C, let again interrupt mov dx, 0x70mov al, 0xc; this time do not prevent nmi interrupt out DX, AL mov dx, 0x71in al, dx; start quasi Ready to display time mov ax, 0xb800mov es, ax mov bx, 12*160 + 40*2mov CX, 3show_rtc:pop ax call Bcd_to_asciimov [ES:BX], ah mov [es:bx+2], alcmp bx, (12*160 + 40*2 +) JE @1mov al,  ': ' mov [es:bx+4], Al not Byte[es:bx+5]@1:add bx, 6loop Show_rtcmov al, 0x20out 0x20, Al out 0xa0, al pop ds pop Espop Dxpop cxpop bxpop AXIRET;BCD code to ASCII code = = "Four BCD converted to a decimal number (0~9), decimal number plus 0x30 hexadecimal number Bcd_to_ascii:mov Ah, Al and Al, 0x0fadd al , 0x30shr Ah, 4and Ah, 0x0fadd ah, 0x30ret; bcd_to_ascii end; interupt end;-------------Code begin--------------------- ----section code align=16 vstart=0; set up stack Start:mov ax, [Section_stack]mov SS, AX mov sp, ax; Set data segment mov ax, [section_data] mov ds, ax; display the content before the installation is interrupted MOV bx, begin_msgcall Print_stringmov bx, install_msgcall print_stringcli; Install interrupt push DS mov ax, 0x 00mov ds, Ax mov al, 0x70; starting from the chip default interrupt number, the main film is: 0x80mov bl, 4mul BL mov bx, ax mov word[ds:bx], Rtc_intmov ax, [es:section_ Int]mov word[ds:bx+2], axpop ds; set register B; COMs port 0x70/0x71mov DX, 0x70mov al, 0xbor al, 0x80; disable NMI interrupt out DX, AL mov DX, 0x71mov al, 0x12ouT DX, AL; Read Register C start interrupt mov dx, 0x70mov al, 0xcout dx, AL mov dx, 0x71in al, DX; set pending word bits from the slice, 0xa1; main film is 0x21mov DX, 0xa1 In Al, DX and al, 0xfeout DX, al Stimov bx, Done_msgcall print_string; show Timemov ax, 0xb800mov es, ax mov si, time_ Msgmov di, 12*160 + 32*2mov CX, (data_end-time_msg) Show_time:mov al, [Si]mov [Es:di], al Inc si add di, 2loop show_ time.halt:hltjmp. Halt; The process of printing strings;--------------------print_string---------------Print_string:mov cl, [BX]CMP cl, 0 JZ . Retcall print_charinc BX jmp print_string.ret:ret;p rint_string end;---------------------Print_  Char-----------------Print_char:push AX push bxpush cx push DX push DS push es; first get the position of the cursor mov dx, 0x3d4mov al, 0xeout DX, Al mov dx, 0x3d5in al, DX mov ah, al mov dx, 0x3d4mov al, 0xfout DX, Almov DX, 0x3d5in al, Dxmov bx, ax; Carriage return CMP cl, 0xd jnz if_nextlinemov bl, 80div bl mul BL mov bx, ax jmp set_cursor; in fact, this is not clear screen, but the cursor returns, but this line still has data; JMP roll_s Creen; determine if a newline character if_nextline:cmp cl, 0xajnz Is_charaddBX, 80jmp roll_screen; ok for normal characters Is_char:mov ax, 0xb800mov ds, AXSHL bx, 1mov [BX], clshr BX, 1inc bxroll_screen:cmp BX, X-=2000jl Set_cursormov es, Axcldmov si, 0xa0; x = 2mov x 1920rep di, 0x0mov cx, Movswmov BX, 1  920clean_lastline:mov CX, 80clean_line:mov Word[di], 0x720add di, 2loop Clean_lineset_cursor:mov DX, 0x3d4mov al,  0xeout DX, Almov DX, 0x3d5mov al, Bhout dx, AL mov dx, 0x3d4mov al, 0xfout DX, Almov DX, 0x3d5mov al, Blout DX, Alpop es pop dspop dxpop cxpop bxpop ax RET;PRINT_STRINGF end;code end;-------------data begin-------------------------SE ction data align=16 vstart=0begin_msg db ' Begin ... ', 0xd, 0xa, 0install_msg db ' Installing ... ', 0xd,0xa, 0done_msg db ' Do Ne .... ', 0time_msg db ' time: ' data_end:;d ata end;-------------stack begin-------------------------Section stack align= Vstart=0resb 256stack_end:;stack end;-------------tail begin--------------------------Section tail align=16  Program_end:;tail End
Reprint Address: http://blog.csdn.net/yuzhihui_no1/article/details/41869291

x86 assembly--RTC Interrupt (time display)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.