我对武器组装很陌生,我正在为一个学校项目使用armsim。我有很多问题。
- 我需要从txtfile中读取多行,每行都有一个字符串,最多需要85字节(每行)。我的程序只读取第一行,不知道如何读取文件的其余部分。
- 我必须从每行中取出每个字符并添加13,如果字符值我将调用"a"((a>=65 &&)a<=77) || (a>=97 &&a<= 109))。我必须减去13如果(a>=78 &&a<= 109) | | (> = 110,,a<= 122))。If (a==32)则打印出空格并移动到下一个字符。我不明白如何使用分支来做到这一点…
循环逐个字符处理,并将字符输出到标准输出中。这是我的代码到目前为止…我花了好多天我花了几个小时在这上面,我就是想不起来。到目前为止我只接触过java。
.equ SWI_Open, 0x66 @open a file
.equ SWI_Close,0x68 @close a file
.equ SWI_PrChr,0x00 @ Write an ASCII char to Stdout
.equ SWI_PrStr, 0x69 @ Write a null-ending string
.equ SWI_PrInt,0x6b @ Write an Integer
.equ SWI_RdInt,0x6c @ Read an Integer from a file
.equ SWI_RdStr, 0x6a @ Read string from file
.equ Stdout, 1 @ Set output target to be Stdout
.equ SWI_Exit, 0x11 @ Stop execution
.global _start
.text
_start:
ldr r0,=InFileName @ set Name for input file
mov r1,#0 @ mode is input
swi SWI_Open @ open file for input
ldr r1,=InFileHandle
str r0,[r1]
ldr r7,[r1]
ldr r1,=array
mov r2,#85
swi SWI_RdStr @stores the string into =array
mov r5,#0 @r5 is index
loop: @processes a single char then loops back
cmp r5,r2 @r2 is 83
bge procstop
ldrb r4,[r1,r5] @loads the character value from =array[r5] into r4
cmp r4,#77
ble add
cmp r4,#65
bge add
cmp r4,#97
bge add
cmp r4,#109
ble add
cmp r4,#78
bge sub
cmp r4,#90
ble sub
cmp r4,#110
bge sub
cmp r4,#122
ble sub
add:
add r4,r4,#13
sub:
sub r4,r4,#13
mov r0,r4
swi SWI_PrChr
strb r4,[r1,r5]
add r5,r5,#1
B loop
procstop:
mov r0,#Stdout
swi SWI_PrStr
swi SWI_Exit
.data
InFileName: .asciz "lab4.txt"
EndOfFileMsg: .asciz "End of file reachedn"
ColonSpace: .asciz": "
NL: .asciz "n " @ new line
array: .skip 85
.align
InFileHandle: .word 0
.end
啊,我明白了。我不知道为什么我没有早点想到这一点。不需要全部比较,只需要一次一个比较从最小的比较到最大的比较,基本上是if/else if语句链