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?

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

0
Posted at

概要

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

練習問題

ABC 085 B - Kagami Mochi
N枚の整数値が与えられ、それらの重複しない要素の数を数える問題です。

投入するソース

4
10 8 8 6

期待値

3

実行結果

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

# ./at7v
4
10 8 8 6
3

# ./at7v
3
15 15 15
1

# ./at7v
7
50 30 50 100 50 80 30
4

サンプルコード


.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
_loop4:
	mov 	r13, 0
_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
	mov 	rax, r15
	dec 	rax
	sub 	rax, r14
	cmp 	rax, r13
	jne 	_loop3
	inc 	r14
	mov 	rax, r15
	dec 	rax
	cmp 	rax, r14
	jne 	_loop4

_solv:
	mov 	rax, r15
	mov 	r11, r15
	dec 	r11
	mov 	r13, 0
	lea 	r14, ari[rip]
_loop:
	mov 	r10, r14
	add 	r10, 4
	mov 	ecx, dword ptr [r14]
	mov 	ebx, dword ptr [r10]
	cmp 	ecx, ebx
	jnz 	_next
	dec 	rax
_next:
	add 	r14, 4
	inc 	r13
	cmp 	r13, r11
	jnz 	_loop

_disp:
	lea 	rdi, fmto[rip]
	mov 	rsi, rax
	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?