stringCode.S

URL: http://147.64.242.52/~bennett/class/cmsc3240/fall2026/homework/act1/code/stringCode.S
 
/*
   Activity 1 by Dan Bennett
   Entered, debugged and understood by Dan Bennett
   Collaborators: none
   AI use: none
*/

.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"

.bss
   inputArea: .zero MAX_LETTERS +1

.text
main:

    // save the stack!
    sub       sp, sp, #16
    stur      x29, [sp, #0]
    stur      x30, [sp, #8]
    mov       x29, sp

    // save the max size in word
    mov   x0, MAX_LETTERS
    ldr   x1, =size
    stur  x0, [x1, #0]

    // prompt for input
    ldr   x0, =prompt
    mov   x1, MAX_LETTERS  
    bl    printf

    // get the input with scanf
    ldr x0, =inputFmt
    ldr x1, =inputArea
    bl scanf

    // print the results
    ldr x0, = outputFmt
    ldr x1, =inputArea
    bl printf

    // return 0
    mov      x0, #0

    // evas the stack!
    ldur     x29, [sp, #0]
    ldur     x30, [sp, #8]
    add      sp, sp, #16
    ret