概要
中古ノート買ってみた。
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
以上。