我是ARM汇编代码的新手,我很难修改此代码以获取TST的结果并打印奇数和偶数输出。安全地在一个帖子中要求回答问题。
R3的结果最终为ffffff,使我的打印没有输出。
.text @ Direvtive
.global _start @ declare global begining
_start:
LDR R1,=idx @ content of idx is length of Vec and now R1 is a counter.
LDR R1,[R1] @ R1 is now the length of Vec. read inderectly
LDR R2,=Vec @ R2 is the address of first element of vector
MOV R0,#0 @ temp register
MOV R4, #0 @ R4 is the summation of odd numbers
MOV R5, #0 @ R5 is the summation of even numbers
LOOP:
LDR R3,[R2] @ R3 = Vec[i]
@idea instead of cond: AND r0, r3, #1 (then even = total-odd)
TST r3, #1
addeq r5,r5,R3
addne r4,r4,R3
ADD R2,R2,#4 @ R2 pointing to the next element of vector
SUBS R1,R1,#1 @ counter
@CMP R1, #0
BNE LOOP @ loop until R1=0
BL ODD_PRINT
BL EVEN_PRINT
ODD_PRINT:
STR R0,[R4]
MOV R4, R0
MOV R4, #1
EVEN_PRINT:
STR R1,[R5]
MOV R5, R1
MOV R5, #1
SWI 0x6b @ Printing the contant of R4 (AND R5?)
SWI 0x11 @ halt
.data @ Directive for begining of data part
.align @ Directive for alagnment of memory addresses
idx: .word 16 @ Total number of elements of vector
Vec: .word -7,3,5,1 @ vector initiation
.word -3,5,-18,-10
.word 2,-1,0,6
.word -10,-9,8,2
.end