Skip to content

Instantly share code, notes, and snippets.

@pinglunliao
Created January 14, 2016 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pinglunliao/df69b41a9d7d4e9e3eb8 to your computer and use it in GitHub Desktop.
Save pinglunliao/df69b41a9d7d4e9e3eb8 to your computer and use it in GitHub Desktop.
//----------------------------------------------------------------
// sum.s:
//
// compile using: $ as sum.s -o sum.o
// link using: $ ld sum.o -o sum
// execute using: $ ./sum
//
//----------------------------------------------------------------
.text # this section is program
.global _start # entry point
_start:
movl $1, %eax # put 1 into eax
addl $8, %eax # add 8 into eax
addl $48, %eax # convert digit to ASCII
movl $msg, %ecx # put address of msg into ecx
movb %al, (%ecx) # store byte in al in location ecx
# points to
# write our string to stdout
movl $len,%edx # third argument: message length
movl $msg,%ecx # second: pointer to message
movl $1,%ebx # sum: file handle (stdout)
movl $4,%eax # system call number (sys_write)
int $0x80 # call kernel
# and exit
movl $0,%ebx # sum argument: exit code
movl $1,%eax # system call number (sys_exit)
int $0x80 # call kernel
.data # this section is data
msg:
.byte 72,10
len = . - msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment