01 Accumulator

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Basic arithmetic operations

M1, M2, M3, M4 ja M5 are memory addresses which you must initialize before making computations. If you need to use more memory locations for example for intermediate results you can use M6-M9. M1 M9 are labels that are defined in the source code template on the last page. Compiler decides exact memory locations when source is compiled.

Exercise
Write a program that computes M5 = (M1 + M2) * (M3 + (M2 * M4)). Try to minimize the number of instructions. Remember that you need to save result of calculation in the end! Verify your result by initializing memory locations to contain last four digits of your student number. Use one digit for each memory location. If digit is zero use numbers from this sequence: 4, 5, 6, 7, 8. Verify your result by calculating the answer yourself and compare your answer with the one that your program produced. The last multiplication can result in a number that is larger than 8-bits. This indicated by register B having non-zero value after multiplication. Ignore upper half of multiplication result (register B) but verify if it affects final result. Calculate the result using windows calculator and convert into hexadecimal value. The lower two digits are in A and upper two in B. Make a note in your comments about the result of your last multiplication.

Accumulator
All ALU-operations are performed on two operands. One of the operands is always accumulator (register A) and result is stored in accumulator. In the following list direct is a memory location. Instead of memory addressed use labels that are defined at the beginning of the source code template. Following instructions are available: ADD ADD MUL MOV MOV MOV MOV MOV MOV MOV MOV MOV MOV XCH XCH A, Rn A, direct AB A, Rn Rn, A A, direct direct, A Rn, direct direct, Rn B, Rn Rn, B B, direct direct, B A, Rn A, direct Add register to A Add memory location to A. Multiply A & B. Move register to A Move A to register Move memory location to A Move A to memory location Move memory location to register Move register to memory location Move register to B Move B to register Move memory location to B Move B to memory location Exchange register with A Exchange memory location

Replace direct with label of memory location you want to access. Replace Rn with general purpose register of your choice. You have 8 general purpose registers available. Registers are named R0 R7. Example: MOV A, M5 ADD A, R3 MOV R0, A MOV A, R1 MOV B, M2 MUL AB ; move byte from memory to register A ; add register R3 to A ; copy result to R0

; multiply R1 with M2

Code template for exercise is on the next page

Code template
;This section assigns labels memory locations ; Directve (.dseg) tells compiler that these ; go into data memory .dseg at 20h .ds 1 .ds 1 .ds 1 .ds 1 .ds 1 .ds 1 .ds 1 .ds 1 .ds 1 ; Directive (.cseg) tells compiler to put following ; things into program memory .cseg ;starting address of the program .ORG 0 ;The addresses of instructions and ;variables may overlap because the ;program and data memories are in ;different address spaces ; set initial values to memory locations ; write your own initial values here ; (replace zeros with your own values) mov M1, #0 mov M2, #0 mov M3, #0 mov M4, #0 ; your own code starts from here

M1: M2: M3: M4: M5: M6: M7: M8: M9:

; end of source code .END

You might also like