05.10.2013 Views

1 Code Generation Code generator phase ... - VTU e-Learning

1 Code Generation Code generator phase ... - VTU e-Learning

1 Code Generation Code generator phase ... - VTU e-Learning

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

MOV b, R0 / load b to register Ro,<br />

MUL C, R0<br />

MOV.R0, a Mov a to Ro and moving Ro to a can be eliminated<br />

MOV a, R0<br />

MUL e, R0<br />

MOV R0, d<br />

Redundant instruction should be eliminated.<br />

Replace n instruction by single instruction<br />

x = x + 1<br />

MOV x, R0<br />

ADD 1, R0 ⇒ INC x<br />

MOV R0. x<br />

Register allocation: If the operands are in register the execution is faster hence the set of<br />

variables whose values are required at a point in the program are to be retained in the<br />

registers.<br />

Familiarities with the target machine and its instruction set are a pre-requisite for designing a<br />

good code <strong>generator</strong>.<br />

Target Machine: Consider a hypothetical byte addressable machine as target machine. It<br />

has n general purpose register R1, R2 ------- Rn. The machine instructions are two address<br />

instructions of the form<br />

op-code source address destination address<br />

Example:<br />

MOV R0, R1<br />

ADD R1, R2<br />

Target Machine supports for the following addressing modes<br />

a. Absolute addressing mode<br />

Example: MOV R0, M where M is the address of memory location of one of the<br />

operands. MOV R0, M moves the contents of register R0 to memory location M.<br />

b. Register addressing mode where both the operands are in register.<br />

Example: ADD R0, R1<br />

c. Immediate addressing mode – The operand value appears in the instruction.<br />

Example: ADD # 1, R0<br />

2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!