├── .gitignore ├── README.md └── hello.asm /.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !*/ 3 | !*.* 4 | *.o -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # learning-asm 2 | 3 | Everything has started from this tweet: 4 | 5 |
6 | 7 | In this repo I'm gonna collect links and resources, that I used for learning [Assembly][assembly]. 8 | 9 | ## Get it running 10 | 11 | I'm working on _MacBook Pro 13" early 2015_ with _macOS Siera_ and use [**nasm**][nasm]. I haven't checked that, but I think it should work on Linux too. 12 | 13 | Probably you've already heart of [tasm], [masm] or [fasm]. To be honest, I don't know which one is better. After researching a bit, I find that [**nasm**][nasm] will be okay for me. _Maybe_. 14 | 15 | To install actual version of **nasm** (on my computer it was too old), type: 16 | 17 | $ brew install nasm 18 | 19 | Close and reopen the terminal and you will get the new version of **nasm**, which had the critical (for macOS) `macho64` format. Execute these commands and check if you have similar output: 20 | 21 | ``` 22 | $ nasm -v 23 | NASM version 2.12.02 compiled on Sep 14 2016 24 | $ nasm -hf 25 | ... 26 | macho32 NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (i386) object files 27 | macho64 NeXTstep/OpenStep/Rhapsody/Darwin/MacOS X (x86_64) object files 28 | dbg Trace of all info passed to output stage 29 | ... 30 | ``` 31 | 32 | ## Compiling and Linking 33 | 34 | To compile, link and run Assembly Program I use these commands: 35 | 36 | ```sh 37 | # Generate object file from assembly: 38 | $ nasm -f macho64 -o filename.o filename.asm 39 | 40 | # Link object file: 41 | ld filename.o -o filename 42 | 43 | # Run executable: 44 | ./filename 45 | ``` 46 | 47 | _Source:_ [Running Assembly on OS X](https://lord.io/blog/2014/assembly-on-osx/) 48 | 49 | [assembly]: https://en.m.wikipedia.org/wiki/Assembly_language 50 | [nasm]: https://en.m.wikipedia.org/wiki/Netwide_Assembler 51 | [tasm]: https://en.m.wikipedia.org/wiki/Turbo_Assembler 52 | [masm]: https://en.m.wikipedia.org/wiki/Microsoft_Macro_Assembler 53 | [fasm]: https://en.m.wikipedia.org/wiki/FASM -------------------------------------------------------------------------------- /hello.asm: -------------------------------------------------------------------------------- 1 | %define SYSCALL_WRITE 0x2000004 2 | %define SYSCALL_EXIT 0x2000001 3 | 4 | global start 5 | start: 6 | mov rdi, 1 7 | mov rsi, str 8 | mov rdx, strlen 9 | mov rax, SYSCALL_WRITE 10 | syscall 11 | 12 | mov rax, SYSCALL_EXIT 13 | mov rdi, 0 14 | syscall 15 | 16 | section .data 17 | str: 18 | db `Hello, assembly!\n` ; to use escape sequences, use backticks 19 | strlen equ $ - str --------------------------------------------------------------------------------I've got a strong desire to learn some basics of Assembler. Can anyone suggest a good point to start from?
— Denys Dovhan (@denysdovhan) 7 Oct 2016