Introductory ARM - Assembly Error

Question!

For a class just starting out with the ARM assembly language, we are required to implement a simple for-loop described below:

h=1;
for (i=0, i<5, i++)
    h=(h*3)-i;

I have written the following code in ARM assembly:

     AREA Prog2, CODE, READONLY
     ENTRY

     MOV r0, #1;         initialize h=1
     MOV r1, #0;         initialize i=0
loop CMP r1, #5;         at start of loop, compare i with 5
     MULLT r0, r0, #3;   if i<5, h=h*3
     SUBLT r0, r0, r1;   if i<5, h=h-i (ties in with previous line)
     ADDLT r1, r1, #1;   increment i if i is less than 5
     BLT loop ;          repeat loop of i is less than 5

stop B stop;             stop program
     END

The problem is that there is an error with the line

     MULLT r0, r0, #3;   if i<5, h=h*3

If I delete it from the code, everything works fine. I just cannot understand the issue with this one line. The error description given is "Bad register name symbol, expected integer register." I have tried loading #3 into a register then multiplying the two registers, but that didn't help. It simply changed the error message to "This register combination results in unpredictable behavior." I am new to this, so please offer only basic instructions as a fix for this. Thanks.



Answers

Multiplying by 3 is overrated anyway; ARM can do it with a single ridiculously idiomatic addition:

add r0, r0, r0 lsl #1    // r0 = r0 + r0 *2


MUL requires all operands to be registers, so you must use the form MUL r0, rn, r0 where rn is some other suitable register.

If the result and the first operand are the same the result is unpredictable as the error says. This is due to the internal operation of the processor. This is why you must use r0, rn, r0 and not r0, r0, rn



Alternatively, you could omit return and block braces, but the function body should be one liner with implicit return:

render() {
  return(
    <div>
      {array.map((element, index) => <MyComponent disturbingVariable={100 + index}/>)}
    </div>
  )
}

More about implicit return here

By : leo


This video can help you solving your question :)
By: admin