0

我对 arm 装配非常陌生,我正在将 armsim 用于学校项目。我有多个问题。

  1. 我需要从 txtfile 读取多行,每行都有一个字符串,最多占用 85 个字节(每行)。我的程序只读取第一行,我不知道如何读取文件的其余部分。
  2. 如果我将调用“a”的字符值((a>=65 && a<=77)||(a>=97 && a<=109)),我必须从每一行中取出每个字符并添加 13。如果 ((a>=78 && a<=109)||(a>=110 && a<=122)),我必须减去 13。如果 (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 reached\n"
ColonSpace: .asciz": "
NL: .asciz "\n " @ new line
array: .skip 85
.align
InFileHandle: .word 0


.end
4

1 回答 1

0

啊,我想通了。我不知道为什么我没有早点想到这个。不需要比较所有这些,只需要从最小的比较到最大的一次进行一次比较,基本上是一个 if/else if 语句链

于 2015-09-30T11:06:12.033 回答