简体   繁体   English

ARMv7-M组件ITEE的用法

[英]ARMv7-M assembly ITEE usage

  • Problem: 问题:

I'm trying to get the ITEE EQ ie 'If-Then-Else-Else Equal' block to work when R6==0, with THEN branching into the END label but the assembler called out an error on the line: BEQ END 我正在尝试让ITEE EQ即'If-Then-Else-Else Equal'块在R6 == 0时工作, 然后THEN分支到END标签,但汇编器在行上发出错误BEQ END

  • Program info: 计划信息:

I'm doing a program that is in pertinence with Optimization. 我正在做一个与优化有关的程序。 I'm using a Gradient Descent to converge to the point where gradient is 0 to find the solution x* that minimises some function f(x). 我正在使用“梯度下降”收敛到梯度为0的点,以找到使某些函数f(x)最小化的解决方案x *。 I'm using C language to call an assembly function which is this program here. 我正在使用C语言来调用汇编程序,该程序就是这里的程序。

Here is my program where the error is: 这是我的程序错误所在:

        CMP R6, #0          @ Compare f'(x) with 0
        ITEE EQ             @ If R6 == 0, Then-Else-Else
        BEQ END             @ Calls END label if equal
        SUBNE R0, R6        @ Change R0(x) in the opp direction of gradient to get lower value of f(x) if not equal
        BNE optimize        @ Branch to optimize if not equal

This is my first assembly program using the NXP LPC1769 for a school assignment. 这是我使用恩智浦LPC1769进行学校作业的第一个汇编程序。 Do let me know what I'm missing or I have done wrong. 让我知道我缺少什么或做错了。 Thank you! 谢谢!

Here is my whole program: 这是我的整个程序:

.syntax unified
.cpu cortex-m3
.thumb
.align 2
.global optimize
.thumb_func

optimize:
@  Write optimization function in assembly language here

        MOV R5, INLAMBDA    @ R5 holds value of inverse lambda(10) ie to eliminate floating point
        LDR R6, #2          @ Load R6 with value '2' ie constant of f'(x)
        MUL R6, R1, R6      @ Multiply R6(2) with R1(a) & store to R6(results)
        MLA R6, R6, R0, R2  @ Multiply R6(results) with R0(x) & sum with R2(b) to get f'(x). Store & update results to R6
        SDIV R6, R5         @ Divide R6(results) by R5(1/lambda) to get f'(x) * lambda

        CMP R6, #0          @ Compare f'(x) with 0
        ITEE EQ             @ If R6 == 0, Then-Else-Else
        BEQ END             @ Calls END label if equal
        SUBNE R0, R6        @ Change R0(x) in the opp direction of gradient to get lower value of f(x) if not equal
        BNE optimize        @ Branch to optimize if not equal

@  End label
END:

BX LR

@ Define constant values
CONST: .word 123
INLAMBDA: .word 10      @ Inverse lambda 1 / lambda(0.1) is 10

The problem is that BEQ END is in the middle of the IT block. 问题在于BEQ END位于IT块的中间 To quote some documentation for IT : 引用一些IT文档

A branch or any instruction that modifies the PC is only permitted in an IT block if it is the last instruction in the block. 仅当IT块中的分支或任何指令是该块中的最后一条指令时,才允许该分支或任何修改PC的指令。

That said, because it's a branch, the "else" is implicit anyway - if you take the branch, you won't be executing the following instructions on account of being elsewhere, and if you don't take it you've got no choice but to execute them, so there's no need for them to be explicitly conditional at all. 就是说, 因为它是一个分支,所以“ else”仍然是隐式的-如果您选择分支,则不会因为在其他地方而执行以下指令,并且如果您不使用它,则说明没有选择而是执行它们,因此根本不需要将它们明确地作为条件。 In fact, you don't even need the IT either, since B<cond> has a proper Thumb instruction encoding in its own right. 实际上,您甚至都不需要IT ,因为B<cond>本身具有正确的Thumb指令编码。 But then you also don't even need that , because you're doing a short forward branch based on a register being zero, and there's a specific Thumb-only compare-and-branch instruction for doing exactly that! 但是然后您甚至根本不需要 ,因为您正在基于寄存器为零的状态下进行短前向转移,并且有一条专门的Thumb-only比较和分支指令可以做到这一点!

In other words, your initial 5-line snippet can be expressed simply as: 换句话说,您最初的5行代码段可以简单表示为:

CBZ R6, END
SUB R0, R6
B optimize 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM