CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Aug 2002
    Location
    Brazil
    Posts
    730

    Talking Linux assembly: Printing date and time

    Hello, I'm trying to print date and time in linux usign GAS (GNU assembler). I started from a hello world code and I modified to show system date and time.

    I'm stuck in two very basic errors I can't seem to find solution. Here's the code:

    Code:
    ##############################################################################
    ## getdatetime.s															##
    ##																			##
    ## Compile with:															##
    ## as -o getdatetime.o getdatetime.s && ld -o getdatetime -O0 getdatetime.o	##
    ##																			##
    ##############################################################################
    	.section .data
    	.section .text
    	.globl _start
    
    _start:
    	# call function to print date and time
    	jmp		print_date_time
    
    	## terminate program via _exit () system call 
    	xorl	%eax,		%eax	# %eax = 0
    	incl	%eax				# %eax = 1 system call _exit ()
    	xorl	%ebx,		%ebx	# %ebx = 0 normal program return code
    	int		$0x80				# execute system call _exit ()
    
    ## get system date and time and push it in stack: sec/min/hour/day/mon/year
    print_date_time:
    	movl	$78,		%eax	# getdatetime () system call
    	int		$0x80				# execute system call getdatetime ()
    	addl	$0x48,		%eax	# convert to ascii value
    	mov		%al,		%ecx	# print %al to see if we have something interesting in it (sec, min, hour, day, mon, year) or something
    	movl	$1,			%edx	# %edx = 1 = print length
    	movl	$4,			%eax	# write () system call
    	int $0x80					# execute write () system call
    	ret
    When I compile with

    Code:
    as -o getdatetime.o getdatetime.s && ld -o getdatetime -O0 getdatetime.o
    It gives me an error:

    Code:
    getdatetime.s: Assembler messages:
    getdatetime.s:27: Error: suffix or operands invalid for `mov'
    Line 27 is:
    Code:
    mov		%al,		%ecx	# print %al to see if we have something interesting in it (sec, min, hour, day, mon, year) or something
    Thanks for your attention.
    Last edited by bubu; May 21st, 2009 at 03:42 PM.
    All consequences are eternal in some way.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured