安装qemu后是否有运行任何ARM程序集文件.s的命令

如何解决安装qemu后是否有运行任何ARM程序集文件.s的命令

我最近运行了以下命令来安装 qemu。

sudo apt-get install qemu-user
sudo mkdir -p /opt/arm/10
wget 'https://developer.arm.com/-/media/Files/downloads/gnu-a/10.2-2020.11/binrel/gcc-arm-10.2-2020.11-x86_64-arm-none-linux-gnueabihf.tar.xz?revision=d0b90559-3960-4e4b-9297-7ddbc3e52783&la=en&hash=985078B758BC782BC338DB947347107FBCF8EF6B' -O gcc-arm-10.2-2020.11-x86_64-arm-none-linux-gnueabihf.tar.xz
sudo tar Jxf  gcc-arm-10.2-2020.11-x86_64-arm-none-linux-gnueabihf.tar.xz  -C /opt/arm/10

现在没有了。我想在我的 linux 子系统上编译和执行的 ARM 文件。如果有人可以为这个问题提供演练,那就太好了。我已经包括了一个不。下面是一些示例文件的链接。我正在寻找能够成功编译和运行所有这些文件的通用命令。就像在 C 中,gcc -o test test.c 将编译和运行任何 C 文件。 我没有树莓派

这里有几个 ARM 程序示例:

.global _start
_start:
        MOV R1,#X
        MOV R2,#Y
        MOV R3,#Z
        MUL R5,R1,R1
        MUL R6,R2,R2
        ADD R5,R6
        MUL R6,R3,R3
        CMP R5,R6
        BEQ _same
        MOV R4,#0
        B _exit
_same:
        MOV R4,#1
_exit:
        MOV R0,R4
        MOV R7,#1
        SWI 0
.data
.global _start
_start:
        LDR R1,=X
        LDR R2,=Y
        LDR R3,=T
        LDR R4,[R1]
        STR R4,[R3]
        LDR R4,[R2]
        STR R4,[R1]
        LDR R4,[R3]
        STR R4,[R2]
_exit:
        MOV R0,#0
        MOV R7,#1
        SWI 0

.data
X: .word 0x16
Y: .word 0x21
T: .word 0x00
@ binary search for V in 25 element array.
        @ returns index for V if V is in the array.
        @ otherwise returns length of array (25).

        .global _start
_start:
        @ populate the array A
        LDR R1,=A
        MOV R2,#0x00
_populate_array:
        CMP R2,#MAX @ i == 25
        BEQ _search
        STR R2,[R1]
        ADD R1,#0x04
        ADD R2,#0x1
        B _populate_array
_search:
        MOV R6,#4      @ R6 == 4 
        MOV R1,#0      @ R1 == left
        MOV R2,#MAX    @ R2 == right
        SUB R2,#1      @ R2 = MAX-1
