zoukankan      html  css  js  c++  java
  • N皇后问题-汇编解法

    传送门

    include irvine32.inc
    .data
    	answer	dd	16 dup(?)
    	cntprt	dd	3
    .code
    
    printInt proc
    	pushad
    	mov	ecx, 0
    	mov	esi, eax
    	cmp	esi, 0
    	je	isZero
    	mov	ebx, 10
    again:
    	mov	edx, 0
    	mov	eax, esi
    	div	ebx
    	mov	esi, eax
    	add	edx, '0'
    	push	edx
    	inc	ecx
    	cmp	esi, 0
    	jg	again
    	jmp	printit
    isZero:
    	mov	edx, '0'
    	push	edx
    	inc	ecx
    printit:
    	pop	eax
    	call	writeChar
    	loop	printit
    final:
    	popad
    	ret
    printInt endp
    
    writeAnswer proc
    	push	ebp
    	mov	ebp, esp
    	pushad
    	
    	mov	ecx, [ebp+16]
    	mov	edx, [ebp+12]
    	cmp	[ebp+8], ecx
    	jne	final
    	cmp	cntprt, 0
    	jle	final
    	
    	mov	esi, 0
    again:
    	mov	eax, [edx+4*esi]
    	inc	eax
    	call	printInt
    	mov	al, ' '
    	call	writeChar
    	inc	esi
    	cmp	esi, ecx
    	jl	again
    	
    	call	crlf
    	dec	cntprt
    final:
    	popad
    	pop	ebp
    	ret	12
    writeAnswer endp
    
    putQueen proc
    	push	ebp
    	mov	ebp, esp
    	push	1
    	pushad
    	; [ebp+28] :	address of answer
    	; [ebp+24] :	the number of q
    	; [ebp+20] :	which line
    	; [ebp+16] :	list State
    	; [ebp+12] : 	main diag State
    	; [ebp+8]  :	vice diag State
    	; [ebp-4]  :	return the number of planning to put q
    	mov	edx, [ebp+28]
    	mov	ebx, [ebp+20]
    	cmp	ebx, [ebp+24]
    	jge	final
    	mov	dword ptr [ebp-4], 0
    	mov	esi, 0
    again:
    	cmp	esi, [ebp+24]
    	jge	final
    	;check list
    	mov	eax, 1
    	mov	ecx, esi
    	shl	eax, cl
    	and	eax, [ebp+16]
    	cmp	eax, 0
    	jne	next
    	;check main diag
    	mov	eax, 1
    	mov	ecx, ebx
    	add	ecx, esi
    	shl	eax, cl
    	and	eax, [ebp+12]
    	cmp	eax, 0
    	jne	next
    	;check vice diag
    	mov	eax, 1
    	mov	ecx, [ebp+24]
    	dec	ecx
    	add	ecx, ebx
    	sub	ecx, esi
    	shl	eax, cl
    	and	eax, [ebp+8]
    	cmp	eax, 0
    	jne	next
    	;all allow
    	mov	[edx+4*ebx], esi
    	push	edx
    	push	[ebp+24]
    	mov	eax, ebx
    	inc	eax
    	push	eax;new line
    	mov	eax, 1
    	mov	ecx, esi
    	shl	eax, cl
    	or	eax, [ebp+16]
    	push	eax;new list state
    	mov	eax, 1
    	mov	ecx, ebx
    	add	ecx, esi
    	shl	eax, cl
    	or	eax, [ebp+12]
    	push	eax;new main diag state
    	mov	eax, 1
    	mov	ecx, [ebp+24]
    	dec	ecx
    	add	ecx, ebx
    	sub	ecx, esi
    	shl	eax, cl
    	or	eax, [ebp+8]
    	push	eax;new vice diag state
    	call	putQueen
    	add	[ebp-4], eax
    next:
    	inc	esi
    	jmp	again
    final:
    	push	[ebp+24]
    	push	edx
    	push	ebx
    	call	writeAnswer
    	popad
    	pop	eax
    	pop	ebp
    	ret	24
    putQueen endp
    
    main proc
    	call	readInt
    	push	offset answer
    	push	eax
    	push	0
    	push	0
    	push	0
    	push	0
    	call	putQueen
    	call	printInt
    	exit
    main endp
    end main
    
  • 相关阅读:
    设计模式(6)--Adapter(适配器模式)--结构型
    设计模式原则(1)--Single Responsibility Principle(SRP)--单一职责原则
    设计模式(5)--Builder(建造模式)--创建型
    设计模式(4)--AbstractFactory(抽象工厂模式)--创建型
    设计模式(3)--SimpleFactory( [1] 简单工厂模式)--创建型
    JS 的map和array集合组合返回JSON字符串
    HTML中直接写js 函数
    设计模式(3)--FactoryMethod( [2] 工厂方法模式)--创建型
    图片剪贴工具类
    远程Get,Post请求工具类
  • 原文地址:https://www.cnblogs.com/JustinRochester/p/14648615.html
Copyright © 2011-2022 走看看