CSC231 GetTimeOfDay.asm

From dftwiki3
Jump to: navigation, search

--D. Thiebaut 17:51, 23 November 2008 (UTC)


;;; getTimeOfDay.asm
;;; D. Thiebaut
;;; 
;;;  nasm -f elf getTimeOfDay.asm
;;;  gcc -o getTimeOfDay driver.c asm_io.o getTimeOfDay.o
;;; 
%include "asm_io.inc"
        
        ;; -------------------------
        ;; data segment
        ;; -------------------------
        section .data
tvsec   dd      0               ; number of seconds since 01/01/1970
tvusec  dd      0               ; number of useconds


        ;; -------------------------
        ;; code area
        ;; -------------------------
        section .text
        global  asm_main
asm_main:       

;;; get the time of day in secs and print it
        
        mov     eax, 78         ; system call: get time of day
        mov     ebx, tvsec      ; address of buffer for secs/usecs
        mov     ecx, 0          ; NULL for timezone
        int     0x80
        mov     eax, [tvsec]
        call    print_int
        call    print_nl
        mov     eax, [tvusec]
        call    print_int
        call    print_nl
        
        
        ;; return to C program

        ret

Here's its output

[12:49:56] ~/public_html/classes/231$: ./getTimeofDay 
1227462599
278245

[12:49:59] ~/public_html/classes/231$: ./getTimeofDay 
1227462600
144638

[12:50:00] ~/public_html/classes/231$: ./getTimeofDay 
1227462600
753965

[12:50:00] ~/public_html/classes/231$: ./getTimeofDay 
1227462601
367852

[12:50:01] ~/public_html/classes/231$: ./getTimeofDay 
1227462601
938595

[12:50:01] ~/public_html/classes/231$: date
Sun Nov 23 12:50:08 EST 2008

The last command gets today's date...