Which assembler should i use




















As under Linux, using a C runtime library makes it very easy to write simple assembly language programs. Here is one in NASM:. There are many versions of the library, but for single threaded programs, libc. Here is the powers program in MASM:. DOS is a primitive operating system indeed, many people, perhaps correctly, refuse to call it an operating system , which runs in real mode only.

A DOS program is a collection of segments. When the program is loaded, DS:0 and ES:0 points to a byte section of memory called the program segment prefix and this is immediately followed by the segments of the program. CS:0 will point to the code segment and SS:0 to the stack segment. SP will be loaded with the size of the stack specified by the programmer, which is perfect because on the x86 a PUSH instruction decrements the stack pointer and then moves the pushed value into the memory addressed by SS:SP.

The length of the command line argument string is placed in the byte at offset 80h of the prefix and the actual argument string begins at offset 81h. Note with the MASM assembler you have to place the. Of course if you wanted to link to a bit C runtime library you certainly can. The echo program defines only a code and stack segment; an example of a program with a programmer-defined data segment is:.

Although DOS has been obsolete for many years, a brief study of DOS systems and the x86 real-addressing mode is somewhat interesting. First, real-mode addresses correspond to real, physical memory, so one can watch exactly what is happening in the machine very easily with a good debugger. In fact, most embedded microprocessors work in a kind of "real mode. Finally a lot of DOS applications still exist, so it might be useful to know what kind of technology underlies it all.

A number of the conditional branches are given names that are intuitively based on the last operation performed being a special compare instruction, cmp see below. For example, conditional branches such as jle and jne are based on first performing a cmp operation on the desired operands.

Otherwise, continue to the next instruction. This instruction is equivalent to the sub instruction, except the result of the subtraction is discarded instead of replacing the first operand.

The call instruction first pushes the current code location onto the hardware supported stack in memory see the push instruction for details , and then performs an unconditional jump to the code location indicated by the label operand. Unlike the simple jump instructions, the call instruction saves the location to return to when the subroutine completes. The ret instruction implements a subroutine return mechanism.

This instruction first pops a code location off the hardware supported in-memory stack see the pop instruction for details. It then performs an unconditional jump to the retrieved code location. The calling convention is a protocol about how to call and return from routines. For example, given a set of calling convention rules, a programmer need not examine the definition of a subroutine to determine how parameters should be passed to that subroutine.

Furthermore, given a set of calling convention rules, high-level language compilers can be made to follow the rules, thus allowing hand-coded assembly language routines and high-level language routines to call one another.

A good way to visualize the operation of the calling convention is to draw the contents of the nearby region of the stack during subroutine execution. The image above depicts the contents of the stack during the execution of a subroutine with three parameters and three local variables.

The cells depicted in the stack are bit wide memory locations, thus the memory addresses of the cells are 4 bytes apart. The first parameter resides at an offset of 8 bytes from the base pointer. Above the parameters on the stack and below the base pointer , the call instruction placed the return address, thus leading to an extra 4 bytes of offset from the base pointer to the first parameter.

When the ret instruction is used to return from the subroutine, it will jump to the return address stored on the stack. Caller Rules To make a subrouting call, the caller should: Before calling a subroutine, the caller should save the contents of certain registers that are designated caller-saved. Since the called subroutine is allowed to modify these registers, if the caller relies on their values after the subroutine returns, the caller must push the values in these registers onto the stack so they can be restore after the subroutine returns.

To pass parameters to the subroutine, push them onto the stack before the call. The parameters should be pushed in inverted order i. Since the stack grows down, the first parameter will be stored at the lowest address this inversion of parameters was historically used to allow functions to be passed a variable number of parameters. To call the subroutine, use the call instruction. This instruction places the return address on top of the parameters on the stack, and branches to the subroutine code.

GAS is included in the GNU binutils and therefore does not introduce new dependencies to your project. If you want to write an project in assembly language entirely, the latter two are usually the tools of choice.

However, FASM being self-assembling and only needs a C standard library to work gives it a slight advantage here as it is way easier to port.

Jump to: navigation , search. Categories : Assembly X Does anyone know all of the dot net API? You know a small core section of any programming language very well, a bit more you can use, but maybe don't fully comprehend, and much large selection you know a little bit about, but have to refer to the manual, and there is an unknown amount about which you know nothing at all.

Even the ancient had dozens of operands and addressing methods. You learn what you need to do the job. The more jobs you do the more you learn. It's quite hard to tell which assembly is "most useful" unless you choose platform you want to use. If you go for PC intel, amd start with x86 assembly. Comes as an executable for Windows ready to run out of the box; decompress its archive and have at it from the command line. Currently, work is underway to develop an almost vm assembler evolving FAsm that will also include native support for ARM chips as well.

It provides macro support as well as headers following its format. For a complete listing of executable file formats supported by FAsm check out the official web site because there are many. FAsm has a pretty large user forum addressing topics regarding all the platforms it serves as well as topics ranging from openGL to developing homebrew PNG image transparency systems and GUI applications -pretty awesome stuff.

Remember that assembler, contrary to idiot speculation, will never die because every compiler has to do the same -just a friendly FYI --compile, link, assemble Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?

Collectives on Stack Overflow. Learn more. Which syntax and architecture of assembly is most useful to know? Ask Question. Asked 12 years, 2 months ago.

Active 4 years, 1 month ago. Viewed 5k times. Improve this question. Joe Phillips I suggest you learn one which is support by your CPU, so that you can practice it; so to start with, know what type of CPU you have. After you've done that, you may find more than one assembler which can emit assembly for your CPU; then choose the assembler in the same way that you might choose a compiler.

Assembly language is an interesting thing: in concept, it's simple to learn since most instructions are very easy to understand. The trick is piecing it all together and making all code paths work correctly.

You learn to be very careful when writing assembly, since debugging it requires a lot of effort. Knowing assembly is knowing how to write a loop, an if statement and things like that. It is the same in all assembly languages pretty much just like it is the same in all high level languages but is different from assembly to high level. The particular version of assembly needs a manual to get right!

Add a comment.



0コメント

  • 1000 / 1000