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?

paiza.ioでaarch64アセンブラ その5

Posted at

概要

paiza.ioでaarch64アセンブラやってみる。
アセンブラ、やってみた。
gccの書式付きprintfを使ってみた。

サンプルコード


use std::fs;
use std::io::{Write, BufWriter};
use std::process::Command;

fn main() {
	let b = "
.text
.global main
main:
	stp 	x29, x30, [sp, -0x10]!
	sub 	sp, sp, 0x10
	mov 	x8, 66
	str 	x8, [sp]
	adr 	x0, Lstr
	bl 		printf
	mov 	w0, 0
	add 	sp, sp, 0x10
	ldp 	x29, x30, [sp], 0x10
	ret
.data
Lstr: .asciz \"test: %x \"
";
	let mut f = BufWriter::new(fs::File::create("test.s").unwrap()); 
	f.write(b.as_bytes()).unwrap();
	f.flush();

	let output0 = Command::new("gcc").args(&["-no-pie", "test.s"]).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());
}




投入したソース


.text
.global main
main:
	stp 	x29, x30, [sp, -0x10]!
	sub 	sp, sp, 0x10
	mov 	x8, 66
	str 	x8, [sp]
	adr 	x0, Lstr
	bl 		printf
	mov 	w0, 0
	add 	sp, sp, 0x10
	ldp 	x29, x30, [sp], 0x10
	ret
    
.data
Lstr: .asciz "test: %x "

実行結果

test: f28ec418 

成果物

以上。

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?