Cannot comprehend machine language. What is machine language? -


i took compilers course , have understanding of how programming languages converted asts, intermediate representations , assembly code.

but having trouble understanding machine language. strings of 0s , 1s? if write 000001111010101000, machine language? computer directly understand that? basically, cannot comprehend machine language.

since understand processing source code assembly, lets start assembly , go machine code!

suppose have very simple cpu, has 2 4bit registers: a , b. instructions supported these:
1. ld a, 4bit_immediate. store operand in register a.
2. ld b, 4bit_immediate. store operand in register b.
3. add. perform b = b + a.
4. sub. perform b = - b.

to better understand machine code is, lets try implementing portion of simple cpu. technical note: example (with faked ics), synchronization part of circuits (the clock, fact register file may o may not transparent, in general design of synchronous vs asynchronous logic nets) , front end left behind.

simple 4 bit machine

we need 2 4 bit register. in scheme reg a , reg b, pipo registers, write data register , read from 2 sets of 4 bit pin. can separately enable write (ew pin) , read (er pin).
below registers alu, alu take 2 4 bit operands (from 2 4 pin sets) , can perform addition (if pin e zero) or subtraction (if pin e 1). output of alu redirected input of reg b. note alu (i.e. in each cycle) compute "something" output stored if reg b enabled write.
above ci register, holds current instruction fetched memory.
black wires control logic wires. blue ones reg b data path, red ones reg a data path.

now, how can code 4 instructions?
1. ld a, imm4bit. need enable reg a write , nothing else. ci must contains value 0100 i3 i2 i1 i0 i3 i2 i1 i0 bit of immediate. ld a, 5 coded machine code 45h.
2. ld b, imm4bit. above, instruction 0001 i3 i2 i1 i0. ld b, 3 13h.
3. add. need enable regs reading , reg b writing. e pin must 0. 0011 xxxx xxxx means don't care (we got opcode space future features!). instruction coded 30h or 31h or ... or 3fh.
4. sub. above e pin set, 1011 xxxx. machine code instruction 0b0h 0bfh.

note how machine code series of numbers! note write machine code in hex rather binary.

when our assembler encounter following source

ld a, 3 ld b, 5 add ld a, 15 sub 

it must output raw binary file content (as seen hex editor)

43h 15h 30h b0h 0machine code

or string "c 0°" if think in term of ascii (or other encoding) strings suggest abandon thinking , adopt 1 numbers: machine code number 2.955.941.187 (in little endian).

so machine code series of numbers.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -