-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prog2 Palindromes
100 lines (80 loc) · 2.76 KB
/
Prog2 Palindromes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
##############################################
# Program Name: Assignment 1 Palindromes
# Programmer: Max Waldt
# Date 02/3/15
#############################################
# Functional Description:
# A program to find palindromes from integers a user inputs
#############################################
# Cross References:
# v0: N,
# t0: Sum
###########################################
.data # Data declaration section
Prompt: .asciiz "\n Please Input an integer: "
Input: .asciiz "\n The original input was: "
Result: .asciiz "\n The palindrome result is: "
Bye: .asciiz "\n ****** Have a good day ******"
T1: .asciiz "\nt1= "
T2: .asciiz "\nt2= "
.globl main
.text
###########################################
main: # Start of code section
#Prompt user for input
li $v0, 4 #System call code for Print String
la $a0, Prompt #load address of prompt into $a0
syscall #print the prompt message
#Wait on input
li $v0, 5 #system call code for Read Integer
syscall #reads the value of N into $v0
blez $v0 Exit #branch if input is 0
#li $t0, 265
move $t0, $v0 #copy $v0 to $t0, this will be the original input value
move $t1, $t0 #copy $t0 to $t1, stepwise original
li $t5, 10 #load value 16 into $t5
#Setup for palindrome calculations and checking
Initialize:
move $t2, $t1 #copy $t0 to $t1, stepwise arithmetic
li $t3, 0 #load 0 into $t3, stepwise flipped
li $t4, 0 #load 0 into $t4, stepwise remainder
b Reversal
#loop
Reversal:
div $t2, $t5 #divide $t1 by $t5
mflo $t2, #move LO to $t1, quotient
mfhi $t4, #move HI to $t4, remainder
mult $t3, $t5 #multiply $t3 by $t5(10)
mflo $t3 #
add $t3, $t3, $t4 #add $t3 and $t4, store in $t3
blez $t2 NumberCheck #branch to palindrome check
b Reversal #repeat loop
###########################################
NumberCheck:
bne $t1, $t3 SumReversal #branch back to Reversal loop
beq $t1, $t3 End #branch to End
###########################################
SumReversal:
add $t1, $t1, $t3
b Initialize
###########################################
End:
li $v0, 4 #System call code for Print String
la $a0, Input #load address of msg into $a0
syscall #print the string
li $v0, 1 #System call code for Print String
move $a0, $t0 #load address of msg into $a0
syscall #print the string
li $v0, 4 #System call code for Print String
la $a0, Result #load address of msg into $a0
syscall #print the string
li $v0, 1 #System call code for Print String
move $a0, $t1 #load address of msg into $a0
syscall #print the string
li $v0, 4 #System call code for Print String
la $a0, Bye #load address of msg into $a0
syscall #print the string
Exit:
li $v0, 10 #terminate program run and
syscall #return control to the system
# END OF PROGRAM