Skip to content

Commit

Permalink
aarch64: Test aarch64 instruction with cc-rs in rust
Browse files Browse the repository at this point in the history
Addition of two numbers in aarch64 using cc-rs compiling in rust.
Compiled and Executed Sucessfully
Output:
$ Finished dev [unoptimized + debuginfo] target(s) in 0.06s
$ Running `target/debug/aarch64`
$ 5
  • Loading branch information
vibhoothi committed Jun 27, 2019
1 parent 69f12b8 commit 1d88562
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
10 changes: 10 additions & 0 deletions aarch64/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "aarch64"
version = "0.1.0"
authors = ["vibhoothi <vibhoothiiaanand@gmail.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cc = "1.0"
8 changes: 8 additions & 0 deletions aarch64/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![feature(rustc_private)]
extern crate cc;

fn main() {
cc::Build::new()
.file("src/add.s")
.compile("my-asm-lib");
}
13 changes: 13 additions & 0 deletions aarch64/src/add.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// add,s

.text

.globl main_addr
/*
Addition of two numbers
*/
main_addr:
mov w0, #2
mov w1, #3
add w0, w0, w1
ret
8 changes: 8 additions & 0 deletions aarch64/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extern "C" {
fn main_addr() -> u32;
}

fn main() {
let sum = unsafe { main_addr() };
println!("{}", sum);
}

0 comments on commit 1d88562

Please sign in to comment.