-
Notifications
You must be signed in to change notification settings - Fork 0
/
CH5utils.asm
175 lines (153 loc) · 3.69 KB
/
CH5utils.asm
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File: utils.asm
# Purpose: To define utilities which will be used in MIPS programs.
# Author: Charles Kann
#
# Instructors are granted permission to make copies of this file
# for use by # students in their courses. Title to and ownership
# of all intellectual property rights
# in this file are the exclusive property of
# Charles W. Kann, Gettysburg, Pa.
#
# Subprograms Index:
# Exit - Call syscall with a server 10 to exit the program
# NewLine - Print a new line character (\n) to the console
# PrintInt - Print a string with an integer to the console
# PrintString - Print a string to the console
# PromptInt - Prompt the user to enter an integer, and return
# it to the calling program.
#
# Modification History
# 12/27/2014 - Initial release
# subprogram: PrintNewLine
# author: Charles Kann
# purpose: to output a new line to the user console
# input: None
# output: None
# side effects: A new line character is printed to the
# user's console
.text
PrintNewLine:
li $v0, 4
move $a1, $a0
la $a0, __PNL_newline
syscall
move $a0, $a1
jr $ra
.data
__PNL_newline: .asciiz "\n"
# subprogram: PrintInt
# author: Charles W. Kann
# purpose: To print a string to the console
# input: $a0 - The address of the string to print.
# $a1 - The value of the int to print
# returns: None
# side effects: The String is printed followed by the integer value.
.text
PrintInt:
# Print string. The string address is already in $a0
li $v0, 4
syscall
# Print integer. The integer value is in $a1, and must
# be first moved to $a0.
move $a0, $a1
li $v0, 1
syscall
#return
jr $ra
# subprogram: PromptInt
# author: Charles W. Kann
# purpose: To print the user for an integer input, and
# to return that input value to the caller.
# input: $a0 - The address of the string to print.
# returns: $v0 - The value the user entered
# side effects: The String is printed followed by the integer value.
.text
PromptInt:
# Print the prompt, which is already in $a0
li $v0, 4
syscall
# Read the integer value. Note that at the end of the
# syscall the value is already in $v0, so there is no
# need to move it anywhere.
move $a0, $a1
li $v0, 5
syscall
#return
jr $ra
# subprogram: PromptFLOAT
# author:
# purpose:
# input:
# returns:
# side effects:.
.text
PromptFloat:
# Print the prompt, which is already in $a0
li $v0, 4
syscall
# Read the integer value. Note that at the end of the
# syscall the value is already in $v0, so there is no
# need to move it anywhere.
move $a0, $a1
li $v0, 6
syscall
#return
jr $ra
# subprogram: PrintString
# author: Charles W. Kann
# purpose: To print a string to the console
# input: $a0 - The address of the string to print.
# returns: None
# side effects: The String is printed to the console.
.text
PrintString:
addi $v0, $zero, 4
syscall
jr $ra
# subprogram: Exit
# author: Charles Kann
# purpose: to use syscall service 10 to exit a program
# input: None
# output: None
# side effects: The program is exited
.text
Exit:
li $v0, 10
syscall
# Subprogram: ConvertIntToHexBin
# Author: Jonathan Rumley
# Purpose: to output a new line to the user console
# Input: $a0, Integer
# Returns: $, $, Binary and Hexadecmial values
# Side effects: Print binary and hexadecimal values from integer input
.text
ConvertIntToHexBin:
li $v0, 34
syscall
jal PrintNewLine
li $v0, 35
syscall
jr $ra
.text
PrintFloat:
# Print string. The string address is already in $a0
li $v0, 4
syscall
# Print float
li $v0, 2
mov.d $f12, $f0
syscall
#return
jr $ra
.text
ReadInt:
li $v0,5
syscall
jr $ra
.text
ConvertINTCtoF:
#v0 holds input from prompt
mul $t0,$v0,9 # to convert,multiply by 9,
div $t0,$t0,5 # divide by 5,then
add $t0,$t0,32 # add 32
jr $ra