带旋转臂指令的 MVN

MVN with rotate arm instruction

这是考试中出现的问题,但我无法理解它的解决方案。

A​​RM 指令是 MVN R7, #0x8C, 4 我必须找到存储在 R7 中的值。

解决方法如下:

= 0x8C ROR 4

= (0000 0000 0000 0000 0000 0000 1000 1100)2 ROR 4

= (1100 0000 0000 0000 0000 0000 0000 1000)2

= 0xC0000008

我觉得这不对,因为 MVN 涉及求补,而上述步骤看起来像是简单的 MOV 操作。即使不正确,正确的答案应该是什么?倒数第二步的补语?

感谢任何帮助。谢谢!

当然可以...

startup.s:

.globl _start
_start:
    mov sp,#0x20000
    bl notmain
hang: b hang

.globl PUT32
PUT32:
    str r1,[r0]
    bx lr

.globl GET32
GET32:
    ldr r0,[r0]
    bx lr

.globl TEST
TEST:
    MVN R0,#0x8C,4
    bx lr

hello.c

void PUT32 ( unsigned int, unsigned int );
unsigned int GET32 ( unsigned int );
unsigned int TEST ( void );
static void uart_putc ( unsigned int x )
{
    PUT32(0x101f1000,x);
}
static void bitstring ( unsigned int d )
{
    unsigned int ra;

    for(ra=0;ra<32;ra++)
    {
        if(d&0x80000000) uart_putc(0x31);
        else             uart_putc(0x30);
        d<<=1;
    }
    uart_putc(0x0D);
    uart_putc(0x0A);
}
int notmain ( void )
{
    bitstring(0x12345678);
    bitstring(TEST());
    return(0);
}

内存映射:

MEMORY
{
    rom  : ORIGIN = 0x00010000, LENGTH = 32K
}

SECTIONS
{
   .text : { *(.text*) } > rom
}

生成文件:

CROSS_COMPILE ?= arm-linux-gnueabi

AOPS = --warn --fatal-warnings 
COPS = -Wall -Werror -O2 -nostdlib -nostartfiles -ffreestanding 

hello_world.bin : startup.o hello.o memmap
    $(CROSS_COMPILE)-ld startup.o hello.o -T memmap -o hello_world.elf
    $(CROSS_COMPILE)-objdump -D hello_world.elf > hello_world.list
    $(CROSS_COMPILE)-objcopy hello_world.elf -O binary hello_world.bin

startup.o : startup.s
    $(CROSS_COMPILE)-as $(AOPS) startup.s -o startup.o

hello.o : hello.c 
    $(CROSS_COMPILE)-gcc -c $(COPS) hello.c -o hello.o

clean :
    rm -f *.o
    rm -f *.elf
    rm -f *.bin
    rm -f *.list

然后

apt-get install qemu-system-arm binutils-arm-linux-gnueabi gcc-arm-linux-gnueabi
make
qemu-system-arm -M versatilepb -m 128M -kernel hello_world.bin

然后按 ctrl-alt-3(3 而不是 F3)以获取串行控制台。你会在哪里看到你的答案...

并关闭该控制台 window 将退出 qemu。

或者如果你有 raspberry pi 或 beaglebone 或 C.H.I.P 或许多其他板 运行ning linux 或 linux 在 qemu 或其他任何地方。

test.s

.globl TEST
TEST:
    MVN R0,#0x8C,4
    bx lr

main.c

#include <stdio.h>
extern unsigned int TEST ( void );
int main ( void )
{
    printf("0x%08X\n",TEST());
    return(0);
}

然后

as test.s -o test.o
gcc main.c test.o -o main.elf
./main.elf

裸机路线在这些平台上非常简单。只需要实际初始化 uart,并等待 rx 缓冲区为空,不能像在模拟器中那样作弊。

不幸的是,您不能在微控制器上执行此操作,因为现在大多数都是基于 cortex-m 的

.thumb
.thumb_func
.globl TEST
TEST:
    MVN R0,#0x8C,4
    bx lr

那行不通

test.s: Assembler messages:
test.s:6: Error: unshifted register required -- `mvn R0,#0x8C,4'

如果你有一个基于 ARM7TDMI 的微控制器(或其他非 cortex-m)并且有 jtag,或者即使上面有 jtag 你只需要给它一个指令。 (也可以使用 gdb,即使使用 qemu)将一条指令送入某处的内存

   1001c:   e3e0028c    mvn r0, #140, 4 ; 0xc0000008

所以 0xe3e0028c 是该指令的 r0 版本。逐步执行它,然后转储寄存器,您也可以看到您的答案。

你知道 gdb 实际上有或应该有内置或可用的 armulator,所以你可能只需要它。

整个程序:

.globl _start
_start:
    MVN R0,#0x8C,4
    b .

然后 arm-linux-gnueabi-ld test.s -o test.o arm-linux-gnueabi-ld -Ttext=0x8000 test.o -o test.elf

并获取 gdb

apt-get install gdb-arm-linux-gnueabi

然后弄清楚如何使用 armulator 在 gdb 中加载和 运行 它,然后停止它并转储寄存器。

编辑

感谢这个问题,我学到了一些东西...链接不好,还有其他预构建的工具链,但在撰写本文时这里有一个

https://launchpad.net/gcc-arm-embedded

然后获取visualboyadvance。 windows mac linux.

支持这些

写这个test.s程序

.globl _start
_start:
    MVN R0,#0x8C,4
    b .

使用该工具链

arm-none-eabi-as test.s -o test.o
arm-none-eabi-ld -Ttext=0x02000000 test.o -o test.elf
arm-none-eabi-objcopy test.elf -O binary  test.mb

一个window

vba -Gtcp test.mb

另一个

arm-none-eabi-gdb

在 gdp 提示符下输入这三个命令

target remote localhost:55555
si
info registers

然后你可以用quit退出,它也会退出vba,或者对我来说...