用& t语法减去汇编代码中的“char”

时间:2015-11-15 12:18:03

标签: assembly x86

我正在试图找出一个汇编示例,这是一种语法。代码是查找字符串的小写。在第26和28行,距离是什么意思?我知道''a'这里有类似ascii的东西,但距离是多少?为什么我们不把$ bl与'a'和'z'进行比较,看看它是否是小写的?

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`

1 个答案:

答案 0 :(得分:0)

  

我知道$&#39; a&#39;这是像ascii,但距离是多少?

不是&#34;类似&#34;, 'a'的ASCII代码。这里的距离是指距离a ASCII代码的距离,即从代码中减去代码的距离。代码。

  

为什么我们不把$ bl与&#39; a&#39;和&#39; z&#39;看看它是否小写?

他们已经这样做了:

20   # check to see if in range ’a’-’z’
21   cmpb $’a’, %bl
22   js nextchar
23   cmpb $’z’+1, %bl
24   jge nextchar