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:

Formal Description

Using the following instructions, produce a working ARM 8 assembly program that will read in and print out a string.
  1. Create an activity1 directory on Archimedes
  2. Copy my Makefile into this directory.
  3. Create a file, perhaps stringCode.S in this directory.
  4. 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.
  5. 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 
  6. Define a maximum string size.
    • .equ MAX_LETTERS, 10
    • This is an assembly directive
  7. Declare a data segment
    • Provide space for a variable called size
      • This is a double, declared with .double and initialized to 0
      • I need this for I/O
      • But we will need other doubles in the future.
    • 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"
  8. Declare the bss segment
    • In this, declare a space big enough to hold the maximum letters.
    • .zero declares a size in bytes.
    •     outputFmt: .asciz "The word is '%s'\n" 
      
      .bss
         inputArea: .zero MAX_LETTERS +1
  9. start the text segment and declare main
    •     inputArea: .zero MAX_LETTERS +1
      
      .text
      main:
  10. 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 stp call.
    • If you use this, please document in your code what this call does.
  11. 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.
  12. 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
    • bl is 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.
  13. 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
  14. Print the resulting string
    •      bl scanf
      
          // print the results
          ldr x0, = outputFmt
          ldr x1, =inputArea
          bl printf
  15. 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
  16. Once your code compiles and runs, submit it to d2l.
Using what you have learned, implement homework 2.

Notes

Required Files

A single arm assembly program.

Submission

Submit the assignment to the D2L folder Activity 1 by the due date.