//---------------------------------------------------------------- // showdate.s // // This Linux assembly language program adjusts its IOPL, to // permit executing 'in' and 'out' instructions which access // the Real-Time Clock's clock/calendar registers, so it can // display the current day-of-the-week and the current date. // // assemble using: $ as showdate.s -o showdate.o // and link using: $ ld showdate.o -o showdate // // programmer: ALLAN CRUSE // written on: 16 MAY 2004 //---------------------------------------------------------------- .equ sys_EXIT, 1 # ID-number for 'exit' .equ sys_WRITE, 4 # ID-number for 'write' .equ sys_IOPL, 110 # ID-number for 'iopl' .equ dev_STDOUT, 1 # ID-number for STDOUT .section .data dayname: .ascii " Sun Mon Tue Wed Thu Fri Sat " monname: .ascii " Jan Feb Mar Apr May Jun Jul " .ascii "Aug Sep Oct Nov Dec " message: .ascii " \n\r" len: .int . - message # count of characters .section .text _start: # adjust this task's IO Privilege-Level movl $sys_IOPL, %eax # system-call ID-number movl $3, %ebx # new value for IOPL int $0x80 # enter the kernel # read the current day-of-the-week movb $6, %al # select register-number out %al, $0x70 # to be accessed in $0x71, %al # read selected register # use day-number to lookup weekday name movzx %al, %eax # extend byte to dword movl dayname(,%eax,4), %edx # lookup weekday's name mov %edx, message # insert name in message # read the current day-of-the-month movb $7, %al # select register-number out %al, $0x70 # to be accessed in $0x71, %al # read selected register # convert BCD value to decimal-string mov %al, %ah # copy BCD value to AH rol $4, %al # exchange the nybbles and $0x0F0F, %ax # mask isolates nybbles or $0x3030, %ax # convert to numerals mov %ax, message+4 # insert into message # read current month-of-the-year movb $8, %al # select register-number out %al, $0x70 # to be accessed in $0x71, %al # read selected register # use month-number to lookup month's name movzx %al, %eax # extend byte to dword movl monname(,%eax,4), %edx # lookup name for month mov %edx, message+7 # insert name in message # read the current year movb $9, %al # select register-number out %al, $0x70 # to be accessed in $0x71, %al # read selected register # convert BCD value to decimal-string mov %al, %ah # copy BCD value to AH rol $4, %al # exchange the nybbles and $0x0F0F, %eax # mask isolates nybbles rol $16, %eax # swap hiword and loword or $0x30303032, %eax # convert into numerals mov %eax, message+11 # insert into message # display message showing the current date mov $sys_WRITE, %eax # system-call ID-number mov $dev_STDOUT, %ebx # ID-number for device lea message, %ecx # message's offset mov len, %edx # message's length int $0x80 # enter the kernel # terminate this application mov $sys_EXIT, %eax # system-call ID-number mov $0, %ebx # value for exit-code int $0x80 # enter the kernel .globl _start # entry-point is public