概要
paiza.ioでaarch64アセンブラやってみる。
bit数を確認する。
仕掛けは、rustでシェルコマンドを実行する。
サンプルコード
use std::fs;
use std::io::{Write, BufWriter};
use std::process::Command;
fn main() {
let b = "
#include <stdio.h>
int main(int argc, char **argv, char **evnp) {
#ifdef __LP64__
printf(\"64bit >> \");
#else
printf(\"32bit >> \");
#endif
printf(\"Hello world.\");
return 0;
}
";
let mut f = BufWriter::new(fs::File::create("hello.c").unwrap());
f.write(b.as_bytes()).unwrap();
f.flush();
let output0 = Command::new("gcc").arg("hello.c").output().expect("failed to execute process");
let hello0 = output0.stderr;
println!("{}", std::str::from_utf8(&hello0).unwrap());
let output = Command::new("./a.out").output().expect("failed to execute process");
let hello = output.stdout;
println!("{}", std::str::from_utf8(&hello).unwrap());
}
実行結果
64bit >> Hello world.
成果物
以上。