_loop:
        CMP R1,R2      @ is left>right ?
        BGT _fail

        @ compute new middle position
        ADD R3,R2  @ R3 = left + right
        LSR R3,#1  @ middle = (left + right)/2
        @ each integer element uses 4 bytes of memory
        @ R7 is the memory address for the middle integer value in array A
        MUL R7,R6  @ R7 = middle * 4

        @ obtain middle value at middle position
        LDR R4,=A      @ R4 == &A    (load address of A's 1st byte)
        ADD R4,R7      @ R4 == &A[m] (add offset of m to that address)
        LDR R5,[R4]    @ R5 == A[m]  (get value in A at that address)

        @ compare middle value to searched for value V
        CMP R5,#V      @ V==A[m]?
        BEQ _exit       @ we've found the value V
        BGT _left       @ is V somewhere in left half?
        
        @ if not,V must be somewhere in right half if at all
        MOV R1,R3      @ left = middle
        ADD R1,#1      @ left = left + 1
        B _loop

_left:                  @ A[m]<V (V would be somewhere in left half)
        MOV R2,R3      @ right = middle;
        SUB R2,#1      @ right = right - 1
        B _loop
        
_fail: 
        MOV R3,#MAX
_exit:
        MOV R0,R5
        MOV R7,#1
        SWI 0
.data
.equ MAX,25
A: .rept MAX
   .word 0
   .endr
.equ V,17
.global main
main:
    @ Stack the return address (lr) in addition to a dummy register (ip) to
    @ keep the stack 8-byte aligned.
    push    {ip,lr}

    @ Load the argument and perform the call. This is like 'printf("...")' in C.
    ldr     r0,=message
    bl      printf

    @ Exit from 'main'. This is like 'return 0' in C.
    mov     r0,#0    @ Return 0.

    @ Pop the dummy ip to reverse our alignment fix,and pop the original lr
    @ value directly into pc — the Program Counter — to return.
    pop     {ip,pc}

    @ --------------------------------
    @ Data for the printf calls. The GNU assembler's ".asciz" directive
    @ automatically adds a NULL character termination.
message:
    .asciz "Hello,world.\n"
@ Here's how we will use the ARM registers R1-R5:
        @
        @ R1 - address of the next word
        @ R2 - the character counter
        @ R3 - contents of the next word
        @ R4 - next byte
        @ R5 - byte count

        .global _start

        @ program starts here
_start:
        LDR R1,=mystring

        @ initialise the character count (R2) to be 0
        MOV R2,#0

nextw:
        @ load the address of the next word into R3
        LDR R3,[R1]
        @ add 4 to the byte count
        MOV R5,#4

nextb:
        @ load next byte from word into R4
        MOV R4,R3
        @ use bitmask to get next byte value
        AND R4,#MASK
        @ if byte in R4 is 0,then we've found the "end of string" value
        CMP R4,#EOS
        BEQ endl
        @ otherwise,increment the character count by 1
    ADD R2,#1
        @ decrement bytes by 1
        SUB R5,#1
        @ while (bytes !=0) from the slide
        CMP R5,#0
        BEQ incr
        @ shift the contents of the word 8 bits right
        LSR R3,#8
        B nextb

incr:
        @ move to the next word address
        ADD R1,#4
        B nextw

endl:
        @ end of string '0' value found,we're done.
        @
        @ return character count as exit value
        MOV R0,R2
        MOV R7,#1
        SWI 0

.data
.equ MASK,0x000000ff
.equ EOS,0
mystring: .asciz "0123456789"

@ try other string examples
@ mystring: .asciz "thunderbirds"

提前谢谢!

解决方法

你的问题的答案是否定的,因为它取决于你的汇编代码所针对的系统,以及它在做什么(我只是在这里提到它,但实际上并没有像 ARM 汇编文件这样的东西,因为这样的文件可能使用不同的指令集,例如 arm/a32thumb2/t32)。

例如,在使用 gcc 的 Linux 系统上编译时,默认情况下假定入口点为 main,而不是 _start - 这就是您必须对第一个程序稍作修改的原因 - 您可以使用诸如 meldwinmerge 之类的程序来识别修改/未修改版本之间的差异。该程序还必须使用 Linux 系统调用接口,您的所有程序都是如此。有关 SVC/SWI 和 Linux 系统调用接口的详细信息,请参阅 here

article 也值得一读,以了解在调用入口点之前会发生什么。

如果您想直接在仿真的 ARM 处理器上执行程序,使用 qemu-system-armarm-none-eabi-gcc 将是解决方案,但我不会推荐它,除非您有更多的知识。>

如果您想熟悉 Windows 上的 ARM 汇编,使用 WSL 和 qemu-arm 是一个很好的解决方案。

我在这里假设您在提供的示例程序中将 _start 替换为 main

您的第一个程序甚至无法组装 - 在将其用于问题之前确保它可以组装。

你的第二个程序使用:

/opt/arm/10/gcc-arm-10.2-2020.11-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-gcc -static -o 2 2.s
 qemu-arm 2

你的第三个程序使用:

/opt/arm/10/gcc-arm-10.2-2020.11-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-gcc -static -o 3 3.s
 qemu-arm 3

你的第四个程序使用:

 /opt/arm/10/gcc-arm-10.2-2020.11-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-gcc -static -o 4 4.s
qemu-arm 4
Hello,world.

您的第五个程序确实使用以下方法编译/执行:

/opt/arm/10/gcc-arm-10.2-2020.11-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-gcc -static -o 5 5.s
qemu-arm 5

底线,一旦修改,除了第一个需要修复的程序之外,所有程序都使用“唯一”命令编译,并使用“唯一”命令执行。


您可以通过以下方式稍微简化用于编译/运行程序的命令:

在 WSL 中安装 binfmt-support

sudo apt-get install binfmt-support

创建一个名为 etc/binfmt.d/qemu-arm.conf 的文件,其中包含这两行:

# /etc/binfmt.d/qemu-arm.conf                                                                                                                                                                                                                                         
:arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff://opt/qemu-4.2.0-static/bin/qemu-arm:OC

这将导致您的系统透明地使用 qemu-arm 来运行您的可执行文件:

qemu-arm 4
Hello,world.

然后可以替换为:

./4
Hello,world.

将 arm-none-linux-gnueabihf 工具链可执行文件的位置添加到您的 PATH。例如,这可以通过将以下行添加到用户主目录中的 .bashrc 文件来完成:

PATH=/opt/arm/10/gcc-arm-10.2-2020.11-x86_64-arm-none-linux-gnueabihf/bin:${PATH}

用于编译的命令可以是:

 arm-none-linux-gnueabihf-gcc -static -o 4 4.s

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-