//----------------------------------------------------------------- // tomorrow.s // // Here is one possible solution to the programming exercise // in Question V, Midterm Exam II. It uses information from // the PC's Real-Time Clock to show tomorrow's weekday-name. // // to assemble: $ as tomorrow.s -o tomorrow.o // and to link: # ld tomorrow.o -o tomorrow // // programmer: ALLAN CRUSE // written on: 11 APR 2007 //----------------------------------------------------------------- # manifest constants .equ sys_IOPL, 110 # system-call ID-number .equ sys_WRITE, 4 # system-call ID-number .equ sys_EXIT, 1 # system-call ID-number .equ STDOUT, 1 # device-file ID-number .equ STDERR, 2 # device-file ID-number .section .data msg0: .ascii "You forgot to execute 'iopl3' \n" len0: .int . - msg0 # length of error-msg msg1: .ascii "Tomorrow is " # first half of report buf: .ascii "xxxxxxxxxx \n" # final half of report len1: .int . - msg1 # length of the report name: .ascii "Sunday Monday Tuesday Wednesday " .ascii "Thursday Friday Saturday Sunday " day: .int 0 .section .text _start: # try to modify the I/O Privilege-Level mov $sys_IOPL, %eax # system-call ID-number mov $3, %ebx # desired IOPL-value int $0x80 # invoke kernel service or %eax, %eax # did request succeed? jz ok # yes, we can do in/out # else show failure message mov $sys_WRITE, %eax # system-call ID-number mov $STDERR, %ebx # device-file ID-number lea msg0, %ecx # address of message mov len0, %edx # length of message int $0x80 # invoke kernel service jmp exit # and terminate program ok: # input today's weekday-number from the RTC (Sunday=1) mov $6, %al # RTC's weekday register out %al, $0x70 # is selected for access in $0x71, %al # input register's value and $0x0000007, %eax # take remainder mod 8 mov %eax, day # then store in memory # compute tomorrow's day-number incl day # add 1 to day's number # copy tomorrow's day-name into the message-buffer mov $10, %ecx # length of each name mov day, %eax # setup for a multiply mul %ecx # compute name's offset lea name(%eax), %esi # point to name-string lea buf, %edi # and to message-buffer cld # do forward processing rep movsb # copy name into message # show the message mov $sys_WRITE, %eax # system-call ID-number mov $1, %ebx # device-file ID-number lea msg1, %ecx # address of message mov len1, %edx # length of message int $0x80 # invoke kernel service exit: # terminate this program mov $sys_EXIT, %eax # system-call ID-number mov $0, %ebx # use zero as exit-code int $0x80 # invoke kernel service .global _start # make entry-point public .end # no more to be assembled NOTE: Official vendor documents show that day-numbers are in the range 1 through 7, with Sunday as day 1. However, we observed that Wednesday was day 3 on our DELL machine.