記憶,我會用代碼首先啓動:零出裝配
.equ SWI_Open, 0x66 @ open a file
.equ SWI_Close, 0x68 @ close a file
.equ SWI_PrStr, 0x69 @ Write a null-ending string
.equ SWI_RdStr, 0x6a @ Read a string
.equ Stdout, 1 @ Set output target to be Stdout
.equ SWI_Exit, 0x11 @ Stop execution
.global _start
.text
_start:
ldr r0,=InFileName
mov r1,#0
swi SWI_Open
bcs InFileError
ldr r1,=InFileHandle
str r0,[r1]
mov r8, r0 @ r8 will hold the address of the file handle
ReadLoop:
mov r0, r8
ldr r1, =LineArray
mov r2, #256
swi SWI_RdStr
bcs EndReached
@ r1 now has address of the read line
mov r9, r1 @ r9 will hold the memory address of the read line
mov r4, #0 @ r4 = START
mov r5, #1 @ r5 = END
bl PerLineFunc @ r0/r1 args passed to PerLineFunc
@ ShuffleWord within PerLineFunc should change the words around, so now we just need to print the new line of words
mov r0, #Stdout
mov r1, r9
swi SWI_PrStr
ldr r1, =NL
swi SWI_PrStr
bal ReadLoop
SWI_RdStr讀取指定的文件,並將其存儲線與存儲到R1的地址位置記憶。我的問題是,我不知道如何將行讀入的內存清零。如果第一行是20個字符,並且下一行是15,那麼在讀取第二行之後,第一行的最後5個字符仍然在內存中。
我想這會是這樣的:
ldr r1, =LineArray
str #0, [r1]
但返回一個語法錯誤......我只是想再次運行ReadLoop之前重置內存。
編輯:在OP中發佈答案。需要被添加到ReadLoop
mov r0, #0
ldr r1, =LineArray
mov r2, #0
bl EraseMemory @ r0, r1, and r2 passed into EraseMemory
這裏結束 這第一部分是在EraseMemory功能
EraseMemory:
str r0, [r1]
add r1, r1, #4
add r2, r2, #1
cmp r2, #64 @ 256/4 = 64
bxeq lr @ This loop should run 64 times to erase all 256 bytes of memory that were used
bal EraseMemory
固定-insn-size RISC機器在單個指令中沒有空間用於立即操作數和尋址模式+位移。即使你不使用位移('[r1 + 100]'或ARM語法是什麼),存儲指令編碼對這些位有意義。 (這類事情是降低指令集複雜性的關鍵)。順便說一句,儘可能避免重新加載常量。你可以將'= NL'加載到另一個reg中,這樣你就不會破壞'= LineArray'。 –
我不太明白你第一部分的意思。至於加載到寄存器,我的印象是這是可以做的,因爲這些都是內存中的位置。 '= NL'是與'= LineArray'不同的內存位置,因此將它加載到r1中並不是什麼大問題。該程序的這部分似乎工作得很好,我只是無法消除記憶後,我已經使用它 – Peter
我的意思是你似乎談論不止一次加載'= LineArray'到'r1',你不是嗎?我在說你應該把'= LineArray'保存在一個寄存器中,而不是重新加載它。另外,如果'NL'接近內存中的'LineArray',你可以'添加r2,r1,#(NL - LineArray)'或其他東西。請記住,'ldr reg,= value'是一個僞操作,可以從附近的常量池變成負載,而不是直接的負載。 –