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?

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

0
Posted at

概要

中古ノート買ってみた。
wsl1のubuntu18.04にnasm入れてみた。
nasmをgasに置き換えてみた。
練習問題やってみた。

練習問題

最初nを入力して、次にn個、数字を入力して、結果を表示せよ。

実行結果

# gcc in0.s -o in0 -no-pie

# ./in0
4
1 2 3 4
1       2       3       4       


サンプルコード

.intel_syntax noprefix
.global main
.extern scanf, printf
.text

main:
	push 	rbp
	mov 	rbp, rsp
	sub 	rsp, 128
	lea 	rdi, fmti[rip]
	lea 	rsi, [rsp + 104]
	call 	scanf

	mov 	r13, [rsp + 104]
	mov		r14, 0
_input:
	lea 	rdi, fmti[rip]
	lea 	rsi, [rsp + 104]
	call	scanf

	mov 	rax, [rsp + 104]
	lea		rbx, arry[rip]
	add		rbx, r14
	mov		dword [rbx], rax
	add		r14, 4
	dec 	r13
	jnz 	_input

	lea		rbx, arry[rip]
	mov		rax, dword [rbx]
	lea 	rdi, fmto[rip]
	mov 	rsi, rax
	call	printf

	add		rbx, 4
	mov		rax, dword [rbx]
	lea 	rdi, fmto[rip]
	mov 	rsi, rax
	call	printf

	add		rbx, 4
	mov		rax, dword [rbx]
	lea 	rdi, fmto[rip]
	mov 	rsi, rax
	call	printf

	add		rbx, 4
	mov		rax, dword [rbx]
	lea 	rdi, fmto[rip]
	mov 	rsi, rax
	call	printf

	xor 	eax, eax
	mov 	rsp, rbp
	pop 	rbp
	ret

.data
	fmti: 	.string "%d"
	fmto: 	.string "%d\t"

.bss
	.comm 	arry, 12



以上。

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?