我如何开始学习装配

时间:2021-01-30 07:09:16

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.

我想在我的Mac上编写一些程序集,理想的是原生的,但是我知道在QEMU中学习它是否更容易。

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?

我真的不知道从哪里开始,有关如何在程序集中运行程序的任何指示?

5 个解决方案

#1


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

我的建议是与那里最好的汇编制作人合作: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.

用C编写简单的程序,然后用-S开关编译它们。你将得到一个包含汇编代码的file.s。修补它,你会学到它。最好的部分是,如果你想学习不同的汇编程序,你可以将gcc编译为交叉编译器,并为任何支持的平台生成汇编程序。

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

记得用-O0禁用优化,否则你会发现奇怪的技巧。

This is hello world in assembler

这是汇编程序中的hello world

    .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

#2


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.

几年前(好多年),我选择了Peter Norton关于大会http://www.amazon.com/Assembly-Language-Primer-Personal-Computer/dp/0136619010的书。这是开始为PC组装编程的绝佳方式。我想知道你是否仍然可以得到它并使用DOSbox来完成它。

#3


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.

好吧即使不是有些人称之为“最佳”组件,我建议学习X86 / X86-64,因为它是最广泛使用的。要运行该程序,您只需使用GCC将其转换为二进制文件,然后通过控制台运行它。

#4


I learned MIPS and tested in SPIM for a class on "computer organization."

我学习了MIPS并在SPIM中测试了一个关于“计算机组织”的课程。

Not sure if this book will work, but it might be worth a shot. We used a "book" (more like a tutorial, and a cheatsheet really) written by the professor, so it's otherwise unavailable.

不确定这本书是否有用,但它可能值得一试。我们使用了一本由教授编写的“书”(更像是一本教程,一本真正的备忘单),所以它不可用。

#5


Get involved with communities that thrive in assembly code. The first that comes to mind is the demoscene. For one, check out the productions released for x86 Macs on pouet.net. Try getting in touch with some of the coders in the active groups. Some of them may be willing to share ideas and code and maybe even get you motivated to write your own.

参与在汇编代码中茁壮成长的社区。首先想到的是demoscene。首先,查看pouet.net上为x86 Mac发布的产品。尝试与活动组中的某些编码器取得联系。他们中的一些人可能愿意分享想法和代码,甚至可能让你有动力去写自己的想法和代码。

This is how I got started back in the day, but on an Atari 8-bit.

这就是我在当天开始的方式,但是在Atari 8位上。

#1


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

我的建议是与那里最好的汇编制作人合作: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.

用C编写简单的程序,然后用-S开关编译它们。你将得到一个包含汇编代码的file.s。修补它,你会学到它。最好的部分是,如果你想学习不同的汇编程序,你可以将gcc编译为交叉编译器,并为任何支持的平台生成汇编程序。

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

记得用-O0禁用优化,否则你会发现奇怪的技巧。

This is hello world in assembler

这是汇编程序中的hello world

    .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

#2


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.

几年前(好多年),我选择了Peter Norton关于大会http://www.amazon.com/Assembly-Language-Primer-Personal-Computer/dp/0136619010的书。这是开始为PC组装编程的绝佳方式。我想知道你是否仍然可以得到它并使用DOSbox来完成它。

#3


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.

好吧即使不是有些人称之为“最佳”组件,我建议学习X86 / X86-64,因为它是最广泛使用的。要运行该程序,您只需使用GCC将其转换为二进制文件,然后通过控制台运行它。

#4


I learned MIPS and tested in SPIM for a class on "computer organization."

我学习了MIPS并在SPIM中测试了一个关于“计算机组织”的课程。

Not sure if this book will work, but it might be worth a shot. We used a "book" (more like a tutorial, and a cheatsheet really) written by the professor, so it's otherwise unavailable.

不确定这本书是否有用,但它可能值得一试。我们使用了一本由教授编写的“书”(更像是一本教程,一本真正的备忘单),所以它不可用。

#5


Get involved with communities that thrive in assembly code. The first that comes to mind is the demoscene. For one, check out the productions released for x86 Macs on pouet.net. Try getting in touch with some of the coders in the active groups. Some of them may be willing to share ideas and code and maybe even get you motivated to write your own.

参与在汇编代码中茁壮成长的社区。首先想到的是demoscene。首先,查看pouet.net上为x86 Mac发布的产品。尝试与活动组中的某些编码器取得联系。他们中的一些人可能愿意分享想法和代码,甚至可能让你有动力去写自己的想法和代码。

This is how I got started back in the day, but on an Atari 8-bit.

这就是我在当天开始的方式,但是在Atari 8位上。