Question:
How do you write an assembly language?
Harry
2007-05-22 15:35:56 UTC
I know this process is long and boring, but I was wondering if anyone knew where I could find a website that teaches how to do it. Thank you!
Three answers:
polly_peptide
2007-05-22 15:51:38 UTC
Assembly language is fun... it's basically direct instructions to the processor, although it is a level above "machine-code".



The issue with assembly language is that it can be very different from one processor to the next. If you want to learn assembly, learn processor concepts first, then pick a particular processor and learn the assembly code for that. The basic grounding that you get learning processor concepts will serve you well in ALL aspects of programming, even in super-high-level languages. It is this knowledge that rescues me from many programming pitfalls that other programmers would be killed by. You have the right idea with wanting to learn assembly. Start with the basics and build from there.



That said, the best processor to learn on is probably the old Motorola 6502C. It only has two registers and an accumulator, it has 16-bit addressing, and a small instruction set. It doesn't do any complex forward-looking or branch pre-calculation or any of that BS which confuses the issue on Pentiums.



The 6502 chip was used in the Commodore Vic-20, Commodore 64, 8-bit Nintendos, and the Apple II lineup. Since it was so popular, information about how to use it is prevalent even today. It is also fairly easy to get your hands on because you can pull one from an old computer, or you can still order them new. You can also find them in other devices like alarm clocks, and there are simulations of the chip which you can run on Windows (links below). There are many web sites, but I started with a simple Google search, and came up with these, which look pretty good... least likely to confuse you anyway.



http://www.6502.org/

http://www.geocities.com/oneelkruns/65index.html

http://www.geocities.com/oneelkruns/asm1step.html

http://richardbowles.tripod.com/cpu_sim/cpu_sim.htm

http://www.atarihq.com/danb/6502.shtml



Note that most of these sites assume that you are starting with a basic knowledge of processors. Be aware that you can Google almost anything for simple definitions... if you don't understand "addressing mode" for example, then you need to read up on it. Any omissions in basic concepts can make assembly very confusing to learn.
Dave H
2007-05-22 23:16:08 UTC
Are you asking how to write IN assembly language or how to write AN assembly language.



Assembly language is a very basic language where 1 assembly instruction translates into 1 machine executable instruction. Macros can be used to create paragraphs of instructions that can be expanded when included in your program.



If you want to write AN assembly language, you will need to have the documentation on the specific processor that you are writing the assembly language for.



For example an assembly instruction may be

LOAD AX, 1



which would load the AX register with the immediate value of 1.



You would need to know how the op-code (machine instruction) is encoded in binary. you would then need to create a translating program that looks up the instructions, and the arguments and determines from the arguments the type of instruction to generate the binary op-code for and how the arguments are formatted in binary.



Most of the time, the processor developer will provide or make available the assembler for the processor. Sometimes

they will even provide or make available a C compiler which translates C code into assembler before assembling the assembly code.



You probably just want to write a program in assembly language. If this is the case, you will need to study the instruction set for the processor.



To get a first look at assembly language, you can take this C

code and compile it with the -S option.



This is the C code compiled on an intel based linux machine with "cc -S":



int test(int x, int y)

{

return x + y;

}



This is the resulting assembler code:

.file "x.c"

.version "01.01"

gcc2_compiled.:

.text

.align 4

.globl test

.type test,@function

test:

pushl %ebp

movl %esp,%ebp

movl 8(%ebp),%eax

movl 12(%ebp),%ecx

leal (%ecx,%eax),%edx

movl %edx,%eax

jmp .L2

.p2align 4,,7

.L2:

leave

ret

.Lfe1:

.size test,.Lfe1-test

.ident "GCC: (GNU) 2.95.3 20010315 (release)"
2007-05-22 22:53:38 UTC
You will not learn this from the web, you need a book on whichever cpu assembly language you are writing for. The command list is massive, you also need multiple sets of instructions if you wish the program to be compatible with all processors in common use.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...