Git Product home page Git Product logo

assembly-example's Introduction

Assembly

Common Functions and Code written in Assembly Language

  • Intel(x86-32)
  • ATT&T
  • MIPS

Compiling x86 on Mac OSX and FreeBSD

Steps:

  • nasm -o hello.tmp -f macho hello.s
  • ld -arch i386 -macosx_version_min 10.6 -no_pie -e _main -o hello.o hello.tmp
  • ./hello.o

One-Liner:

  • nasm -o hello.tmp -f macho hello.s && ld -arch i386 -macosx_version_min 10.6 -no_pie -e _main -o hello.o hello.tmp && ./hello.o

Important:

Note: I use .tmp in order to go from (.s) - assembly -> (.tmp) - temporary -> (.o) - binary
Note: I also use "&&" in order to stop execution if anything goes wrong

For nasm:

  • -o hello.tmp - outfile
  • -f macho - specify format
    • Linux - elf or elf64
    • Mac OSX - macho

For ld:

  • -arch i386 - specify architecture (32 bit assembly)
  • -macosx_version_min 10.6 (Mac OSX - complains about default specification)
  • -no_pie (Mac OSX - removes ld warning)
  • -e main - specify main symbol name (Mac OSX - default is start)
  • -o hello.o - outfile

For Shell:

  • ./hello.o - execution

Compilation Issues:

Mac OSX

"ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in _start from hello.o. To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie"

  • Add the "-no_pie" option to "ld" when linking

"ld: warning: -macosx_version_min not specified, assuming 10.6"

  • Add the "-macosx_version_min 10.6" option to "ld" when linking

Other

"ld: warning: option -m is obsolete and being ignored"

  • Older option

"ld: warning: option -s is obsolete and being ignored"

  • Older option

assembly-example's People

Contributors

jaredsburrows avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.