about summary refs log tree commit diff
path: root/src/rt/rust_env.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-03-15 21:15:46 -0700
committerbors <bors@rust-lang.org>2013-03-15 21:15:46 -0700
commitdc5ad5070d06015d6a45f656882ae245197d0ff8 (patch)
tree977b611b2987dadc410537ffdd32e1671a11b959 /src/rt/rust_env.cpp
parent6f1e8ef71abb390a8f6406292ea06c729dcbf9e5 (diff)
parent83f2d4ab3dbd3b52ea60212a6698c73201b67a34 (diff)
downloadrust-dc5ad5070d06015d6a45f656882ae245197d0ff8.tar.gz
rust-dc5ad5070d06015d6a45f656882ae245197d0ff8.zip
auto merge of #5359 : luqmana/rust/inline-asm, r=pcwalton
Continuation of #5317. Actually use operands properly now, including any number of output operands.

Which means you can do things like call printf:
```Rust
fn main() {
    unsafe {
        do str::as_c_str(~"The answer is %d.\n") |c| {
            let a = 42;
            asm!("mov $0, %rdi\n\t\
                  mov $1, %rsi\n\t\
                  xorl %eax, %eax\n\t\
                  call _printf"
                 :
                 : "r"(c), "r"(a)
                 : "rdi", "rsi", "eax"
                 : "volatile","alignstack"
                 );
        }
    }
}
```

```
% rustc foo.rs
% ./foo
The answer is 42.
```

Or just add 2 numbers:
```Rust
fn add(a: int, b: int) -> int {
    let mut c = 0;
    unsafe {
        asm!("add $2, $0"
             : "=r"(c)
             : "0"(a), "r"(b)
             );
    }
    c
}

fn main() {
    io::println(fmt!("%d", add(1, 2)));
}
```

```
% rustc foo.rs
% ./foo
3
```

Multiple outputs!
```Rust
fn addsub(a: int, b: int) -> (int, int) {
    let mut c = 0;
    let mut d = 0;
    unsafe {
        asm!("add $4, $0\n\t\
              sub $4, $1"
             : "=r"(c), "=r"(d)
             : "0"(a), "1"(a), "r"(b)
             );
    }
    (c, d)
}

fn main() {
    io::println(fmt!("%?", addsub(5, 1)));
}
```
```
% rustc foo.rs
% ./foo
(6, 4)
```

This also classifies inline asm as RvalueStmtExpr instead of the somewhat arbitrary kind I made it initially. There are a few XXX's regarding what to do in the liveness and move passes.
Diffstat (limited to 'src/rt/rust_env.cpp')
0 files changed, 0 insertions, 0 deletions