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?

アセンブラfasmでatcoder その4

0
Posted at

概要

アセンブラfasmで、atcoder、やってみた。

練習問題

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

投入するソース

2
2
2
100

期待値

2

サンプルコード


format PE64 console
entry start
include 'C:\Program Files (x86)\fasmw17334\INCLUDE\win64a.inc'

section '.idata' import data readable writeable
	library kernel32, 'kernel32.dll', msvcrt, 'MSVCRT.DLL'
	import kernel32, ExitProcess, 'ExitProcess'
	import msvcrt, printf, 'printf', scanf, 'scanf'

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

section '.bss' data readable writeable
	VA		dd  ?
	VB		dd  ?
	VC		dd  ?
	VD		dd  ?

section '.text' code readable executable
start:
	sub 	rsp, 32
	cinvoke scanf, fmt4, addr VA, addr VB, addr VC, addr VD
	mov 	eax, [VA]
	mov 	ebx, [VB]
	mov 	ecx, [VC]
	mov 	r12d, [VD]
	mov 	edx, [a]
	mul 	edx
	mov 	r8d, eax
	mov 	eax, ebx
	mov 	edx, [b]
	mul 	edx
	mov 	ebx, eax
	mov 	eax, ecx
	mov 	edx, [c]
	mul 	edx
	mov 	ecx, eax
	xor 	rsi, rsi
_L1:
	mov 	r9d, ebx
_L2:
	mov 	r10d, ecx
_L3:
	mov 	r11d, r8d
	add 	r11d, r9d
	add 	r11d, r10d
	cmp 	r11d, r12d
	jne 	_SK
	inc 	rsi
_SK:
	sub 	r10d, 50
	jnc 	_L3
	sub 	r9d, 100
	jnc 	_L2
	sub 	r8d, 500
	jnc 	_L1
	cinvoke printf, fmt, rsi
	cinvoke ExitProcess, 0




実行結果

>atcoder4
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?