简体   繁体   English

如何运行单行程序集,然后查看[R1]和条件标志

[英]How to run a single line of assembly, then see [R1] and condition flags

I'm trying to teach myself assembly. 我正在努力教自己装配。 I've got years and year of experience with C, Java and Python- but I cant make ANY headway here and I'm about to give up. 我有多年和一年的C,Java和Python经验 - 但我不能在这里取得任何进展,我即将放弃。

So, I downloaded uVision4, and assumed I could just write a basic assembly program: 所以,我下载了uVision4,并假设我可以编写一个基本的汇编程序:

MOV R1,  #0x7F0E0C2D
MOV R3,  #0x1048B3C5
ADCS  R1, R3, ROR #0x18
END

So, establish two variables, do an operation, done. 所以,建立两个变量,做一个操作,完成。 Check the Registers for output and debugger for condition flags, surely. 当然,检查寄存器的输出和调试器是否有条件标志。

Apparently, this is impossible. 显然,这是不可能的。

I create the text file, write my code, save as a .asm file, then try to build- 我创建文本文件,编写我的代码,保存为.asm文件,然后尝试构建 -

It hates that. 它讨厌这个。

Okay, so I create a new project, add the .asm file, 好的,所以我创建了一个新项目,添加.asm文件,

And it refuses, demanding I apparently write an entire device driver to do a god damn hello world. 它拒绝,要求我显然写了一个完整的设备驱动程序来做一个该死的你好世界。

How can I run a simple couple lines of code to start learning? 如何运行简单的几行代码才能开始学习?

I do stuff like this all the time on my x86 desktop, using gdb to single-step code. 我一直在x86桌面上做这样的事情,使用gdb来执行单步代码。 Usually with x86 instructions, but it's doable for ARM cross-development, too. 通常使用x86指令,但它也适用于ARM交叉开发。 Build with gcc -nostdlib foo.S , and it should set the default entry point to the beginning of your .text section. 使用gcc -nostdlib foo.S构建,它应该将默认入口点设置为.text部分的开头。 You do get a warning from the linker, though: 但是,您确实会从链接器收到警告:

$ arm-linux-gnueabi-gcc -nostdlib arm-simple.S 
/usr/lib/gcc-cross/arm-linux-gnueabi/5/../../../../arm-linux-gnueabi/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000010098

I had to modify your source for it to assemble. 我不得不修改你的源码来组装。 Here's my arm-simple.S: 这是我的手臂简单。:

.globl _start                                                                                                                                                       
_start:                        @ make debugging easier to have a symbol name                                                                                        

ldr   R1,  =#0x7F0E0C2D       @ ARM immediate constants can't be arbitrary 32-bit values.  Use the ldr reg, =value pseudo-op, which in this case assembles to a PC-relative load from a nearby literal pool.  Often it can use mov reg, #imm or movn reg, #imm
ldr   R3,  =#0x1048B3C5
ADCS  R1, R3, ROR #0x18

@END  This isn't an instruction.

Then you can use gdb and set a breakpoint at the first instruction, run it, and single step. 然后你可以使用gdb并在第一条指令处设置断点,运行它,然后单步执行。

You can even do this in a cross-development environment, with a few wrinkles. 您甚至可以在交叉开发环境中执行此操作,只需要一些皱纹。


In one terminal, run QEMU on your binary, waiting for a debugger connection : 在一个终端中, 在二进制文件上运行QEMU,等待调试器连接

$ arm-linux-gnueabi-gcc -g -nostdlib arm-simple.S
$ qemu-arm -g 12345 ./a.out                    # user-mode emulation, waiting for gdb to connect

Use -mcpu=something for gcc, and -cpu model for qemu if you want to be specific. 如果你想要特定的话,使用-mcpu=something gcc的-mcpu=something和qemu的-cpu model


In another terminal, run ARM gdb (in my case, from Ubuntu's gdb-arm-none-eabi package, since they Ubuntu doesn't distribute a arm-linux-gnueabi-gdb cross-ARM-gdb package for x86). 在另一个终端中,运行ARM gdb (在我的例子中,来自Ubuntu的gdb-arm-none-eabi包,因为它们Ubuntu不为x86分发arm-linux-gnueabi-gdb跨ARM-gdb包)。

TODO: try gdb-multiarch. TODO:尝试gdb-multiarch。 Regular gdb on an x86 desktop can only debug x86 binaries, so you definitely can't use that. x86桌面上的常规gdb只能调试x86二进制文件,所以你绝对不能使用它。

$ arm-none-eabi-gdb ./a.out          # give the gdb client the same binary to read symbols / debug info
(gdb) target remote localhost:12345
(gdb) layout asm
(gdb) layout reg
(gdb) si               # single step by instruction, not source line
(gdb) si

Then gdb shows: 然后gdb显示:

+--Register group: general-----------------------------------------------------------------------------------------------------------------------------------------+
|r0             0x0      0                             r1             0x7f0e0c2d       2131627053            r2             0x0      0                             |
|r3             0x1048b3c5       273200069             r4             0x0      0                             r5             0x0      0                             |
|r6             0x0      0                             r7             0x0      0                             r8             0x0      0                             |
|r9             0x0      0                             r10            0x100ac  65708                         r11            0x0      0                             |
|r12            0x0      0                             sp             0xf6ffea40       0xf6ffea40            lr             0x0      0                             |
|pc             0x100a0  0x100a0 <_start+8>            cpsr           0x10     16                                                                                  |
|                                                                                                                                                                  |
|                                                                                                                                                                  |
|                                                                                                                                                                  |
|                                                                                                                                                                  |
|                                                                                                                                                                  |
|                                                                                                                                                                  |
|                                                                                                                                                                  |
|                                                                                                                                                                  |
|                                                                                                                                                                  |
   ----------------------------------------------------------------------------------------------------------------------------------------------------------------+
   |0x10098 <_start>        ldr    r1, [pc, #4]    ; 0x100a4 <_start+12>                                                                                           |
   |0x1009c <_start+4>      ldr    r3, [pc, #4]    ; 0x100a8 <_start+16>                                                                                           |
  >|0x100a0 <_start+8>      adcs   r1, r1, r3, ror #24                                                                                                             |
   |0x100a4 <_start+12>     svcvc  0x000e0c2d                                                                                                                      |
   |0x100a8 <_start+16>     subne  r11, r8, r5, asr #7                                                                                                             |
   |0x100ac                 andeq  r1, r0, r1, asr #18                                                                                                             |
   |0x100b0                 cmnvs  r5, r0, lsl #2                                                                                                                  |
   |0x100b4                 tsteq  r0, r2, ror #18                                                                                                                 |
   |0x100b8                 andeq  r0, r0, pc                                                                                                                      |
   |0x100bc                 subseq r3, r4, r5, lsl #10                                                                                                             |
   |0x100c0                 tsteq  r8, r6, lsl #6                                                                                                                  |
   |0x100c4                 andeq  r0, r0, r9, lsl #2                                                                                                              |
   |0x100c8                 andeq  r0, r0, r12, lsl r0                                                                                                             |
   |0x100cc                 andeq  r0, r0, r2                                                                                                                      |
   |0x100d0                 andeq  r0, r4, r0                                                                                                                      |
   +---------------------------------------------------------------------------------------------------------------------------------------------------------------+
remote Remote target In: _start                                                                                                              Line: 6    PC: 0x100a0 
(gdb) si

It highlights the last register(s) modified, which is pretty great. 它突出显示了最后修改的寄存器,这非常棒。

It seems to be too old to decode flags symbolically, though. 但是,象征性地解码标志似乎太旧了。 modern x86 gdb does that. 现代的x86 gdb做到了。

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

相关问题 使用程序集(Keil)比较R0与R1 - Comparing R0 with R1 using assembly (Keil) 如何处理:选定的处理器不支持`qadd16 r1,r1,r0&#39; - How to deal with this : selected processor does not support `qadd16 r1,r1,r0' 可能要合并r1,r1吗? - Possible to mul r1,r1? kdbg程序集,如何显示标志? - kdbg assembly, how to display flags? 16位Thumb-2汇编指令集中的“更新条件标志” S如何编码? - How is the “update condition flags” S encoded in the 16-bit Thumb-2 assembly instruction set? 为什么我的汇编程序没有将r1设置为正确的值? - Why isn't my assembly program setting r1 to the correct value? 如何为8086手动更改标志(在汇编代码中)? - how to change flags manually (in assembly code) for 8086? 为什么我在sample.bin文件中写道,为什么我在LC-3仿真器中看到R3寄存器而不是R1? - Why do I see R3 register in the LC-3 simulator instead of R1, as I wrote in a sample.bin file? 怎么 ”!” Armv6-M 架构编码中“LDM R1!{R2}”指令的一部分? - How is "!" part of "LDM R1! {R2}" instruction in Armv6-M Architecture Encoded? 汇编语言新手并出现错误:“add.s:7: Error: shift expression expected — `adds R0,R1,R2,R3'” - New to assembly language and having the error: “add.s:7: Error: shift expression expected — `adds R0,R1,R2,R3'”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM