概要
中古ノート買ってみた。
wsl1のubuntu18.04にnasm入れてみた。
アセンブラで、atcoder、見つけたので、やってみた。
参考にしたページ
練習問題
PracticeA - Welcome to AtCoder
3つの整数値と文字列を1つ受け取り、整数値の和と文字列を一行に出力する問題です。
投入するデータ
1
2
3
hello
期待値
6 hello
サンプルコード
global main
extern printf, scanf
section .text
main:
push rbp
mov rbp, rsp
sub rsp, 128
lea rdi, [rel fmti]
lea rsi, [rsp]
lea rdx, [rsp + 4]
lea rcx, [rsp + 8]
lea r8, [rsp + 12]
call scanf wrt ..plt
mov rax, [rsp]
mov rbx, [rsp + 4]
mov rcx, [rsp + 8]
lea rdx, [rsp + 12]
add rax, rbx
add rax, rcx
lea rdi, [rel fmto]
mov rsi, rax
call printf wrt ..plt
xor eax, eax
mov rsp, rbp
pop rbp
ret
section .data
fmti db "%d%d%d%s\n", 10, 0;
fmto db "%d %s", 10, 0;
コンパイル、実行結果
# nasm -f elf64 at0.asm
# gcc -o at0 at0.o -lc
# ./at0
1
2
3
hello
6 hello
以上。