×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Capitalizing strings from a file using ARM assembly homework help

July 10, 2024
Dr. Samantha Chang
Dr. Samantha
🇨🇦 Canada
Programming
Dr. Chang is a seasoned software engineer with a Ph.D. in Computer Engineering from MIT. She has completed over 900 Programming assignments and specializes in optimizing code performance, debugging, and troubleshooting. Dr. Chang's expertise lies in ensuring efficient and scalable solutions for Groovy programming tasks.
Key Topics
  • Capitalizing Strings and Accessing Files using Software Interrupts
Tip of the day
Use well-structured shaders to optimize rendering and ensure efficient resource management. Start with simple shapes, gradually adding complexity, and debug in small steps to identify errors easily.
News
An open-source framework that allows developers to create rich Python applications in the browser using HTML's interface, bridging the gap between web development and Python scripting.

The homework deals with reading data from a file and process it by capitalizing the first letter of every word in the file and saving the resulting conversion to a different file. The program uses software interrupts (SWI) in order to access the files and printing errors. The program is to be implemented for the ARMSim# simulator. Check out the following solution provided by our ARM assembly homework help experts to learn more about string capitalization.

Capitalizing Strings and Accessing Files using Software Interrupts

Capitalizing strings from a file using ARM assembly assignment help

.text .global _start _start: @ Open input file ldr r0, =inputfile @ set input filename mov r1, #0 @ open for reading swi 0x66 @ Open the file bcs inputError @ if error opening, go to error mov r4, r0 @ save input file handle in r4 @ Open output file ldr r0, =outputfile @ set output filename mov r1, #1 @ open for writing swi 0x66 @ Open the file bcs outputError @ if error opening, go to error mov r5, r0 @ save output file handle in r5 readLoop: @ Read char from input file mov r0, r4 @ load input file handle ldr r1, =buffer @ read in buffer mov r2, #1024 @ read at most 1024 characters swi 0x6a @ read string from file bcs readEnd @ if empty file, end loop ldr r1, =buffer @ point to buffer mov r2, #0 @ index in buffer, start in zero mov r3, #1 @ indicate if we should change to uppercase convLoop: ldrb r0, [r1, r2] @ load char from string cmp r0, #0 @ see if we reached the end of string beq writeFile @ if so, write string cmp r0, #'A' @ if not letter blt saveSpace cmp r0, #'Z' @ if letter ble letter cmp r0, #'a' @ if not letter blt saveSpace cmp r0, #'z' @ if not letter bgt saveSpace cmp r3, #1 @ see if we need to capitalize bne saveChar @ if not, don't capitalize sub r0, r0, #32 @ convert character to lowercase letter: mov r3, #0 @ 0 to avoid capitals, we are inside a word b saveChar @ save character saveSpace: mov r3, #1 @ 1 to capitalize next letter mov r0, #32 @ load space character saveChar: strb r0, [r1, r2] @ save space in string add r2, r2, #1 @ increment string index b convLoop writeFile: mov r0, #10 strb r0, [r1, r2] @ save newline in string add r2, r2, #1 @ increment string index mov r0, #0 strb r0, [r1, r2] @ save end of string @ Write string to ouput file mov r0, r5 @ load output file handle ldr r1, =buffer @ write from buffer mov r2, #1024 @ write all characters swi 0x69 @ write string to file b readLoop @ read next string from file readEnd: @ Close input file mov r0, r4 @ get input file handle swi 0x68 @ close the file @ Close output file mov r0, r5 @ get output file handle swi 0x68 @ close the file @ print end message mov r0, #1 @ print to stdout ldr r1, =okMsg @ load ok message swi 0x69 @ print the message b exit @ exit the program inputError: mov r0, #1 @ print to stdout ldr r1, =inputErrorMsg @ load error message swi 0x69 @ print the error message b exit outputError: mov r0, #1 @ print to stdout ldr r1, =outputErrorMsg @ load error message swi 0x69 @ print the error message exit: swi 0x11 @ Exit the program .data inputfile: .asciz "input.txt" outputfile: .asciz "output.txt" inputErrorMsg: .asciz "Error opening the input file: \"input.txt\"\n" outputErrorMsg: .asciz "Error opening the ouutput file: \"output.txt\"\n" okMsg: .asciz "File \"output.txt\" has been created\n" buffer: .skip 1024 .end

Related Samples

Explore our collection of free programming assignment samples for inspiration and guidance. Whether you're new to coding or seeking advanced techniques, our samples offer valuable insights and solutions across various programming topics.