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?

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

0
Posted at

概要

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

参考にしたページ

練習問題

ABC 083 B - Some Sums
1以上N以下の整数のうち、10進法での各桁の和がA以上B以下であるものの総和を求める問題です。

投入するソース

20 2 5

期待値

84

サンプルコード


global main
extern printf, scanf
section .text

main:
	push 	rbp
	mov 	rbp, rsp
	sub 	rsp, 32
	lea 	rdi, [rel fmt3]
	lea 	rsi, [rsp]
	lea 	rdx, [rsp + 8]
	lea 	rcx, [rsp + 16]
	call 	scanf wrt ..plt
	mov 	r8, [rsp]
	mov 	rbx, [rsp + 8]
	mov 	rcx, [rsp + 16]
	xor		r12, r12
loop:
	mov 	rax, r8
	xor 	r9, r9
	mov 	r11, 10
dig:
	xor 	rdx, rdx
	div 	r11
	add 	r9, rdx
	cmp 	rax, 0
	jne 	dig
	cmp 	rbx, r9
	jg 		skip
	cmp 	r9, rcx
	jg 		skip
	add 	r12, r8
skip:
	dec 	r8
	jnz 	loop
	lea 	rdi, [rel fmt1]
	mov 	rsi, r12
	call 	printf WRT ..plt
	xor 	eax, eax
	mov 	rsp, rbp
	pop 	rbp
	ret

section .data
	fmt3 db "%lld%lld%lld\n", 10, 0;
	fmt1 db "%d", 10, 0;





コンパイル、実行結果

# nasm -f elf64 at5.s

# gcc -o at5 at5.o

# ./at5
20 2 5
84

以上。

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?