Alternative Assignment September 28 2026
Short Description:
Write a program that will do basic string input/output using scanf and printf.
Goals
When you finish this homework, you should have:- Used scanf and printf to perform string I/O
- Stored a string in memory and retrieved that string from memory.
- Produced a working ARM 8 assembly program that runs on archimedes.
Formal Description
Using the following instructions, produce a working ARM 8 assembly program that will read in and print out a string.- Create an activity1 directory on Archimedes
- Copy my Makefile into this directory.
- Create a file, perhaps stringCode.S in this directory.
- Add a comment at the top of the file.
- It appears you can use
- block comments /* ... */
- C style comments //
- Comments starting with
- Add your name.
- Add AI usage information.
- Add collaborator information.
- It appears you can use
- Add
.global main- As last semester, this exports the main routine to the linker
/* Activity 1 by Dan Bennett Entered, debugged and understood by Dan Bennett Collaborators: none AI use: none */ .global main
- Define a maximum string size.
-
.equ MAX_LETTERS, 10 - This is an assembly directive
-
- Declare a data segment
- Provide space for a variable called size
- This is a double, declared with
.doubleand initialized to 0 - I need this for I/O
- But we will need other doubles in the future.
- This is a double, declared with
- Provide a prompt
- Provide an input format
- Provide an output format
-
.global main .equ MAX_LETTERS, 10 .data size: .double 0 prompt: .asciz "Enter a word with up to %d letters\n" inputFmt: .asciz "%10s" outputFmt: .asciz "The word is '%s'\n"
- Provide space for a variable called size
- Declare the bss segment
- In this, declare a space big enough to hold the maximum letters.
-
.zerodeclares a size in bytes. -
outputFmt: .asciz "The word is '%s'\n" .bss inputArea: .zero MAX_LETTERS +1
- start the text segment and declare main
-
inputArea: .zero MAX_LETTERS +1 .text main:
-
- Save the fp and sp and adjust the sp.
-
main: // save the stack! sub sp, sp, #16 stur x29, [sp, #0] stur x30, [sp, #8] mov x29, sp - You might want to investigate the
stpcall. - If you use this, please document in your code what this call does.
-
- Save the max word size in the memory location size.
- This is so we can pass it to scanf, we need to pass a pointer to the location holding the size.
-
mov x29, sp // save the max size in word mov x0, MAX_LETTERS ldr x1, =size stur x0, [x1, #0] - We load MAX_LETTERS into x0
- We load the address of size into x1
- We store x0 at Memory[x1 + 0]
- So size will hold the max size of an string.
- Call printf to prompt the user
-
stur x0, [x1, #0] // prompt for input ldr x0, =prompt mov x1, MAX_LETTERS bl printf - x0 holds the address of the prompt
- x1 holds the value of the max letters
-
blis branch and link instruction- It saves the pc in x30
- And branches to the given label.
- We will look at this further in the future.
-
- Call scanf to read in the string
- x0 is the address of the input format string
- x1 is the address of the allocated memory for the string
-
bl printf // get the input with scanf ldr x0, =inputFmt ldr x1, =inputArea bl scanf
- Print the resulting string
-
bl scanf // print the results ldr x0, = outputFmt ldr x1, =inputArea bl printf
-
- Finally, return 0 and restore the stack.
-
bl printf // return 0 mov x0, #0 // evas the stack! ldur x29, [sp, #0] ldur x30, [sp, #8] add sp, sp, #16 ret
-
- Once your code compiles and runs, submit it to d2l.
Notes
- The final program is stringCode.S
- All files are in the code directory.
- If you used an AI to solve this problem, please note in the comments the percentage of the problem that AI was used to solve.
- If you worked with others, please note who, and the amount of collaboration.