{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

MIT6_004s09_lec11

# MIT6_004s09_lec11 - MIT OpenCourseWare http/ocw.mit.edu...

This preview shows pages 1–4. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
L11 - Machine Language 1 6.004 – Spring 2009 3/12/09 Machine Language, Assemblers, and Compilers When I ﬁnd my code in tons of trouble, Friends and colleagues come to me, Speaking words of wisdom: "Write in C." Long, long, time ago, I can still remember how mnemonics used to make me smile. .. And I knew that with just the opcode names that I could play those BSim games and maybe hack some macros for a while. But 6.004 gave me shivers with every lecture they delivered. Bad news at the door step, I couldn’t read one more spec. I can’t remember if I tried to get Factorial optimized, But something touched my nerdish pride the day my Beta died. And I was singing… References (on web site): ± Documentation BSIM reference Notes on C Language Quiz 2 TOMORROW! modiﬁed February 23, 09 L11 - Machine Language 2 6.004 – Spring 2009 3/12/09 ± Machine Language: 32-bit instructions Ra and Rb are the operands, Rc is the destination. R31 reads as 0, unchanged by writes arithmetic: ADD, SUB, MUL, DIV compare: CMPEQ, CMPLT, CMPLE boolean: AND, OR, XOR shift: SHL, SHR, SRA arithmetic: ADDC, SUBC, MULC, DIVC compare: CMPEQC, CMPLTC, CMPLEC boolean: ANDC, ORC, XORC shift: SHLC, SHRC, SRAC branch: BNE/BT, BEQ/BF (const = word displacement from PC NEXT ) jump: JMP (const not used) memory access: LD, ST (const = byte oﬀset from Reg[ra]) Two’s complement 16-bit constant for numbers from –32768 to 32767; sign-extended to 32 bits before use. OPCODE r c r a r b unused OPCODE r c r a 16-bit signed constant How can we improve the programmability of the Beta? L11 - Machine Language 3 6.004 – Spring 2009 3/12/09 Encoding Binary Instructions Means, to BETA, Reg[4] = Reg[2] + Reg[3] OpCode Rb Ra 10 (unused) 000 100 00 1 0 01 1 Rc 32-bit (4-byte) ADD instruction: But, most of us would prefer to write ADD(R2, R3, R4) a = b+c; or, be±er yet, (ASSEMBLER) (High Level Language) 0 Software Approaches: INTERPRETATION, COMPILATION L11 - Machine Language 4 6.004 – Spring 2009 3/12/09 Structure Language Application Applic Lang (())() (()()) (())() APPLICATION M 2 ± Result: a “virtual” M 2 Interpretation Turing’s model of Interpretation: M 1 ± Start with some hard-to-program universal machine, say M 1 Pgm ± Write a single program for M 1 which mimics the behavior of some easier machine, say M 2 “Layers” of interpretation: ± Often we use several layers of interpretation to achieve desired behavior, eg: DATA Scheme Interp Scheme SCHEME Hardware X86 Instrs X86 ± X86 (Pentium), running ± Scheme, running ± Application, interpreting ± Data.
L11 - Machine Language 5 6.004 – Spring 2009 3/12/09 Compilation Model of Compilation: M 1 ± Given some hard-to-program machine, say M 1 ... P2 ± Find some easier-to-program language L 2 (perhaps for a more complicated machine, M 2 ); write programs in that language P1 C 2-1 ± Build a translator (compiler) that translates programs from M 2 ’s language to M 1 ’s language. May run on M 1 , M 2 , or some other machine.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 8

MIT6_004s09_lec11 - MIT OpenCourseWare http/ocw.mit.edu...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online