导航

    全志在线开发者论坛

    • 注册
    • 登录
    • 搜索
    • 版块
    • 话题
    • 在线文档
    • 社区主页

    自己动手编写一个非常简单的RISC-V C调用使用ABI规则ASM汇编的demo, 使用qemu-riscv64虚拟机测试.

    MR Series
    1
    1
    735
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • tigger
      tigger LV 7 最后由 编辑

      hello.c

      #include <stdio.h>
      
      extern int plus(int a, int b);
      
      int main(void)
      {
              printf("hello, %d\n", plus(111, 222));
      }
      

      plus.S

      .text
      
      .global plus
      
      plus:
              add     a0,a1,a0
              ret
      

      编译:

      riscv64-linux-gnu-gcc -o hello hello.c plus.S -g
      

      运行:

      $ QEMU_LD_PREFIX=/usr/riscv64-linux-gnu/ qemu-riscv64 hello
      hello, 333
      
      1 条回复 最后回复 回复 引用 分享 0
      • Referenced by  Kirin Kirin 
      • 1 / 1
      • First post
        Last post

      Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号

      行为准则 | 用户协议 | 隐私权政策