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?

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

0
Last updated at Posted at 2025-11-09

概要

中古ノート買ってみた。
wsl1のubuntu18.04にnasm入れてみた。
アセンブラで、atcoder、見つけたので、やってみた。

参考にしたページ

練習問題

ABC 086 C - Traveling
時刻0のとき、平面上の(0, 0)にいます。平面上のN箇所の点を、ある時刻に移動できるかという問題です。

投入するソース

2
3 1 2
6 1 1

期待値

Yes

サンプルコード


global main
extern printf, scanf
section .text

main:
	push 	rbp
	mov 	rbp, rsp
	sub 	rsp, 32
	lea 	rdi, [rel fmt1]
	lea 	rsi, [rsp]
	call 	scanf WRT ..plt
	mov 	rbx, [rsp]
	xor 	r12, r12
	xor 	r13, r13
	xor 	r14, r14
.loop:
	lea 	rdi, [rel fmt3]
	lea 	rsi, [rsp]
	lea 	rdx, [rsp + 8]
	lea 	rcx, [rsp + 16]
	call 	scanf WRT ..plt
	mov 	r8, [rsp]
	mov 	r9, [rsp + 8]
	mov 	r10, [rsp + 16]
	mov 	rax, r9
	sub 	rax, r13
	mov 	r13, r9
	mov 	rdx, rax
	sar 	rdx, 63
	xor 	rax, rdx
	sub 	rax, rdx
	mov 	rcx, r10
	sub 	rcx, r14
	mov 	r14, r10
	mov 	rdx, rcx
	sar 	rdx, 63
	xor 	rcx, rdx
	sub 	rcx, rdx
	add 	rax, rcx
	mov 	rdx, r8
	sub 	rdx, r12
	mov 	r12, r8
	cmp 	rax, rdx
	jg 		.out
	xor 	rax, rdx
	test 	rax, 1
	jz 		.safe
.out:
	lea 	rdi, [rel No]
	call 	printf WRT ..plt
	xor 	eax, eax
	mov 	rsp, rbp
	pop 	rbp
	ret
.safe:
	dec 	rbx
	jnz 	.loop
	lea 	rdi, [rel Yes]
	call 	printf WRT ..plt
	xor 	eax, eax
	mov 	rsp, rbp
	pop 	rbp
	ret

section .data
	fmt1 db "%lld\n", 0;
	fmt3 db "%lld%lld%lld\n", 0;
	Yes  db "Yes", 0;
	No   db "No", 0;





コンパイル、実行結果


# nasm -f elf64 at10.s

# gcc -o at10 at10.o

# ./at10
2
3 1 2
6 1 1
Yes

以上。

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?