[Solved] What is the trick to learn x86 assembly language on Windows PC? [closed]


1) x86 probably the worst instruction set to learn first. just because you have one is not a good reason (you may not know it but for every x86 you have several arm processors not that using those is a good idea either).

2) start with a simulator, bare metal makes it a lot easier…pcemu for example. ideally something that shows you stuff as it runs, register and memory accesses, not gdb type of a thing as that wont prevent you from a hang or crash or necessarily help for those.

3) arm/thumb or msp430 are good instruction sets

Nevertheless, this is on linux but can be done simply with windows as well..

main.c

#include <stdio.h>

extern unsigned int fun ( unsigned int a, unsigned int b );

int main ( void )
{
    printf("%u\n",fun(1,2));
    return(0);
}

fun.c

unsigned int fun ( unsigned int a, unsigned int b )
{
    return(a+b+7);
}

build and run

gcc -O2 -c fun.c -o fun.o
gcc -O2 main.c fun.o -o main
./main
10

now…

objdump -D fun.o
... the part we care about:
0000000000000000 <fun>:
   0:   8d 44 37 07             lea    0x7(%rdi,%rsi,1),%eax
   4:   c3  
...

from that make fun.s

.globl fun
fun:
    lea    0x8(%rdi,%rsi,1),%eax
    retq

changing the 7 to an 8

as fun.s -o funs.o
gcc -O2 main.c funs.o -o main
./main
11

there you go, an program with some x86 assembly, worry about main later. running on an operating system what you can do is extremely limited, so your hands will be tied, often leading to general protection faults crashing the program.

You can make increasingly more complicated C programs, compile and disassemble, look those instructions up on the web or in the books you have. Make mods where possible and see what happens.

Compilers do not necessarily generate code that is easy to follow, but it is code that obviously works. and the code generated is not the only way, also play with different optimization levels, for this kind of thing more optimization is better so long as you can write high level code that doesnt have dead code in it that gets optimized out.

solved What is the trick to learn x86 assembly language on Windows PC? [closed]