本文介绍了比较字符(ARM汇编)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将我的汇编代码中的字符数组中的字符与字符进行比较.
I'm trying to compare a Character from a Char-Array with a char in my assembly code.
这是我用来启动汇编代码的C代码:
This is the C-Code I use to start the assembly code:
char a[] = "abc";
char b = 'a';
int size = 3;
int d = _asm_main(a);
printf("Char a: %s\n",a);
printf("Erg:%d\n",d);
这是汇编代码:
_asm_main:
push {r6,r7,r8,lr}
mov r8,r0
ldr r7,[r8,#2]
mov r6,r7
b compare
compare:
cmp r6,#'c'
beq true
b false
true:
mov r0,#1
b end
false:
mov r0,#2
b end
end:
pop {r6,r7,r8,pc}
BX lr
它适用于'c',但是如果我尝试使用'a'或'b',我总是陷入错误的寓言中.我不明白为什么它对这三个之一有效,而对另外两个无效.
It works for 'c' but if I try it with 'a' or 'b' I always get into the false lable. I don't get why it works for one of the three and not for the other two.
推荐答案
使用ldrb处理ASCII字节和gdb调试器的粗略说明.
A crude illustration using ldrb to deal with the ASCII byte and gdb debugger.
.data
array: .string "abc"
.text
.global _start
_start:
nop
ldr r0,=array
ldrb r1, [r0,#0]
ldrb r2, [r0,#1]
ldrb r3, [r0,#2]
...
gdb:
16 ldr r0,=array
(gdb) si
17 ldrb r1, [r0,#0]
(gdb)
18 ldrb r2, [r0,#1]
(gdb)
19 ldrb r3, [r0,#2]
(gdb)
_exit () at stuff.s:25
25 mov r7, #1
(gdb) i r
r0 0x20094 131220
r1 0x61 97
r2 0x62 98
r3 0x63 99
这篇关于比较字符(ARM汇编)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!