本文介绍了ARM汇编印刷数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图打印,我已经存储的号码。我不知道我是否接近或路要走。任何帮助将是虽然pciated AP $ P $。这里是我的code:

I am trying to print a number that I have stored. I'm not sure if I am close or way off. Any help would be appreciated though. Here is my code:

.data
.balign 4
a: .word 4

.text
.global main
main:
        ldr r0, addr_of_a
        mov r1, #8
        str r1, [r0]
write:
        mov r0, #1
        ldr r1, addr_of_a
        mov r2, #4
        mov r7, #4
        swi #0
        bx lr

addr_of_a: .word a

据编译和运行,但我没有看到任何打印。据我了解,我需要到哪里的R1,R2中,R0中的文件描述符,和R7有多少字节指定写入调用,如果它被设置为#4开始打印的地址。我只是尝试存储#8,然后打印存储的号码。

It compiles and runs, but I don't see anything printed. From what I understand, I need the address of where to start printing in r1, how many bytes in r2, the file descriptor in r0, and r7 specifies the write call if it is set to #4. I am simply trying to store #8, then print the stored number.

推荐答案

该系统调用写操作的第二个参数(R1)的指针,你想打印字符串。您传递给它一个指向整数。这就是为什么它没有打印任何东西,因为有你正在传递给它的内存区域没有ASCII字符。

The syscall write takes on the second argument (r1) a pointer to the string you want to print. You are passing to it a pointer to an integer. That's why it's not printing anything, because there are no ASCII characters on the memory region you are passing to it.

下面你会使用系统调用写找到一个Hello World程序。

Below you'll find a "Hello World" program using the syscall write.

.text
.global main
main:
        push {r7, lr}

        mov r0, #1
        ldr r1, =string
        mov r2, #20
        mov r7, #4
        svc #0

        pop {r7, pc}

.data
string: .asciz "Hello World\n"

如果您想打印一个数字,你可以使用printf函数C库。像这样的:

If you want to print a number you can use the printf function from the C library. Like this:

.text
.global main
.extern printf
main:
        push {ip, lr}

        ldr r0, =string
        mov r1, #1024
        bl printf

        pop {ip, pc}

.data
string: .asciz "The number is: %d\n"

最后,如果你要打印的系统调用写的数量,您还可以实现itoa函数(一个整数转换为字符串)。

Finally, if you want to print the number with the syscall write you can also implement a itoa function (one that converts an integer to a string).

这篇关于ARM汇编印刷数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 09:09