150 likes | 329 Views
Operand Addressing And Instruction Representation. Tutorial 3. Addressing Modes. Addressing Modes. One, Two, Three-Address Machines. Consider how the C expression A = B*C + D might be evaluated by each of the one, two, and three-address instruction types.
E N D
Operand Addressing And Instruction Representation Tutorial 3
One, Two, Three-Address Machines • Consider how the C expression A = B*C + D might be evaluated by each of the one, two, and three-address instruction types. • • Assumptions: Addresses and data words are two bytes in size. Opcodes are 1 byte in size. Operands are moved to and from memory one word (two bytes) at a time. • • Three-Address Instructions: In a three-address instruction, the expression A = B*C + D might be coded as: • mult B, C, A • add D, A, Awhich means multiply B by C and store the result at A Then, add D to A and store the result at address A.
One, Two, Three-Address Machines • Two Address Instructions: In a two-address instruction, one of the operands is overwritten by the result. Here, the code for the expression A = B*C + D is: • load B, A • mult C, A • add D, A
One, Two, Three-Address Machines • One Address (Accumulator) Instructions: A one-address instruction employs a single arithmetic register in the CPU, known as the accumulator. The code for the expression A = B*C + D is now: • load B • mult C • add D • store A • The load instruction loads B into the accumulator, mult multiplies C by the accumulator and stores the result in the accumulator, and add does the corresponding addition. The store instruction stores the accumulator in A.
One, Two, Three-Address Machines • Evaluate the expression Z= (X*Y)+(W*Z) For 3address, 2 address, 1 address and 0 address instructions
Three Address Operands • 3 Address operands (first operand is the destination) Using the 3 address instructions the code to evaluate the expression for Z is written as:- Mult R1, X, Y Mult R2, W, u Add Z, R2, R1
Two address Instruction • When using two address instructions, one address specifies a register the other operand can be a register or a memory location. Load R1, X Mult R1, Y Load R2, W Mult R2, U Add R1, R2 Store Z, R1
One Address Instruction • The Accumulator is assumed as a destination in One Address instruction Load X Mult Y Store Temp Load W Mult U Add Temp Store Z
Zero Address Instruction • Stack based Architectures use no operands for instructions such as Add, Sub, Mult or Divide. Push X Push Y Mult Push W Push U Mult Add Pop Z
One, Two, Three-Address Machines Show the programs to execute Y= (A-B)/[C+(D*E)] on One address, two Address and Three Address operand Instructions Three Address Instruction: SUB Y, A, B YA-B MULT T, D, E T<- D*E ADD T, T,C TT+C DIV Y, Y, T YY/T
Two Address Instruction MOV Y, A YA SUB Y, B YY-B MOV T, D TD MULT T, E TT*E ADD T, C TT+C DIV Y, T YY/D
One Address Instruction LOAD D AC D MULT E ACACXE ADD C ACAC+C STORE Y YAC LOAD A AC A SUB B ACAC-B DIV Y AC AC/Y STORE Y YAC