0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

中古ノート、買ってみた。 その119

0
Posted at

概要

中古ノート買ってみた。
wsl1のubuntu18.04にnasm入れてみた。
練習問題、やってみた。

練習問題

ABC 088 B - Card Game for Two
N枚のカードを二人で交互に取っていき、カードに書かれている数字の和の差を求める問題。

投入するソース

2
3 1

期待値

2

実行結果

# gcc -o at6v at6v.s -no-pie

# ./at6v
4
20 18 2 18
18

# ./at6v
2
3 1
2

# ./at6v
3
2 7 4
5

サンプルコード


.intel_syntax noprefix
.global main
.text

main:
	push	rbp
	mov 	rbp, rsp

_start:
	lea 	rdi, fmti[rip]
	lea 	rsi, buf[rip]
	call	scanf
	mov 	r15, [buf]
	mov 	r13, [buf]
	lea 	r14, ari[rip]
_input:
	lea 	rdi, fmti[rip]
	lea 	rsi, buf[rip]
	call	scanf
	mov 	rax, [buf]
	mov 	[r14], rax
	add 	r14, 4
	dec 	r13
	jnz 	_input

_sort:
	mov 	r14, 0  #i
_loop4:
	mov 	r13, 0  #j
_loop3:
	lea 	r12, ari[rip]
	mov 	rax, 0
	mov 	eax, 4
	mul 	r13d
	add 	rax, r12
	mov 	r11, rax
	add 	rax, 4
	mov 	r10, rax
_if:
	mov 	ebx, dword ptr [r11]
	mov 	ecx, dword ptr [r10]
	cmp 	ebx, ecx
	jge 	_pass
	mov 	dword ptr [r11], ecx
	mov 	dword ptr [r10], ebx
_pass:
	inc 	r13			#j
	mov 	rax, r15
	dec 	rax
	sub 	rax, r14
	cmp 	rax, r13
	jne 	_loop3
	inc 	r14			#i
	mov 	rax, r15
	dec 	rax
	cmp 	rax, r14
	jne 	_loop4

_solv:
	mov 	rbx, 0
	mov 	r13, 0
	lea 	r14, ari[rip]
_loop:
	mov 	rcx, [r14]
	mov 	rdx, 0
	mov 	rax, r13
	mov 	r12, 2
	div 	r12
	cmp 	rdx, 1
	jz  	_pass2
	add 	rbx, rcx
	jmp 	_next
_pass2:
	sub 	rbx, rcx
_next:
	add 	r14, 4
	inc 	r13
	cmp 	r13, r15
	jnz 	_loop

_disp:
	lea 	rdi, fmto[rip]
	mov 	rsi, rbx
	call	printf

_end:
	xor 	eax, eax
	mov 	rsp, rbp
	pop 	rbp
	ret

.data
	fmti:	.string "%d"
	fmto:	.string "%d\n"
	fmts:	.string "%d  "
	fmtd:	.string "%d %d\n"

.bss
	.comm	buf, 10
	.comm	ari, 40





以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?