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