Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 03-14-2012, 06:12 PM   #1
In Runtime
 
Join Date: Sep 2010
Posts: 240
Default Assembler

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.
__________________

TP-Oreilly is offline   Reply With Quote
Old 03-16-2012, 04:57 AM   #2
In Runtime
 
Join Date: Sep 2010
Posts: 240
Default Re: Assembler

?
__________________

TP-Oreilly is offline   Reply With Quote
Old 03-21-2012, 12:15 PM   #3
Site Team
 
berry120's Avatar
 
Join Date: Jul 2009
Location: England, UK
Posts: 3,425
Default Re: Assembler

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.)

Quote:
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.
__________________
Save the whales, feed the hungry, free the mallocs.
berry120 is offline   Reply With Quote
Old 03-21-2012, 12:48 PM   #4
Daemon Poster
 
Dngrsone's Avatar
 
Join Date: Nov 2006
Location: 'Murica
Posts: 951
Default Re: Assembler

Quote:
Originally Posted by berry120 View Post
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.
__________________
Civility, Substance, Subtlety, Style: Success
Dngrsone is offline   Reply With Quote
Old 03-23-2012, 06:41 PM   #5
In Runtime
 
Join Date: Sep 2010
Posts: 240
Default Re: Assembler

Thanks
TP-Oreilly is offline   Reply With Quote
Old 03-26-2012, 08:33 AM   #6
Beta Member
 
mohsen's Avatar
 
Join Date: Mar 2012
Location: Iran
Posts: 5
Question Re: Assembler

Quote:
Originally Posted by berry120 View Post
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!!
can cpus understand the Assembly language?
help please!!!
mohsen is offline   Reply With Quote
Old 03-27-2012, 05:03 AM   #7
In Runtime
 
Join Date: Sep 2010
Posts: 240
Default Re: Assembler

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?
TP-Oreilly is offline   Reply With Quote
Old 03-28-2012, 11:55 AM   #8
Daemon Poster
 
Dngrsone's Avatar
 
Join Date: Nov 2006
Location: 'Murica
Posts: 951
Default Re: Assembler

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.
__________________
Civility, Substance, Subtlety, Style: Success
Dngrsone is offline   Reply With Quote
Old 03-30-2012, 04:11 PM   #9
In Runtime
 
Join Date: Sep 2010
Posts: 240
Default Re: Assembler

Thank you for your detailed reply
TP-Oreilly is offline   Reply With Quote
Old 03-31-2012, 11:18 AM   #10
Beta Member
 
mohsen's Avatar
 
Join Date: Mar 2012
Location: Iran
Posts: 5
Default Re: Assembler

Thanks For Your Perfect Answer
__________________

mohsen is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 06:19 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0