【发布时间】:2016-10-16 00:55:00
【问题描述】:
所以,我正在 ARM 中开发一个程序,该程序从文件中获取一堆数字并判断它们是偶数还是奇数。
问题是我知道如何乘以 0.5,但我不知道如何在 ARM 中执行这种高级语句
if (A / 2 == 0)
print even
else
print odd
以下是我的代码:
@open input file
ldr r0,=FileName @ set Name for input file
mov r1,#0 @ mode is input
swi SWI_Open @ open file for input
bcs InFileError @ if error?
ldr r1,=InFileHandle @ load input file handle
str r0,[r1] @ save the file handle
@read integers from input file
NUMBERS:
ldr r0,=InputFileHandle @ load input file handle
ldr r0,[r0]
swi SWI_RdInt @ read the integer into R0
bcs EofReached @ Check Carry-Bit (C): if= 1 then EOF reached
@multiplication by 0.5 to test for odd or even
MUL R2 R0 0.5
@what is the test in ARM
@for ( R0 / 0.5 ) == a multiple of 1?
B NUMBERS
LOOP:
@end of program
Message1: .asciz"Hello World!"
EOL: .asciz "\n"
NewL: .ascii "\n"
Blank: .ascii " "
FileName: .asciz"input.txt"
.end
所以我认为从文件输入和读取整数的前两件事是可行的。我不知道如何测试它可以被 2 整除的条件。我认为它乘以 0.5,然后下一步是说即使该数字没有小数位,后面还有任何内容,但如果是这样,那么除以数字 B 的数字 A 是奇数。否则是偶数?
【问题讨论】:
标签: input architecture arm division multiplication