Io 机具气泡按臂组件排序

Io 机具气泡按臂组件排序,io,arm,bubble-sort,Io,Arm,Bubble Sort,我希望使用ARM来编译我的树莓派终端的功能:输入一些数字,然后在程序中进行气泡排序,并输出排序结果。 编译和链接没有问题,但在执行目标文件时屏幕显示“非法指令”(ARM GNU样式) 现在,我可以使用ARM assembler在没有输入字符的树莓派上实现气泡排序,代码如下: .section .text .global _start _start: mov r2,#10 @The number of characters output mov r4,r2 b

我希望使用ARM来编译我的树莓派终端的功能:输入一些数字,然后在程序中进行气泡排序,并输出排序结果。 编译和链接没有问题,但在执行目标文件时屏幕显示“非法指令”(ARM GNU样式)


现在,我可以使用ARM assembler在没有输入字符的树莓派上实现气泡排序,代码如下:

.section .text
.global _start

_start: 
    mov r2,#10  @The number of characters output
    mov r4,r2   
    b loop      @Enter the first cycle
loop:
    mov r1,pc   @Point to the first position of the string
    ldr r1,=str 
    sub r4,r4,#1
    cmp r4,#0   @R4 is compared to 0, and if r4 is equal to 0, 
                @end up,print result 
                @greater than it goes into the second cycle
    beq stop    
    mov r5,#0   
    b loop1     @The entrance to the second cycle
    b loop


loop1:

    ldrb r3,[r1]    @R1 is pointing to the memory address of the value of 
                    @the assignment to the r3 register
    ldrb r6,[r1,#1] 
    cmp r3,r6       @r3 r6 compared
    strgtb r3,[r1,#1]   @If greater than r6, their values are exchanged
    strgtb r6,[r1]
    add r1,r1,#1        @R1 points to the next character
    add r5,r5,#1        
    cmp r5,r4       @r5 r4 compared
    bne loop1       @r5<r4 next loop1
    b loop          @r5=r4,Jump out of the second cycle and return to the 
                    @first cycle
stop:
    @printf str
    add r2,r2,#1
    mov r0,#0x1
    mov r1,pc
    ldr r1,=str
    mov r7,#0x4
    svc 1

    @exit
    mov r0,#0x0
    mov r7,#0x1
    svc 1
@Define data segment
.data
str:
.ascii "7543216890\n"
.section.text
.全球启动
_开始:
mov r2,#10@输出的字符数
mov r4,r2
b循环@进入第一个循环
循环:
mov r1,pc@指向字符串的第一个位置
ldr r1,=str
第r4、r4、1小节
cmp r4,#0@r4与0比较,如果r4等于0,
@最后,打印结果
@大于它进入第二个循环
北京站
mov r5,#0
b循环1@进入第二个循环
b环
循环1:
ldrb r3,[r1]@r1指向
@对r3寄存器的赋值
ldrb r6,[r1,#1]
cmp r3,r6@r3 r6比较
strgtb r3,[r1,#1]@如果大于r6,则交换其值
strgtb r6[r1]
将r1、r1、#1@r1点添加到下一个字符
加上r5,r5,#1
cmp r5,r4@r5 r4比较

bne loop1@r5您应该能够在ARM上做与在x86上完全相同的事情。你能给我们看一个代码示例,说明你可以用x86而不是ARM做什么吗?虽然ARM程序集不同,但我高度怀疑ARM ubuntu内核没有用于
读/写
的系统API和STDIN/STDOUT支持,这将不再是一个类似UNIX的操作系统了。。。您只需要找到正确的文档,如何从程序集中调用系统服务。等等,ubuntu在你的开发虚拟机上,不是在Pi上?这取决于什么操作系统有Pi,或者如果你没有操作系统。。。您仍然需要目标OS API,或者学习如何控制连接到Pi的硬件。x86程序集无法在OS上直接访问终端输入或输出,您必须询问操作系统。显然,这两个平台都支持哪些。您在哪里拥有此虚拟机?你的意思是说你在pi上有一些操作系统,然后在另一个操作系统上有ubuntu,比如raspian,然后在vm上有ubuntu?为什么要加一层?这并不是说它改变了什么。@ZeusChen那么你为什么不直接说出来,而不是含糊不清地说些什么呢?我们已经讨论了一天了,只是为了解决您的实际问题,您可以直接将其发布到问题中。
.section .text
.global _start

_start: 
    mov r2,#10  @The number of characters output
    mov r4,r2   
    b loop      @Enter the first cycle
loop:
    mov r1,pc   @Point to the first position of the string
    ldr r1,=str 
    sub r4,r4,#1
    cmp r4,#0   @R4 is compared to 0, and if r4 is equal to 0, 
                @end up,print result 
                @greater than it goes into the second cycle
    beq stop    
    mov r5,#0   
    b loop1     @The entrance to the second cycle
    b loop


loop1:

    ldrb r3,[r1]    @R1 is pointing to the memory address of the value of 
                    @the assignment to the r3 register
    ldrb r6,[r1,#1] 
    cmp r3,r6       @r3 r6 compared
    strgtb r3,[r1,#1]   @If greater than r6, their values are exchanged
    strgtb r6,[r1]
    add r1,r1,#1        @R1 points to the next character
    add r5,r5,#1        
    cmp r5,r4       @r5 r4 compared
    bne loop1       @r5<r4 next loop1
    b loop          @r5=r4,Jump out of the second cycle and return to the 
                    @first cycle
stop:
    @printf str
    add r2,r2,#1
    mov r0,#0x1
    mov r1,pc
    ldr r1,=str
    mov r7,#0x4
    svc 1

    @exit
    mov r0,#0x0
    mov r7,#0x1
    svc 1
@Define data segment
.data
str:
.ascii "7543216890\n"