概要
中古ノート買ってみた。
wsl1のubuntu18.04にnasm入れてみた。
nasmをgasに置き換えてみた。
環境
windows10
wsl1
ububtu18.04
手順
- nasm->gas
- .intel_syntax noprefix使う。
- .comm使う。
- .string使う。
- [rip]使う。
サンプルコード
大きさ 7 の欠片を大きさ 3 以下の欠片に分ける最小の切断回数を 1 行で出力してください。
答えは2。
.intel_syntax noprefix
.global main
.extern scanf, printf
.text
main:
sub rsp, 8
lea rdi, fmti[rip]
lea rsi, a[rip]
call scanf
lea rdi, fmti[rip]
lea rsi, b[rip]
call scanf
mov eax, a[rip]
sub eax, 1
mov edx, 0
mov ecx, b[rip]
div ecx
lea rdi, fmto[rip]
mov rsi, rax
call printf
done:
add rsp, 8
mov rax, 0
ret
.data
fmti: .string "%d"
fmto: .string "%d \n\0"
.bss
.comm a, 4
.comm b, 4
コンパイル、実行結果
# gcc oupc.s -o oupc -no-pie
# ./oupc
7
3
2
以上。