[英]Andl with a parameter in x86 assembly
pushl %ebp
movl %esp, %ebp
subl $36, %esp // allocate 36 bytes for local vars
movl 8(%ebp), %eax // eax = n
andl $1, %eax // how can u andl a parameter? parameter can be greater than 1
testl %eax, %eax
jmp .L4
cmpl $2, 8(%ebp)
jne .L6
.L4:
movl 8(%ebp), %eax //eax = n
movl %eax, -28(%ebp) //x = eax
movl $1431655766, -32(%ebp) //y = 1431655766
movl -32(%ebp), %eax //eax = y
imull -28(%ebp) //edx = x * eax
movl %edx, %ecx //ecx = edx
movl -28(%ebp), %eax //eax = x
sarl $31, %eax //eax = eax >> 31
movl %ecx, %edx //edx = ecx
subl %eax, %edx //edx = edx - eax
movl %edx, -24(%ebp) //z = edx
movl -24(%ebp), %eax //eax = z
addl %eax, %eax //eax = eax+eax
addl -24(%ebp), %eax //eax = z+eax
movl -28(%ebp), %ecx //ecx = x
subl %eax, %ecx //ecx = ecx-eax
movl %ecx, -24(%ebp) //z = ecx
cmpl $0, -24(%ebp) //compare z and 0
jne .L7 //if not equal jmp to .L7
cmpl $3, 8(%ebp) //compare n and 3
jne .L6 //if not equal jmp .L6
好的,我有這個匯編代碼片段,我想知道如何將andl
$ 1和一個參數設置為大於1的參數。此外, testl
似乎毫無用處,因為jmp
跳轉。 有什么想法嗎?
編輯:我已經更新了代碼,不確定是否所有代碼都正確。 對不imull -28(%ebp)
非常困惑
$1
常數(數字)的縮寫形式,不帶前導零。 在32位環境(%eax!)中,它等效於0x00000001
並且意味着:將除最右邊的所有位都設置為零,使最右邊的位保持不變。 在這里,它可能用於隔離布爾值(0 =假或1 =真)或確定奇數(0 =偶數,1 =奇數)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.