1
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 その2

1
Posted at

概要

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

練習問題

ABC 081 A - Placing Marbles
文字列を受け取り、1の個数をカウントする問題です。

投入するソース

111

期待値

3

サンプルコード

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
	fmti		db "%s", 0
	fmto		db "%d", 10, 0

section '.bss' data readable writeable
	buff	rq 64

section '.text' code readable executable
start:
	sub 	rsp, 32
	cinvoke scanf, fmti, buff
	lea 	r13, [buff]
	xor 	rbx, rbx
count_loop:
	mov 	al, [r13]
	test 	al, al
	jz 		print_result
	cmp 	al, '1'
	jne 	next_char
	inc 	rbx
next_char:
	inc 	r13
	jmp 	count_loop
print_result:
	cinvoke printf, fmto, rbx
	cinvoke ExitProcess, 0




実行結果

>set PATH=C:\Program Files (x86)\fasmw17334;%PATH%

>fasm atcoder2.asm
flat assembler  version 1.73.34  (1048576 kilobytes memory)
4 passes, 4.5 seconds, 2560 bytes.

>atcoder2
111
3

以上。

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