32位汇编输出全排列

INCLUDE Irvine32.inc
.data
    arr dd 120 dup(?)
    ; arr dd 1,2,3,4,5,6,7,8,9,10
.code
main PROC
    ; call readInt
    ; mov edx,eax
    mov eax,4
    push eax ;eax:count
    mov edx,offset arr ;edx:arr
    push edx
    call Assign

    ; mov edx,offset arr 
    ; push edx ;edx:arr
    ; ; mov eax,edx
    ; push eax ;eax:count
    ; call output

    mov ecx,0
    push eax
    push ecx
    push edx
    call FullPermutation
    exit
main ENDP

FullPermutation PROC
    push ebp
    mov ebp,esp
    pushad
    mov edx,[ebp+8] ;edx:arr
    mov esi,[ebp+12] ;esi:begin
    mov edi,[ebp+16] ;edi:end
    mov ecx,0

    cmp esi,edi
    jl else1
again:
    cmp ecx,edi
    jge final
    mov eax,[edx+ecx*4]
    call writedec
    inc ecx
    jmp again

else1:
    mov ecx,esi
again1:
    cmp ecx,edi ;ecx:i
    jge final

    cmp esi,ecx
    je next1

    push dword ptr [edx+esi*4]
    push dword ptr [edx+ecx*4]
    pop dword ptr [edx+esi*4]
    pop dword ptr [edx+ecx*4]
next1:
    push edi
    mov eax,esi
    inc eax
    push eax
    push edx
    call FullPermutation
    
    cmp esi,ecx
    je next2
    push dword ptr [edx+esi*4]
    push dword ptr [edx+ecx*4]
    pop dword ptr [edx+esi*4]
    pop dword ptr [edx+ecx*4]

next2:
    inc ecx
    jmp again1
final:
    call crlf
    popad
    pop ebp
    ret 12
FullPermutation ENDP

Assign PROC
    push ebp
    mov ebp,esp
    pushad
    mov ecx,[ebp+12] ;ecx:count
    mov edx,[ebp+8] ;edx:arr
    mov edi,0
again:
    cmp edi,ecx
    jge final
    mov eax,edi
    inc eax
    mov [edx+edi*4],eax
    inc edi
    jmp again
final:
    popad
    pop ebp
    ret 8
Assign ENDP

output PROC
    push ebp
    mov ebp,esp
    pushad
    mov edx,[ebp+12]; edx:arr
    mov ecx,[ebp+8]; ecx:count
    mov ebx,0
next:
    cmp ebx,ecx
    jge final
    mov eax,[edx+ebx*4]
    ; mov eax,ebx
    call writeint
    inc ebx
    jmp next
final:
    popad
    ret 8
output ENDP
END main

  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值