I'll start with the code first:
.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 reads a line from the given file and stores it into memory with the address location stored into r1. My issue is that I don't know how to zero out the memory where the line was read into. If the first line is 20 characters, and the next line is 15, then the last 5 characters of the first line are still in memory after the 2nd line is read.
I was thinking it would be something like:
ldr r1, =LineArray
str #0, [r1]
but that returns a syntax error... I'm just trying to reset the memory before running the ReadLoop again.
Edit: Posting answer in OP.
This first part needs to be added to the end of ReadLoop
mov r0, #0
ldr r1, =LineArray
mov r2, #0
bl EraseMemory @ r0, r1, and r2 passed into EraseMemory
Here's the EraseMemory function
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
question from:
https://stackoverflow.com/questions/65909705/put-zero-into-address-using-arm-assembly