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?

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

0
Posted at

概要

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

参考にしたページ

練習問題

ABC 081 B - Shift Only
N個の整数値を受け取り、一度の操作ですべての数を2で割る。割り切れなくなるまで割っていった時、何回割ることが出来るか?

投入するソース

3
8 12 40

期待値

2

サンプルコード


global main
extern printf, scanf
section .text

main:
	push 	rbp
	lea 	rdi, [rel fmt]
	lea 	rsi, [rsp]
	call 	scanf wrt ..plt
	xor 	rbx, rbx
	mov 	r13, [rsp]
loop:
	lea 	rdi, [rel fmto]
	lea 	rsi, [rsp]
	call 	scanf wrt ..plt
	mov 	rax, [rsp]
	or 		rbx, rax
	dec 	r13
	cmp 	r13, 0
	jz 		loop
	lea 	rdi, [rel fmto]
	tzcnt 	rsi, rbx
	sub 	rsi, 1
	call 	printf wrt ..plt
	xor 	eax, eax
	pop 	rbp
	ret

section .data
	fmt db "%d\n", 10, 0;
	fmto db "%d", 10, 0;





コンパイル、実行結果


# nasm -f elf64 at3.s

# gcc -o at3 at3.o

# ./at3
3
8 16 40
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?