如何在Linux子系统中的VSCode上运行程序集(.s)文件 [英] How do i run assembly (.s) files on VSCode in Linux subsystem
问题描述
我刚刚接触过ARM编程.学习了一些基础知识,但是在运行代码方面遇到了问题.我在Linux子系统上使用VSCode作为我的IDE.
I have just got into ARM programming. Learned a few basics but am having issues with running code. I use VSCode on Linux Subsystem as my IDE.
我的计算机上没有安装任何东西,我想运行ARM代码.我已经在线阅读了有关" qemu "的信息.和"内核"和其他东西,但不确定它们的含义.如果有人针对此问题提供详细的演练,那就太好了.我没有树莓派.
I have nothing installed on my computer and i would like to run ARM code. I have read online something about "qemu" and "kernel" and stuff, but am not sure what they mean. It would be great if someone provides a detailed walkthrough for such a problem. I do not have a raspberry pi.
例如,如何在VSCode上运行以下 division.s
文件?
For example, how do i run the following division.s
file on VSCode?
.global _start
_start:
MOV R1, #X
MOV R2, #Y
MOV R3, #Z
CMP R1, R2 @ is x>y ?
BGT _tryx
CMP R2, R3 @ is y>z ?
BGT _isy
MOV R4, R3
B _exit
_isy:
MOV R4, R2
B _exit
_tryx:
CMP R1, R3 @ is x>z ?
BGT _isx
MOV R4, R3
B _exit
_isx:
MOV R4, R1
_exit:
MOV R0, R4
MOV R7, #1
SWI 0
.data
.equ X, 3
.equ Y, 5
.equ Z, 4
我需要安装任何扩展程序吗?我需要下载什么吗?我已经使用 gcc
来编译C代码.可以在这里使用吗?
Are there any extensions i need to install? Is there anything i need to download? I have used gcc
to compile C code. Can it be used here too?
提前谢谢!:D
推荐答案
您的问题相当广泛.话虽如此,您可以使用以下过程在WSL中执行程序的稍微修改的版本:
Your question is rather a broad one. This being said, a slightly modified version of your program can be executed in WSL using the following procedure:
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
/tmp/division.s:
/tmp/division.s:
@ count how often we can take Y from X
.global main
main:
MOV R1, #X
MOV R2, #Y
MOV R3, #0 @ Q
_loop:
CMP R1, R2
BLT _exit
SUB R1, R2
ADD R3, #1
B _loop
_exit:
MOV R0, R3
MOV R7, #1
SWI 0
.data
.equ X, 23
.equ Y, 4
编译:
/opt/arm/10/gcc-arm-10.2-2020.11-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-gcc -static -o /tmp/division /tmp/division.s
执行-WSL:
qemu-arm /tmp/division
echo $?
5
这是预期的结果,因为23 div 4是5.
Which is the expected result, since 23 div 4 is 5.
执行-Windows 10:
Executing - Windows 10:
C:\>c:\Windows\System32\bash -c "qemu-arm /tmp/division; echo $?"
5
C:\>
或者:
C:\>c:\Windows\System32\bash -c "qemu-arm /tmp/division"
C:\>echo %ERRORLEVEL%
5
请注意,也可以通过下载/安装 gcc-arm-10.2-2020.11-mingw-w64-i686-arm-none-linux-gnueabihf.tar.xz
而不是 gcc-arm-10.2-2020.11-x86_64-arm-none-linux-gnueabihf.tar.xz
-您的选择.
Note that division.s may have been compiled in Windows 10 as well by downloading/installing gcc-arm-10.2-2020.11-mingw-w64-i686-arm-none-linux-gnueabihf.tar.xz
instead of gcc-arm-10.2-2020.11-x86_64-arm-none-linux-gnueabihf.tar.xz
- your choice.
我想让您了解一下使用上述信息从 vscode
运行程序的详细信息,您会质疑恕我直言.
I let it to you than to go into the details of using the information above for running your program from vscode
, you question being a bit too broad IMHO.
更新: Division.s是静态编译的,目的是避免为任何不需要的动态库指定位置.
Update: division.s was compiled statically on purpose for avoiding having to specify the locations for any non-needed dynamic libraries.
在不使用 -static
选项的情况下对其进行编译,然后执行将导致显示以下错误消息:
Compiling it without using the -static
option, and executing it would result in the following error message to be displayed:
qemu-arm division
/lib/ld-linux-armhf.so.3: No such file or directory
可以通过告诉 qemu-arm
在哪里寻找所需的动态库(在这种情况下为/lib/ld-linux-armhf.so.3
)来避免:
It can be avoided by telling qemu-arm
where to look for required dynamic libraries, /lib/ld-linux-armhf.so.3
in this case:
qemu-arm -L /opt/arm/10/gcc-arm-10.2-2020.11-x86_64-arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/libc division
echo $?
5
这篇关于如何在Linux子系统中的VSCode上运行程序集(.s)文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!