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?

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

0
Posted at

概要

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

参考にしたページ

練習問題

ABC 085 C - Otoshidama
10000円札と、5000円札と、1000円札が合計でN枚あって、合計金額がY円であった。このような条件を満たす各金額の札の枚数の組を1つ求める問題です。

投入するソース

9 45000

期待値

4 0 5 または 0 9 0

サンプルコード


global main
extern printf, scanf
section .text

main:
	push 	rbp
	mov 	rbp, rsp
	sub 	rsp, 128
	lea 	rdi, [rel fmti]
	lea 	rsi, [rsp]
	lea 	rdx, [rsp + 8]
	call 	scanf wrt ..plt
	mov 	r12, [rsp]
	mov 	r13, [rsp + 8]
	lea 	rdi, [rel fmto]
	mov 	r8, r12
loop1:
	mov 	rax, [rel a]
	mul 	r8
	mov 	rbx, rax
	mov 	r9, r12
	sub 	r9, r8
loop2:
	mov 	rax, [rel b]
	mul 	r9
	mov 	rcx, rax
	mov 	r10, r12
	sub 	r10, r8
	sub 	r10, r9
	mov 	rax, [rel c]
	mul 	r10
	add 	rax, rbx
	add 	rax, rcx
	cmp 	rax, r13
	jne 	next
	mov 	rsi, r8
	mov 	rdx, r9
	mov 	rcx, r10
	call 	printf WRT ..plt
	xor 	eax, eax
	mov 	rsp, rbp
	pop 	rbp
	ret
next:
	dec 	r9
	jns 	loop2
	dec 	r8
	jns 	loop1
	mov 	rsi, -1
	mov 	rdx, -1
	mov 	rcx, -1
	call 	printf WRT ..plt
	xor 	eax, eax
	mov 	rsp, rbp
	pop 	rbp
	ret

section .data
	fmti db "%lld%lld\n", 10, 0;
	fmto db "%lld %lld %lld", 10, 0;
	a dq 10000;
	b dq 5000;
	c dq 1000;





コンパイル、実行結果


# nasm -f elf64 at8.s

# gcc -o at8 at8.o

# ./at8
9 45000
4 0 5

以上。

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?