Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 2.97 KB | None | 0 0
  1. .data
  2.  
  3. new_line: .asciiz "\n"
  4. prompt_post: .asciiz "Give me your zip code (0 to stop): "
  5. input_string: .space 128
  6. leading_string: .asciiz "The sum of all digits in your zip code is: "
  7. debug_out_1: .asciiz "Rec Stop"
  8.  
  9. .text
  10.  
  11. #   -------[Macro Section]-------
  12.     .macro exit_prog #Used to terminate the program
  13.     li $v0, 10 #Let syscall know we want to terminate the program
  14.     syscall #Exit program
  15.     .end_macro #End exit_prog macro
  16.    
  17.     .macro print (%msg_out) #Used to simplify output and make code look cleaner
  18.     li $v0, 4 # Let syscall know we want to print a NULL terminated string
  19.     la $a0, %msg_out # Let syscall know the address of the NULL terminated string we want to print
  20.     syscall #Print the NULL terminated string
  21.     .end_macro #End print macro
  22.    
  23.     .macro print_pointer (%msg_out) #Used to simplify output and make code look cleaner
  24.     li $v0, 4 # Let syscall know we want to print a NULL terminated string
  25.     move $a0, %msg_out # Let syscall know the address of the NULL terminated string we want to print
  26.     syscall #Print the NULL terminated string
  27.     .end_macro #End print macro
  28.    
  29.     .macro print_stored_int (%label) #Used to simplify output and make code look cleaner
  30.     li $v0, 1 #Let syscall know we want to print an int
  31.     la $t0, %label #Load the address of %label
  32.     lw $a0, ($t0) #Load the int that %label points to
  33.     syscall #Print the loaded int
  34.     .end_macro #End print_stored_int macro
  35.    
  36.     .macro print_int (%label) #Used to simplify output and make code look cleaner
  37.     li $v0, 1 #Let syscall know we want to print an int
  38.     move $a0, %label #Load the int that %label points to
  39.     syscall #Print the loaded int
  40.     .end_macro #End print_stored_int macro
  41.    
  42.     .macro get_int_store (%label) #Used to simplify input and make code look cleaner
  43.     li $v0, 5 #Let syscall know we want to load an in from the users input
  44.     syscall #Wait for number input
  45.     la $t1, %label #Get the address of the label
  46.     sw $v0, 0($t1) #Store the int recieved into the address the label is pointing to
  47.     .end_macro #End get_int_store macro
  48.    
  49.     .macro get_string_store (%label) #Used to simplify input and make code look cleaner
  50.     li $v0, 8 #Let syscall know we want to load an in from the users input
  51.     la $a0, %label
  52.     li $a1, 127
  53.     syscall #Wait for number input
  54.     .end_macro #End get_int_store macro
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64. getzip:
  65.     print(prompt_post)
  66.     get_string_store(input_string)
  67.     lb $t0, input_string
  68.     sub $t0, $t0, 48
  69.     beqz $t0, stop_me
  70.     la $t0, input_string
  71.     addi    $a0, $zero, 5
  72.     add $a1, $zero, $t0
  73.     jal recGetNumber
  74.     j getzip
  75.     stop_me:
  76.  
  77.     j exit
  78.  
  79.  
  80. recGetNumber:
  81.     subi    $sp, $sp, 12     # move stack pointer up 3 words
  82.     sw  $ra, 0($sp)
  83.     sw  $a0, 4($sp)
  84.     sw  $a1, 8($sp)
  85.     move    $s0, $a0
  86.     move    $s1, $a1
  87.     beq     $a0, $zero, recGetNumberExit #if arg is zero, leave
  88.     #Do Stuff
  89.     lb $t1, 0($s1)
  90.     sub $t1, $t1, 48
  91.     print_int($t1)
  92.    
  93.     #End stuff
  94.     subiu   $a0, $s0, 1
  95.     addiu   $a1, $s1, 1
  96.     sw  $ra, 0($sp)
  97.     jal recGetNumber
  98.    
  99.     recGetNumberExit:
  100.     lw  $ra, 0($sp)
  101.     addi    $sp, $sp, 12
  102.    
  103.     jr $ra
  104.  
  105.  
  106.  
  107.  
  108. exit:
  109.     exit_prog
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement