Assembler

TP-Oreilly

In Runtime
Messages
240
Hi,

I understand that when we write a program, the compiler will convert this into assembly code, which will then convert this into machine code.

I know that there are different types of assembly languages to suit different cpu architectures, such as intels x86 and x64 instruction sets.

My question is, where is the assembly program located? Is it actually stored on the cpu, as assemblers are cpu independent?

---------- Post added at 10:12 PM ---------- Previous post was at 10:08 PM ----------

Also, if we write a program which is converted into assembly which uses new cpu instructions, how would the program work on an older cpu?

Thanks.
 
Assembly code is essentially machine code, it's not converted into machine code. Think of it as a programming language your CPU understands directly. All other languages (C, C++, VB, Java, etc.) are just abstraction layers on top of ASM.

You're correct in that compilers often convert down to ASM (though not always, sometimes there's steps in between.)

Also, if we write a program which is converted into assembly which uses new cpu instructions, how would the program work on an older cpu?
In short, it won't! If you make use of an instruction set that doesn't exist on some processors, then you won't be able to run it on those older processors.
 
Assembly code is essentially machine code, it's not converted into machine code. Think of it as a programming language your CPU understands directly. All other languages (C, C++, VB, Java, etc.) are just abstraction layers on top of ASM.

You're correct in that compilers often convert down to ASM (though not always, sometimes there's steps in between.)


In short, it won't! If you make use of an instruction set that doesn't exist on some processors, then you won't be able to run it on those older processors.

This.

If you try running a program on an older machine (say a program written for the 486DX instruction set on a 286 processor) you will run into one of several problems, depending on how well the program was written/structured: If the developer wrote the headers correctly, the OS will say right off the bat that the program was not compatible and refuse to run it. Otherwise, you might get an error message of some sort during execution or the computer might hang up.
 
Assembly code is essentially machine code, it's not converted into machine code. Think of it as a programming language your CPU understands directly. All other languages (C, C++, VB, Java, etc.) are just abstraction layers on top of ASM.

You're correct in that compilers often convert down to ASM (though not always, sometimes there's steps in between.)

so,if we compile a program with compilers such as Delphi,C++,etc, the compiler convert the top level code to Assembly language? if it's true so what's the job of Assemblers?
convert Assembly Codes To Assembly Codes Again? i've confused!!:eek:
can cpus understand the Assembly language?
help please!!!
 
Good question ^^^

"Assembly code is essentially machine code, it's not converted into machine code"

Assembly code must be converted into assembly code??? Like the person above said, whats the point of an assembler then?
 
Assembly language and machine code are considered more or less synonymous, depending on who you talk to.

Machine code is the hard-and-fast numbers language the processor uses to do its thing.

Assembly language is a mnemonic language that is easier to visualize and use in place of just plain number codes when working with machine code.

For instance, machine instruction 0x00A may mean move the contents of register A to a memory location to be specified.

Or, you can use assembly instruction MOV to accomplish the same thing.

Yes, there is an assembler language that will translate those mnemonics into straight machine code, but Assembly is a lower-level language that translates directly to machine code.

In fact, I have somewhere a pamphlet listing the machine code/assembly for a Harris H100 24-bit mainframe. The machine I worked with had 512Kb addressable RAM, something like five registers. If I wanted to 'thumb-in' a program, using the interface panel on the computer itself, then I would use the machine code.

If I were to use the assembler that came with the native operating system, then I would use the assembly code. Some assemblers will have additional codes that automate certain basic functions, making for a faster programming cycle.

Higher-level languages do much the same, though they automate many more functions, at the cost of bloat-- if you want tight code (efficient, as small as possible), then you will program in machine or assembly. If you don't want to be bothered with optimizing your code, and just want to build the program as rapidly as possible, then use a higher language that will be larger in size and possibly a bit buggier.

Of course, if you are using a larger processor (32-bit, 64-bit, et al) with a dozen registers and a couple stacks, then you would be hard-pressed to get any programming done in assembly, so a higher-level language such as a C variant would be necessary.

The advantage of Assembly/Machine code is tight, compact code that runs as fast as the machine will go. The disadvantage is that the code is restricted to that specific processor (and likely that specific hardware), whereas using a high-level language is a lot easier to 'port' or translate to a different processor/hardware set.
 
Last edited:
Back
Top Bottom