# A question I find it difficult to solve

#### puzzle

Joined Oct 30, 2016
53
Hi,

I will appreciate any help solving this programming question :

"You have just those 4 operations :

BEQ lable - jump to lable if the result of the last line equals zero
INC Rn - Increase Rn by one
DEC Rn - decrease Rn by one
RST Rn - initiate Rn to zero (nullify it)

You have to write a pseudo code for implementing multiplication of 2 numbers stored in R1 and R2. You can use additional registers."

I've wrote this code, but I find it difficult to translate it to pseudo code using just this 4 operations :

#include <stdio.h>

int main() {
int n, m, i,j, c = 0;
printf("enter 2 positive numbers you want the multiply result of\n");
scanf("%d , %d", &n,&m);
if ((n == 0) || (m == 0))
return 0;
for (i = n; i > 0; i--)
for (j = m; j > 0; j--)
c += 1;
printf("%d", c);
return c;
}

thanks!

#### puzzle

Joined Oct 30, 2016
53
Code:
#include <stdio.h>

int main() {
int n, m, i,j, c = 0;
printf("enter 2  positive numbers you want the multiply result of\n");
scanf("%d , %d", &n,&m);
if ((n == 0) || (m == 0))
return 0;
for (i = n; i > 0; i--)
for (j = m; j > 0; j--)
c += 1;
printf("%d", c);
return c;
}

#### WBahn

Joined Mar 31, 2012
30,303
It would seem that one of the first things you should focus on is using those four instructions to implement an if-else structure. Given that, a looping structure is easy. At that point you have everything you need.

#### puzzle

Joined Oct 30, 2016
53
It would be easy if I had an BNEQ and not the BEQ, casue I am counting down...
If I had BNEQ as an instruction I could decrease R2 (m) and increase R3 (the result) until R2 equals zero.... same on R1.
I really don't know where to start from with BEQ.

#### WBahn

Joined Mar 31, 2012
30,303
Draw a flow chart for a selection statement that skips code if a particular test is true. Now rearrange that flow chart so that it skips code if that same test is false.

#### dannyf

Joined Sep 13, 2015
2,197
implementing multiplication of 2 numbers stored in R1 and R2
multiplication of m and n is the same of adding m n times. adding m is the same incrementing m times.

so something like this:
Code:
  for (; m; m--)
for (x=n; x; x--)
inc y;