[ACCEPTED]-How do assembly languages work?-grammar
Computers are basically built out of logic gates. Though 63 this is an abstract idealization of the 62 real physical machinery, it is close enough 61 to the truth that we can believe it for 60 now. At a very basic level, these things 59 work just like true/false predicates. Or 58 if you've ever played minecraft, it works 57 a lot like redstone. The field which studies 56 how to put together logic gates to make 55 interesting complex circuits, like computers, is 54 called computer architecture. It is traditionally viewed as 53 a mixture of computer science and electrical 52 engineering.
The most basic logic gates are 51 things like AND, and OR which just take 50 bits together and smash out some boolean 49 operation between them. By creating feed 48 back loops in logic gates you can store 47 memory. One type of standard memory circuit 46 is called a flip-flop, and it is basically a little 45 loop of wire together with some AND gates 44 and power to keep it stable. Putting together 43 multiple latches lets you create bit vectors, and 42 these things are called registers (which are what 41 things like eax and ebx represent). There 40 are also many other types of parts, like 39 adders, multiplexors and so on which implement 38 various pieces of boolean logic. Here is 37 a directory of some circuits:
http://www.labri.fr/perso/strandh/Teaching/AMP/Common/Strandh-Tutorial/Dir.html
Your CPU is 36 basically a bunch of these things stuck 35 together, all built out of the same basic 34 logic gates. The way that your computer 33 knows how to keep on executing instructions 32 is that there is a special piece of machinery 31 called a clock which emits pulses at regular 30 intervals. When your CPU's clock emits 29 a pulse it sets off a sequence of reactions 28 in these logic gates that causes the CPU 27 to execute an instruction. For example, when 26 it reads an instruction that says "mov 25 eax, ebx", what ends up happening is 24 that the state of one of these registers 23 (ebx) gets copied over to the state of another 22 (eax) just in time before the next pulse 21 of comes out of the clock.
Of course this 20 is a gross oversimplification, but as a 19 high level picture it is essentially correct. The 18 rest of the details take awhile to explain, and 17 there are a few things here that I neglected 16 due to unnecessary subtlety (for example, in 15 a real CPU sometimes multiple instructions 14 get executed in a single clock; and due 13 to register paging sometimes eax isn't always 12 the same thing; and sometimes due to reordering 11 occasionally the way that instructions get 10 executed gets moved around, and so on). However, it 9 is definitely worth learning the whole story 8 since it is actually quite amazing (or at 7 least I like to think so!) You would be 6 doing yourself a great favor to go out and 5 read up on this stuff, and maybe try building 4 a few circuits of your own (either using 3 real hardware, a simulator, or even minecraft!)
Anyway, hope 2 that answers a bit of your question about 1 what mov eax, ebx does.
What you see there are mnemonics, which 19 make it easy for a programmer to write assembly; it 18 is however not executable in mnemonic form. When 17 you pass these assembly instructions through 16 an assembler, they are translated into machine 15 code they represent, which is what the CPU 14 and its various co-processors interpret 13 and execute (it's generally taken down into 12 smaller units by the CPU, called micro-ops).
If 11 you're curious as to how exactly it does 10 that, well that's a long process, but this has 9 all that information.
All the semantics, etc. are 8 handled by the assembler, which checks for 7 validity and integrity where possible (one 6 can still assemble invalid code however!). This 5 basically makes assembly a low-level language, even 4 though it has a 1 to 1 correlation to the 3 outputted machine code (except when using 2 macro based assemblers, but then the macros 1 still expand to 1 to 1).
Your CPU doesn’t execute assembly. The assembler 22 converts it into machine code. This process 21 depends on both the particular assembly 20 language and the target computer architecture. Generally 19 those go hand in hand, but you might find 18 different flavors of assembly language (nasm 17 vs. AT&T, for example), which all translate 16 into similar machine code.
A typical (MIPS) assembly 15 instruction such as “And immediate”
andi $t, $s, imm
would 14 become the 32-bit machine code word
0011 00ss ssst tttt iiii iiii iiii iiii
where 13 s
and t
are numbers from 0–31 which name registers, and 12 i
is a 16-bit value. It’s this bit pattern 11 that the CPU actually executes. The 001100
in 10 the beginning is the opcode corresponding 9 to the andi
instruction, and the bit pattern 8 that follows — 5-bit source register, 5-bit 7 target register, 16-bit literal — varies 6 depending on the instruction. When this 5 instruction is placed into the CPU, it responds 4 appropriately by decoding the opcode, selecting 3 the registers to be read and written, and 2 configuring the ALU to perform the necessary 1 arithmetic.
The instructions in assembly code map to 11 the actual instruction set and register 10 names for the CPU architecture you're targeting. mov
is 9 an X86 instruction, and eax
and others are 8 the names of (in this case general purpose) registers 7 defined it the Intel x86 reference manual.
Same 6 thing for other architectures - the assembly 5 code maps quite directly to the actual names 4 of the operations as defined in the chip's 3 specifications/documentation.
That mapping 2 is way more simple than for instance compiling 1 C
code.
first thing every instruction like mov ,add 18 etc have own meaning in binary form like 17 10101010, 00110000, 10100 some of these 16 also be, which understands cpu always.
but 15 human cant remember all of them. so... for 14 programming purpose that used in english 13 language. which is ultimately will come 12 to its own place(binary).
second thing conversion 11 from english(mov, add etc.) to binary occurs 10 at, when assembling or compiling them code. after 9 that- binary instructions(instruction sets) stored 8 in ram and ready for execution.
but it may 7 be not your answer i know.
if you want know 6 and imagine perfectly- how does cpu exucute 5 instructions and work on them. You can 4 learn it with graphics here. see this video 3 on youtube: (link given here)
watch 2 it once and i promise you. you will more 1 clear about it. have a look just right.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.