Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I start learning Assembly

Tags:

assembly

I'd like to play with writing some assembly on my Mac, ideally native, but I'd understand if it's easier to learn in QEMU or something.

I see that there are different dialects of assembly depending on the processor - what dialect is the "best" to learn?

I don't really have any idea of where to start, any pointers as to how to even run a program in assembly?

like image 981
Rich Bradshaw Avatar asked Jul 20 '09 17:07

Rich Bradshaw


People also ask

How do I get started in assembly?

Write simple programs in C and then compile them with the -S switch. you will get a file. s containing the assembler code. Tinker with it and you will learn it.

Is learning assembly easy?

Assembly language is also quite dif- ferent from Pascal. It will be a little harder to learn than one of the other Pascal-like languages. However, learning assembly isn't much more difficult than learning your first programming language. Assembly is hard to read and understand.


3 Answers

My suggestion is to act with the best assembler producer out there: gcc.

Write simple programs in C and then compile them with the -S switch. you will get a file.s containing the assembler code. Tinker with it and you will learn it. The best part is that if you want to learn a different assembler, you can just compile gcc as cross compiler, and produce assembler for any supported platform.

Remember to disable optimizations with -O0, otherwise you could find strange tricks.

This is hello world in assembler

    .cstring
LC0:
    .ascii "hello world!\0"
    .text
.globl _main
_main:
    pushl   %ebp
    movl    %esp, %ebp
    pushl   %ebx
    subl    $20, %esp
    call    L3
"L00000000001$pb":
L3:
    popl    %ebx
    leal    LC0-"L00000000001$pb"(%ebx), %eax
    movl    %eax, (%esp)
    call    L_puts$stub
    movl    $0, %eax
    addl    $20, %esp
    popl    %ebx
    leave
    ret
    .section __IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5
L_puts$stub:
    .indirect_symbol _puts
    hlt ; hlt ; hlt ; hlt ; hlt
    .subsections_via_symbols
like image 194
Stefano Borini Avatar answered Oct 09 '22 19:10

Stefano Borini


A few (OK many) years ago I picked up Peter Norton's book on Assembly http://www.amazon.com/Assembly-Language-Primer-Personal-Computer/dp/0136619010. It was a fantastic way to begin assembly programming for the PC. I wonder if you can still get this and use DOSbox to work through it.

like image 44
Rich Avatar answered Oct 09 '22 20:10

Rich


Well even though it isn't what some people call the "best" assembly out there, I would recommend learning X86 / X86-64 as it is the most widely used. To run the program, you can simply use GCC to translate it into binary and then run it through your console.

like image 45
Gab Royer Avatar answered Oct 09 '22 19:10

Gab Royer