Jump to content
43oh

Assembler instruction format, if-then instruction


Recommended Posts

Hi,

Has anyone used the if-then instruction for the Tiva/Stellaris using the CCS assembler?

I am using CCS and I tried the following, which is supposed to be a simple rendering of

if( r2 == 0x10001)

    pass();

else

   fail(); 

 

    mov r2,#1
    movt r2, #1
    cmp r2,#0x10001
    itte eq
    bl pass
    bl fail
 
I get
"../main.s", ERROR!   at line 45: [E0003] Empty or Invalid condition code
   itte eq
1 Assembly Error, 2 Assembly Warnings
 
"../main.s", WARNING! at line 46: [W0004] Missing condition code inside of IT block
   bl pass
 
"../main.s", WARNING! at line 47: [W0004] Missing condition code inside of IT block
   bl fail
 
Unfortunately, I am unable to find any documentation on the formats required by the assembler so 
I am using the UAL (Universal Assembler Language) formats as described in the ARM documentation.
 
The only assembler manual I can find on ti.com is SPNU118 which spends a lot of time describing Assembler directives but very little on the actual instruction formats.
 
I have tried a number of combinations like
itte.eq
bleq pass
blne fail
but this has been an exercise in futility and I am really working in the dark here.
 
 
Link to post
Share on other sites

Well on further experimentation I found one way to do this.

myiteq .set 0xbf0c

.

.

   cmp r2,#0x10001
    .short myiteq
    mov r0, r1
    mov r0, r5
 
It appears to work as advertised - r0 ends up the same as r1
and the CCS disassembler likes it
0000004c:   BF0C     ITE             EQ
 46           mov r0, r1
0000004e:   4608     MOV             R0, R1
 47           mov r0, r5
00000050:   4628     MOV             R0, R5
 
Not exactly the most user-friendly to do it, but it gets the job done.
 
My original code appears to be wrong
    .short myiteq
    bl pass
    bl fail
calls both routines.
I read the spec as allowing a BL as the last instruction in an it block so I'm not sure what Is wrong here.
Link to post
Share on other sites

Hi,

Unfortunately more documentations about CCS asm cannot be found, except a practical example which exercise several possible directives to write .asm file. These are to be found in Tiva/boot-loader/bl_startup_ccs.s file.

As for IT instruction here are some aspects of using this:

 

In IT instruction blocks, the first line must be the IT instruction, detailing the choice of execution, followed by the condition it checks. The first statement after the IT command must be TRUE-THEN-EXECUTE, which is always written as ITxyz, where T means THEN and E means ELSE. The second through fourth statements can be either THEN (true) or ELSE (false). 

So the general form of this instruction is: IT<x><y><z> <cond>, where <x>, <y>, <z> can be T or E, so at maximum you have a choice of four instructions to be executed.

Example:

   cmp R1, R2                               ; if R1<R2 (less then)

   ITTEE LT                                 ; then execute instruction 1 and 2, as indicated by T

                                                    ; else execute instruction 3 and 4 as indicated by E

In the case of problems, try to write what you need as C statement and then see the generated listing. This is somewhat a cheating way, but until you find out more documentation...

L

Link to post
Share on other sites

Thanks for the tip Lyon,

Sadly, the bootstrap code contains no it instructions,( although a load of other useful examples)

bit I found a nice example in the third party RTOS code (third_party\FreeRTOS\Source\portable\CCS\ARM_CM4F\portasm.asm)

eg.

tst r14, #0x10
it EQ
vldmiaeq r0!, {s16-s31}
 
All I was missing was that the condition had to be upper case and you need the condition on each instruction in the block.
The following works too
    ite EQ
    vldmiaeq r0!, {s16-s31}  ; if true
    vldmiane r0!, {s16-s30}  ; if false
 
 
 I also found some useful guidance in the ARM manuals for the Cortex-M series under Cortex-M Instruction set.
Not in CCS asm format, but very instructive.
eg.
   ITTEE  EQ           ; Next 4 instructions are conditional
    MOVEQ  R0, R1       ; Conditional move
    ADDEQ  R2, R2, #10  ; Conditional add
    ANDNE  R3, R3, #1   ; Conditional AND
    BNE.W  dloop        ; Branch instruction can only be used in the last
                        ; instruction of an IT block
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...