gcc assembly question on Mac

Discussion in 'General Mac Discussion' started by chrislee8, Aug 5, 2004.

  1. macrumors regular

    Joined:
    Jul 26, 2004
    Location:
    NY, NY
    #1
    Code:
    .data                       ; section declaration - variables only
    
    msg:
      .ascii    "Hello, world!\n\0"
      len = . - msg		    ; length of our dear string
    
    .text                       ; section declaration - begin code
    
      .globl _main
    _main:
    
    # write our string to stdout
    
      li      r0, 4         ; syscall number (sys_write)
      li      r3, 1         ; first argument: file descriptor (stdout)
    			; second argument: pointer to message to write
      lis     r4, ha16(msg); load top 16 bits of &msg
      addi    r4, r4,lo16(msg)   ; load bottom 16 bits
      li      r5, len       ; third argument: message length
      sc			; call kernel
    
    # and exit
    
      li      r0, 1		; syscall number (sys_exit)
      li      r3, 1		; first argument: exit code
      sc			; call kernel
    
    
    this is the assembly code, then I do this at the root prompt:
    gcc helloworld.s -o helloworld, it compiles and create the helloworld, i thought the will be executable to run, so I run it, it says helloworld command not found.

    so what the process of having the executable to run and display 'hello world' as my program does?

    thanks
     
  2. macrumors regular

    Joined:
    Jun 14, 2002
    Location:
    Mountain View, California
    #2
    By default, the current directory is not in your path; the file is being created, but the command line doesn't know to look for it there. Under bash, use:

    export PATH=${PATH}:.

    Under tcsh, I think it would be: setenv PATH ${PATH}:.

    If you need to run programs from the current working directory on a regular basis, you should add this line to your shell config files.
     
  3. thread starter macrumors regular

    Joined:
    Jul 26, 2004
    Location:
    NY, NY
    #3
    thanks man
    it works
     

Share This Page