# assembly gcc on Mac question.



## chrislee8 (Aug 5, 2004)

```
.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


----------



## scruffy (Aug 5, 2004)

could it just be that it's not in your path?  Does it work if you explicitly say ./helloworld ?


----------



## Captain Code (Aug 5, 2004)

You might have to do chmod +x helloworld to make it executable, but I think gcc will do that for you.

Then you'll have to do the ./helloworld to run it.


----------



## chrislee8 (Aug 5, 2004)

i found out export PATH = ${PATH}:. work for me. thanks guys


----------



## lurk (Aug 6, 2004)

Just for reference putting . in your path like you did above is a security risk.  A common account hijack is to write a program called something like "cd" which squirrels away the access privileges of someone who executes it and the does the cd.  Now this is obviously only really a problem on multiuser systems but it is a good habit to get into of typing ./foo to execute foo in the current directory and not sticking . in your path.


----------

