I am working on a school project that is in arm assembly using the raspberry pi. My goal is to open a input file and calculate the checksum just by counting the ASCII character in the input file. Then open a output file that will write the same message but add the ASCII value at the end of the text. My professor is asking to allocate memory dynamically for input and output arrays. My question is how would I go about that because he never showed us how to use it. I have researched how to use it in C but I am having a hard time putting that knowledge to arm assembly.
I have gone through a sheet from what my professor has posted online but it seems like it does not help at all. All it shows is this
in n = 500;
/* example n has value of 500 */
dbptr = (char *) malloc(n)
/* will allocate 500 bytes and dbptr will be the pointer to the beginning of
the dynamically allocated array/buffer */
What goes through my head is would I open the file. Then put the size of the string into a variable and call malloc with the variable as a parameter?
.data
disInput: .asciz "Enter input file name: "
disOutput: .asciz "\nEnter output file name: "
disHash: .asciz "Enter hash seed: "
disOptions: .asciz "\nGet checksum(1) or check integrity(2)?: "
disDone: .asciz "Checksum calculated!"
disSafe: .asciz "Integrity passed. File is safe."
disBad: .asciz "Integrity failed. File is not safe."
disNoFile: .asciz "No file exists"
disEmpty: .asciz "Empty file"
disWrong: .asciz "You entered a bad option\n"
formOption: .asciz "%d"
formInFile: .asciz "%s"
formOutFile:.asciz "%s"
formHash: .asciz "%d"
inputFile: .asciz ""
outputFile: .asciz ""
hashSeed: .int 0
option: .int 0
.text
.global main
main:
push {ip,lr}
b menu
menu:
@ask user to enter input file name
ldr r0,=disInput
bl printf
@user input for file name
ldr r0,=formInFile
ldr r1,=inputFile
bl scanf
@open file and check if empty or if it exists
@ask user to enter hash seed
ldr r0,=disHash
bl printf
@user input for hash seed
ldr r0,=formHash
ldr r1,=hashSeed
bl scanf
@ask user for option of get checksum or check integrity
ldr r0,=disOptions
bl printf
@user input for option
ldr r0,=formOption
ldr r1,=option
bl scanf
@branch depending on user option
ldr r4,=option
ldr r5,[r4]
cmp r5,#1
beq option1
cmp r5,#2
beq option2
b wrongOption
option1:
@ask user to enter output file name
ldr r0,=disOutput
bl printf
@user input for output file name
ldr r0,=formOutFile
ldr r1,=outputFile
bl scanf
@branch to calculate checksum
option2:
@
ldr r0,=disDone
bl printf
wrongOption:
@when user enters the wrong option
ldr r0,=disWrong
bl printf
b done
calculate:
@where checksum is calculated
@if option 1 then branch to done
done:
mov r0,#0
pop {ip,pc}
.end
Here is my code so far for the project just in case if its any help. Sorry if it is asking for too much but I have researched everywhere and there is not too much help with arm assembly. Thank you!