Programming the Basic Computer 8 4 Instruction Formats

Programming the Basic Computer

8. 4 Instruction Formats • The most common fields in instruction formats are: 1. Mode field: Specifies the way the effective address is determined 2. Operation code: Specifies the operations to be performed. 3. Address field: Designates a memory address or a processor register Mode Opcode Address

8. 4 Instruction Formats • Zero address instruction: Stack is used. Arithmetic operation pops two operands from the stack and pushes the result. • One address instructions: AC and memory. Since the accumulator always provides one operand, only one memory address needs to be specified. • Two address instructions: Two address registers or two memory locations are specified, one for the final result. • Three address instructions: Three address registers or memory locations are specified, one for the final result. It is also called general address organization.

Zero address instructions Instruction: ADD Push and pop operations need to specify one address involved in data transfer. Stack-organized computer does not use an address field for the instructions ADD, and MUL Instruction: POP X Evaluate X = ( A + B ) * ( C + D ) PUSH, and POP instructions need an address field to specify the operand

Zero address instructions PUSH A PUSH B ADD PUSH C PUSH D ADD MUL POP X Advantages: No memory addresses needed during the operation. Disadvantages: results in longer program codes.

One address instructions • One address can be a register name or memory address. • SINGLE ACCUMULATOR ORGANIZATION • Since the accumulator always provides one operands, only one memory address needs to be specified. Instruction: ADD X Microoperation: AC ¬ AC + M[X]

One address instructions LOAD A ADD B STORE T All operations are done between the AC register and memory operand Advantages: fewer bits are needed to specify the address. Disadvantages: results in writing long programs.

Two address instructions • • Assumes that the destination address is the same as that of the first operand. Can be a memory address or a register name. • Instruction: ADD R 1, R 2 Microoperation: R 1 + R 2

Two address instructions MOV R 1, A MOV R 2, B ADD R 1, R 2 MOV X, R 1 most common in commercial computers Each address fields specify either a processor register or a memory operand Advantages: results in writing medium size programs Disadvantages: more bits are needed to specify two addresses.

Three address organization • GENERAL REGISTER ORGANIZATION • Three address instructions: Memory addresses for the two operands and one destination need to be specified. Instruction: ADD R 1, R 2, R 3 Microoperation: R 1 R 2 + R 3 ADD R 1, R 2, R 3 • Advantages: results in writing short programs Disadvantages: more bits are needed to specify three addresses.

EXAMPLE: Show can the following operation be performed using: a- three address instruction b- two address instruction c- one address instruction d- zero address instruction X = (A + B) * (C + D)

a-Three-address instructions (general register organization) • • • ADD R 1, A, B R 1 M[A] + M[B] ADD R 2, C, D R 2 M[C] + M[D] MUL X, R 1, R 2 M[X] R 1 * R 2

b-Two-address instructions (general register organization) • • • MOV R 1, A R 1 M[A] ADD R 1, B R 1 + M[B] MOV R 2, C R 2 M[C] ADD R 2, D R 2 + M[D] MOV X, R 2 M[X] R 2 MUL X, R 1 M[X] R 1 * M[X]
![c- One-address instructions • • • • LOAD A AC M[A] ADD B AC c- One-address instructions • • • • LOAD A AC M[A] ADD B AC](http://slidetodoc.com/presentation_image_h2/d1bddcace030815fafb4781f56f69015/image-14.jpg)
c- One-address instructions • • • • LOAD A AC M[A] ADD B AC + M[B] STORE T M[T ] AC LOAD C AC M[C] ADD D AC + M[D] MUL T AC * M[T ] STORE X M[X] AC Store

d- Zero-address instructions (stack organization) • Push value • Else If operator is encountered: Pop, pop, operation, push • Pop operand pop another operand then perform an operation and push the result back into the stack. • • • PUSH A TOS A Push PUSH B TOS B ADD TOS (A+B) Pop, pop, operation, push PUSH C TOS C PUSH D TOS D ADD TOS (C+D) MUL TOS (C+D)*(A+B) POP X M[X] TOS (*TOS stands for top of stack).
- Slides: 15