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?

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

0
Posted at

概要

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

参考にしたページ

練習問題

ABC 087 B - Coins
500円玉をA枚、100円玉をB枚、50円玉をC枚持っているとき、これらの硬貨の中から何枚かを選び、合計金額をちょうどX円にする組み合わせを求める問題です。

投入するソース

2
2
2
100

期待値

2

サンプルコード


global main
extern printf, scanf
section .text

main:
	push 	rbp
	mov 	rbp, rsp
	sub 	rsp, 128
	lea 	rdi, [rel fmt4]
	lea 	rsi, [rsp]
	lea 	rdx, [rsp + 8]
	lea 	rcx, [rsp + 16]
	lea 	r8 , [rsp + 24]
	call 	scanf wrt ..plt
	mov 	rax, [rsp]
	mov 	rbx, [rsp + 8]
	mov 	rcx, [rsp + 16]
	mov 	r12, [rsp + 24]
	mov 	edx, [rel a]
	mul 	edx
	mov 	r8, rax
	mov 	rax, rbx
	mov 	edx, [rel b]
	mul 	edx
	mov 	rbx, rax
	mov 	rax, rcx
	mov 	edx, [rel c]
	mul 	edx
	mov 	rcx, rax
	lea 	rdi, [rel fmt1]
	xor 	rsi, rsi
.L1:
	mov 	r9, rbx
.L2:
	mov 	r10, rcx
.L3:
	mov 	r11, r8
	add 	r11, r9
	add 	r11, r10
	cmp 	r11, r12
	jne 	.SK
	inc 	rsi
.SK:
	sub 	r10, 50
	jnc 	.L3
	sub 	r9, 100
	jnc 	.L2
	sub 	r8, 500
	jnc 	.L1
	lea 	rdi, [rel fmt1]
	call 	printf WRT ..plt
	xor 	eax, eax
	mov 	rsp, rbp
	pop 	rbp
	ret

section .data
	fmt4 db "%d%d%d%d\n", 10, 0;
	a dd 500;
	b dd 100;
	c dd 50;
	fmt1 db "%d", 10, 0;





コンパイル、実行結果


# nasm -f elf64 at4.s

# gcc -o at4 at4.o

# ./at4
2
2
2
100
2

以上。

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?