Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- new_line: .asciiz "\n"
- prompt_post: .asciiz "Give me your zip code (0 to stop): "
- input_string: .space 128
- leading_string: .asciiz "The sum of all digits in your zip code is: "
- debug_out_1: .asciiz "Rec Stop"
- .text
- # -------[Macro Section]-------
- .macro exit_prog #Used to terminate the program
- li $v0, 10 #Let syscall know we want to terminate the program
- syscall #Exit program
- .end_macro #End exit_prog macro
- .macro print (%msg_out) #Used to simplify output and make code look cleaner
- li $v0, 4 # Let syscall know we want to print a NULL terminated string
- la $a0, %msg_out # Let syscall know the address of the NULL terminated string we want to print
- syscall #Print the NULL terminated string
- .end_macro #End print macro
- .macro print_pointer (%msg_out) #Used to simplify output and make code look cleaner
- li $v0, 4 # Let syscall know we want to print a NULL terminated string
- move $a0, %msg_out # Let syscall know the address of the NULL terminated string we want to print
- syscall #Print the NULL terminated string
- .end_macro #End print macro
- .macro print_stored_int (%label) #Used to simplify output and make code look cleaner
- li $v0, 1 #Let syscall know we want to print an int
- la $t0, %label #Load the address of %label
- lw $a0, ($t0) #Load the int that %label points to
- syscall #Print the loaded int
- .end_macro #End print_stored_int macro
- .macro print_int (%label) #Used to simplify output and make code look cleaner
- li $v0, 1 #Let syscall know we want to print an int
- move $a0, %label #Load the int that %label points to
- syscall #Print the loaded int
- .end_macro #End print_stored_int macro
- .macro get_int_store (%label) #Used to simplify input and make code look cleaner
- li $v0, 5 #Let syscall know we want to load an in from the users input
- syscall #Wait for number input
- la $t1, %label #Get the address of the label
- sw $v0, 0($t1) #Store the int recieved into the address the label is pointing to
- .end_macro #End get_int_store macro
- .macro get_string_store (%label) #Used to simplify input and make code look cleaner
- li $v0, 8 #Let syscall know we want to load an in from the users input
- la $a0, %label
- li $a1, 127
- syscall #Wait for number input
- .end_macro #End get_int_store macro
- getzip:
- print(prompt_post)
- get_string_store(input_string)
- lb $t0, input_string
- sub $t0, $t0, 48
- beqz $t0, stop_me
- la $t0, input_string
- addi $a0, $zero, 5
- add $a1, $zero, $t0
- jal recGetNumber
- j getzip
- stop_me:
- j exit
- recGetNumber:
- subi $sp, $sp, 12 # move stack pointer up 3 words
- sw $ra, 0($sp)
- sw $a0, 4($sp)
- sw $a1, 8($sp)
- move $s0, $a0
- move $s1, $a1
- beq $a0, $zero, recGetNumberExit #if arg is zero, leave
- #Do Stuff
- lb $t1, 0($s1)
- sub $t1, $t1, 48
- print_int($t1)
- #End stuff
- subiu $a0, $s0, 1
- addiu $a1, $s1, 1
- sw $ra, 0($sp)
- jal recGetNumber
- recGetNumberExit:
- lw $ra, 0($sp)
- addi $sp, $sp, 12
- jr $ra
- exit:
- exit_prog
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement