我在业余时间学习汇编,因为我对低级操作感兴趣。 我尝试运行本教程中的代码。
代码可以在这里和下面找到:
/******************************************************************************
* @file float.s
* @brief simple example of scalar multiplication using the FPU
*
* Simple example of using the ARM FPU to compute the multiplication result of
* two float values
*
* @author Christopher D. McMurrough
******************************************************************************/
.global main
.func main
main:
LDR R0, =val1 @ load variable address
VLDR S0, [R0] @ load the value into the VFP register
LDR R0, =val2 @ load variable address
VLDR S1, [R0] @ load the value into the VFP register
VMUL.F32 S2, S0, S1 @ compute S2 = S0 * S1
VCVT.F64.F32 D4, S2 @ covert the result to double precision for printing
VMOV R1, R2, D4 @ split the double VFP register into two ARM registers
BL _printf_result @ print the result
B _exit @ branch to exit procedure with no return
_exit:
MOV R7, #4 @ write syscall, 4
MOV R0, #1 @ output stream to monitor, 1
MOV R2, #21 @ print string length
LDR R1, =exit_str @ string at label exit_str:
SWI 0 @ execute syscall
MOV R7, #1 @ terminate syscall, 1
SWI 0 @ execute syscall
_printf_result:
PUSH {LR} @ push LR to stack
LDR R0, =result_str @ R0 contains formatted string address
BL printf @ call printf
POP {PC} @ pop LR from stack and return
.data
result_str: .asciz "Multiplication result = %f \n"
exit_str: .ascii "Terminating program.\n"
val1: .float 3.14159
val2: .float 0.100
我在 Raspberry Pi 中编译代码:
gcc -o float float.s
它编译没有任何问题,但是当我运行它时,我收到以下错误:
程序收到信号 SIGBUS,总线错误。
main() 中的 0x00010428
我已经对导致 SIGBUS 错误的原因进行了一些研究,在这里我唯一能想到的是访问未对齐的内存,但是十进制的 0x00010428 = 66,600 可以被 4 整除,所以我不确定问题是什么.
跑步
cat/proc/cpuinfo
我得到以下信息:
处理器:0
型号名称:ARMv6 兼容处理器 rev 7 (v6l)
BogoMIPS:2.00
特点:half thumb fastmult vfp edsp java tls
CPU 实现者:0x41
CPU 架构:7
CPU 变体:0x0
CPU 部分:0xb76
CPU 修订:7硬件:BCM2708
修订:0002