0
我试图找出一个汇编示例,它在& t语法。代码是找到字符串的小写字母。在第26和第28行,距离是什么意思?我知道这里的$'a'有点像ascii,但距离是多少?为什么我们不把$ b1与'a'和'z'进行比较以查看它是否是小写?在&t语法中减去汇编代码中的“char”
1 .data
2 x: .string "c92jemc82ne<824j8vcm92jq3.,.u"
3 counts:
4 .rept 26
5 .byte 0
6 .endr
7 .text
8 .globl _start
9 _start:
10 # EAX will always point to the current character to be tallied
11 movl $x, %eax
12 top:
13 # need to zero out all of EBX for later use (see subl)
14 movl $0, %ebx
15 # get the character to be tallied
16 movb (%eax), %bl
17 # check for end of string
18 cmpb $0, %bl
19 jz done
20 # check to see if in range ’a’-’z’
21 cmpb $’a’, %bl
22 js nextchar
23 cmpb $’z’+1, %bl
24 jge nextchar
25 # find distance past counts where we will increment
26 subl $’a’,%ebx
27 # add that distance to counts to get address of place to increment
28 addl $counts, %ebx
29 # now increment
30 incb (%ebx)
31 # OK, ready to go to the next character in the string
32 nextchar:
33 addl $1, %eax
34 jmp top
35 done: movl %edx, %edx`
是的,我知道他们比较$用“a”和“Z” BL,但是为什么我们仍然需要找到的距离? – Wiiiii
因为该代码不仅仅用于查找字符串是否小写。 – m0skit0