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アセンブラ その4

Last updated at Posted at 2025-11-14

概要

paiza.ioでaarch64アセンブラやってみる。
アセンブラ、やってみた。
gccのputsを使ってみた。

サンプルコード


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

fn main() {
	let b = "
.global main
.text
;.align 4
main:
	sub 	sp, sp, 16
	str 	x30, [sp]
	adrp 	x0, message
	add 	x0, x0, #:lo12:message
	bl 		puts
	ldr 	x30, [sp]
	add 	sp, sp, 16
	mov 	w0, 0
	ret

.data	
message: .string \"Hello world. \"
";
	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());
}




投入したソース




.global main
.text
main:
	sub 	sp, sp, 16
	str 	x30, [sp]
	adrp 	x0, message
	add 	x0, x0, #:lo12:message
	bl 		puts
	ldr 	x30, [sp]
	add 	sp, sp, 16
	mov 	w0, 0
	ret

.data	
message: .string "Hello world. "


    

実行結果

Hello world. 

成果物

以上。

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?