LM3000 Multiplication Program

From BenningtonWiki

Jump to: navigation, search

This program multiplies the two numbers X and Y, by adding X repeatedly to itself Y times.

Addr Code    Instruction         Comment
00   13XX    MOV  R0, #X         ; X  - the first number
01   17YY    MOV  R1, #Y         ; Y  - the second number
02   1B00    MOV  R2, #0         ; 0  - the counter
03   1F00    MOV  R3, #0         ; 0  - the sum


04   2000    MOV  A, R1          ; have we added the number sufficiently many times (i.e. Y times)?
05   2500    MOV  B, R2
06   4D00    CMP
07   F80C    BEQ  12             ; if so, end the program by sticking in a loop


08   2000    MOV  A, R0          ; add X to the sum
09   2700    MOV  B, R3
0A   4C00    ADD  R3
0B   F004    BRA  04

0C   F00D    BRA  13	         ; stick in a loop once finished w/ the multiplication
0D   F00C    BRA  12

The equivalent code in C might look like this:

int x;
int y;
int count;
int sum = 0;

for ( count = 0; count < y; count++  ) {
       sum += x;
}
Personal tools