MIPS Code For conversion of string of characters to base 10 from base 33
I have this assignment and it has to do all of the following:
I have to: write a MIPS program that reads a string of up to 4 characters from user input. The program must process the user input with a loop. The program must NOT have subprograms. Then, assume that the user input is in base 33. Convert that to a decimal integer. Please help me. I get errors in my code. Also, I don't know how I would convert the string to an integer to later convert into base 10. I thought I was doing it right, but am confused now.
I wrote my code but it seems to not be working.
Here is my code:
.data
Ask:
.asciiz "n Please Enter 4 Charactersn"
userInput: .space 20
Answer:
.asciiz "n You Entered : n"
.text
main:
#addi $t0, 0
li $v0, 4
la $a0, Ask #display question
syscall
li $v0, 8 #get input
la $a0, userInput
li $a1, 20
syscall
li $v0, 4
la $a0, Answer
syscall
li $v0, 4
la $a0, userInput
syscall
lb $s1, 1($a0) #last digit
lb $s2 2($a0) #third
lb $s3 3($a0) #second digit
lb $s4, 4($a0) #first digit
lb $t0, 0($a0) #checks for n
addi $t1, $zero, 10 #takes in n
addi $t7, $zero, 33 #gets value to multiply
addi $s0, $zero, 1089 #gets 33^2
addi $t5, $zero, 97 #gets 64, smaller than ascii code for 'A'
addi $t6, $zero 96 #gets 96, smaller than ascii code for 'a'
addi $t2, $zero, 65 #loads 47 into $t2, smaller than the ascii code for '0'
#addi $t3, $zero, 55
beq $t0, $t1, Label1
Label1:
blt $s1, $t2, L1
blt $s1, $t5, L2
bgt $s1, $t6, L3
L1:
addi $s1, $s1, -48 #subtracts 48 from $s1 which is 48 to get int from 0 to 9
L2:
addi $s1, $s1, -55 #gets values from 10 to 33
L3:
addi $s1, $s1, -87 #gets values from 10 to 33 for small caps
blt $s2, $t2, L4
blt $s2, $t5, L5
bge $s2, $t6, L6
L4:
addi $s2, $s2, -48
L5:
addi $s2, $s2, -55
L6:
addi $s2, $s2, -87
blt $s3, $t2, L7
blt $s3, $t5, L8
bgt $s3, $t6, L9
L7: addi $s3, $s3, -48
L8: addi $s3, $s3, -55
L9: addi $s3, $s3, -87
blt $s4, $t2, L10
blt $s4, $t5, L11
bgt $s4, $t6, L12
L10:
addi $s4, $s4, -48
L11:
addi $s4, $s4, -55
L12:
addi $s4, $s4 , -87
syscall
add $s5, $zero, 0
add $s5,$s5, $s1
mult $s2, $t7
mflo $s2
add $s5, $s5, $s2
mult $s3, $s0
mflo $s3
add $s5, $s5, $s3
mult $s0, $t7
mflo $s0
mult $s4, $s0
mflo $s4
mfhi $s0
add $s5, $s5, $s4
add $s5, $s5, $s0
syscall
#li $v0, 1
#la $a0, $s5
#la $v0, 4
#lw $a0, s4
#last system call of the program will be very last instruction
li $v0, 10
syscall
string mips base review
|
show 1 more comment
I have this assignment and it has to do all of the following:
I have to: write a MIPS program that reads a string of up to 4 characters from user input. The program must process the user input with a loop. The program must NOT have subprograms. Then, assume that the user input is in base 33. Convert that to a decimal integer. Please help me. I get errors in my code. Also, I don't know how I would convert the string to an integer to later convert into base 10. I thought I was doing it right, but am confused now.
I wrote my code but it seems to not be working.
Here is my code:
.data
Ask:
.asciiz "n Please Enter 4 Charactersn"
userInput: .space 20
Answer:
.asciiz "n You Entered : n"
.text
main:
#addi $t0, 0
li $v0, 4
la $a0, Ask #display question
syscall
li $v0, 8 #get input
la $a0, userInput
li $a1, 20
syscall
li $v0, 4
la $a0, Answer
syscall
li $v0, 4
la $a0, userInput
syscall
lb $s1, 1($a0) #last digit
lb $s2 2($a0) #third
lb $s3 3($a0) #second digit
lb $s4, 4($a0) #first digit
lb $t0, 0($a0) #checks for n
addi $t1, $zero, 10 #takes in n
addi $t7, $zero, 33 #gets value to multiply
addi $s0, $zero, 1089 #gets 33^2
addi $t5, $zero, 97 #gets 64, smaller than ascii code for 'A'
addi $t6, $zero 96 #gets 96, smaller than ascii code for 'a'
addi $t2, $zero, 65 #loads 47 into $t2, smaller than the ascii code for '0'
#addi $t3, $zero, 55
beq $t0, $t1, Label1
Label1:
blt $s1, $t2, L1
blt $s1, $t5, L2
bgt $s1, $t6, L3
L1:
addi $s1, $s1, -48 #subtracts 48 from $s1 which is 48 to get int from 0 to 9
L2:
addi $s1, $s1, -55 #gets values from 10 to 33
L3:
addi $s1, $s1, -87 #gets values from 10 to 33 for small caps
blt $s2, $t2, L4
blt $s2, $t5, L5
bge $s2, $t6, L6
L4:
addi $s2, $s2, -48
L5:
addi $s2, $s2, -55
L6:
addi $s2, $s2, -87
blt $s3, $t2, L7
blt $s3, $t5, L8
bgt $s3, $t6, L9
L7: addi $s3, $s3, -48
L8: addi $s3, $s3, -55
L9: addi $s3, $s3, -87
blt $s4, $t2, L10
blt $s4, $t5, L11
bgt $s4, $t6, L12
L10:
addi $s4, $s4, -48
L11:
addi $s4, $s4, -55
L12:
addi $s4, $s4 , -87
syscall
add $s5, $zero, 0
add $s5,$s5, $s1
mult $s2, $t7
mflo $s2
add $s5, $s5, $s2
mult $s3, $s0
mflo $s3
add $s5, $s5, $s3
mult $s0, $t7
mflo $s0
mult $s4, $s0
mflo $s4
mfhi $s0
add $s5, $s5, $s4
add $s5, $s5, $s0
syscall
#li $v0, 1
#la $a0, $s5
#la $v0, 4
#lw $a0, s4
#last system call of the program will be very last instruction
li $v0, 10
syscall
string mips base review
"I get errors in my code." and "it seems to not be working." are not good problem descriptions. What exactly are the errors, and where exactly do they occur? Also, the code appears to be targeting a simulator like SPIM or MARS, which have fairly decent debugging features built in (e.g. single-stepping, breakpoints, register/memory viewer). What have you done in terms of analyzing the runtime behavior of your code?
– Michael
Nov 12 '18 at 16:01
Ok. So basically, it is not an error from mips. What I mean by that is that if I try to convert 12AB to base 33, it is not working. It just keeps it at 12AB. Also, I don't know for sure if the string to int conversion is actually working. Can you please help?
– Eva Achim
Nov 12 '18 at 16:03
Alright. Then use the simulator to single-step through the conversion code and verify that the result of each step is what you expect.
– Michael
Nov 12 '18 at 16:06
I tried doing that but I am using QTSpim and I don't think it has that feature. Can you please advise me on how to fix/improve my code?
– Eva Achim
Nov 12 '18 at 16:16
Sure it does. You can set breakpoints by right-clicking in the code window, and you can single-step with the F10 key.
– Michael
Nov 12 '18 at 16:17
|
show 1 more comment
I have this assignment and it has to do all of the following:
I have to: write a MIPS program that reads a string of up to 4 characters from user input. The program must process the user input with a loop. The program must NOT have subprograms. Then, assume that the user input is in base 33. Convert that to a decimal integer. Please help me. I get errors in my code. Also, I don't know how I would convert the string to an integer to later convert into base 10. I thought I was doing it right, but am confused now.
I wrote my code but it seems to not be working.
Here is my code:
.data
Ask:
.asciiz "n Please Enter 4 Charactersn"
userInput: .space 20
Answer:
.asciiz "n You Entered : n"
.text
main:
#addi $t0, 0
li $v0, 4
la $a0, Ask #display question
syscall
li $v0, 8 #get input
la $a0, userInput
li $a1, 20
syscall
li $v0, 4
la $a0, Answer
syscall
li $v0, 4
la $a0, userInput
syscall
lb $s1, 1($a0) #last digit
lb $s2 2($a0) #third
lb $s3 3($a0) #second digit
lb $s4, 4($a0) #first digit
lb $t0, 0($a0) #checks for n
addi $t1, $zero, 10 #takes in n
addi $t7, $zero, 33 #gets value to multiply
addi $s0, $zero, 1089 #gets 33^2
addi $t5, $zero, 97 #gets 64, smaller than ascii code for 'A'
addi $t6, $zero 96 #gets 96, smaller than ascii code for 'a'
addi $t2, $zero, 65 #loads 47 into $t2, smaller than the ascii code for '0'
#addi $t3, $zero, 55
beq $t0, $t1, Label1
Label1:
blt $s1, $t2, L1
blt $s1, $t5, L2
bgt $s1, $t6, L3
L1:
addi $s1, $s1, -48 #subtracts 48 from $s1 which is 48 to get int from 0 to 9
L2:
addi $s1, $s1, -55 #gets values from 10 to 33
L3:
addi $s1, $s1, -87 #gets values from 10 to 33 for small caps
blt $s2, $t2, L4
blt $s2, $t5, L5
bge $s2, $t6, L6
L4:
addi $s2, $s2, -48
L5:
addi $s2, $s2, -55
L6:
addi $s2, $s2, -87
blt $s3, $t2, L7
blt $s3, $t5, L8
bgt $s3, $t6, L9
L7: addi $s3, $s3, -48
L8: addi $s3, $s3, -55
L9: addi $s3, $s3, -87
blt $s4, $t2, L10
blt $s4, $t5, L11
bgt $s4, $t6, L12
L10:
addi $s4, $s4, -48
L11:
addi $s4, $s4, -55
L12:
addi $s4, $s4 , -87
syscall
add $s5, $zero, 0
add $s5,$s5, $s1
mult $s2, $t7
mflo $s2
add $s5, $s5, $s2
mult $s3, $s0
mflo $s3
add $s5, $s5, $s3
mult $s0, $t7
mflo $s0
mult $s4, $s0
mflo $s4
mfhi $s0
add $s5, $s5, $s4
add $s5, $s5, $s0
syscall
#li $v0, 1
#la $a0, $s5
#la $v0, 4
#lw $a0, s4
#last system call of the program will be very last instruction
li $v0, 10
syscall
string mips base review
I have this assignment and it has to do all of the following:
I have to: write a MIPS program that reads a string of up to 4 characters from user input. The program must process the user input with a loop. The program must NOT have subprograms. Then, assume that the user input is in base 33. Convert that to a decimal integer. Please help me. I get errors in my code. Also, I don't know how I would convert the string to an integer to later convert into base 10. I thought I was doing it right, but am confused now.
I wrote my code but it seems to not be working.
Here is my code:
.data
Ask:
.asciiz "n Please Enter 4 Charactersn"
userInput: .space 20
Answer:
.asciiz "n You Entered : n"
.text
main:
#addi $t0, 0
li $v0, 4
la $a0, Ask #display question
syscall
li $v0, 8 #get input
la $a0, userInput
li $a1, 20
syscall
li $v0, 4
la $a0, Answer
syscall
li $v0, 4
la $a0, userInput
syscall
lb $s1, 1($a0) #last digit
lb $s2 2($a0) #third
lb $s3 3($a0) #second digit
lb $s4, 4($a0) #first digit
lb $t0, 0($a0) #checks for n
addi $t1, $zero, 10 #takes in n
addi $t7, $zero, 33 #gets value to multiply
addi $s0, $zero, 1089 #gets 33^2
addi $t5, $zero, 97 #gets 64, smaller than ascii code for 'A'
addi $t6, $zero 96 #gets 96, smaller than ascii code for 'a'
addi $t2, $zero, 65 #loads 47 into $t2, smaller than the ascii code for '0'
#addi $t3, $zero, 55
beq $t0, $t1, Label1
Label1:
blt $s1, $t2, L1
blt $s1, $t5, L2
bgt $s1, $t6, L3
L1:
addi $s1, $s1, -48 #subtracts 48 from $s1 which is 48 to get int from 0 to 9
L2:
addi $s1, $s1, -55 #gets values from 10 to 33
L3:
addi $s1, $s1, -87 #gets values from 10 to 33 for small caps
blt $s2, $t2, L4
blt $s2, $t5, L5
bge $s2, $t6, L6
L4:
addi $s2, $s2, -48
L5:
addi $s2, $s2, -55
L6:
addi $s2, $s2, -87
blt $s3, $t2, L7
blt $s3, $t5, L8
bgt $s3, $t6, L9
L7: addi $s3, $s3, -48
L8: addi $s3, $s3, -55
L9: addi $s3, $s3, -87
blt $s4, $t2, L10
blt $s4, $t5, L11
bgt $s4, $t6, L12
L10:
addi $s4, $s4, -48
L11:
addi $s4, $s4, -55
L12:
addi $s4, $s4 , -87
syscall
add $s5, $zero, 0
add $s5,$s5, $s1
mult $s2, $t7
mflo $s2
add $s5, $s5, $s2
mult $s3, $s0
mflo $s3
add $s5, $s5, $s3
mult $s0, $t7
mflo $s0
mult $s4, $s0
mflo $s4
mfhi $s0
add $s5, $s5, $s4
add $s5, $s5, $s0
syscall
#li $v0, 1
#la $a0, $s5
#la $v0, 4
#lw $a0, s4
#last system call of the program will be very last instruction
li $v0, 10
syscall
string mips base review
string mips base review
edited Dec 11 '18 at 18:32
halfer
14.3k758109
14.3k758109
asked Nov 12 '18 at 15:57
Eva Achim
64
64
"I get errors in my code." and "it seems to not be working." are not good problem descriptions. What exactly are the errors, and where exactly do they occur? Also, the code appears to be targeting a simulator like SPIM or MARS, which have fairly decent debugging features built in (e.g. single-stepping, breakpoints, register/memory viewer). What have you done in terms of analyzing the runtime behavior of your code?
– Michael
Nov 12 '18 at 16:01
Ok. So basically, it is not an error from mips. What I mean by that is that if I try to convert 12AB to base 33, it is not working. It just keeps it at 12AB. Also, I don't know for sure if the string to int conversion is actually working. Can you please help?
– Eva Achim
Nov 12 '18 at 16:03
Alright. Then use the simulator to single-step through the conversion code and verify that the result of each step is what you expect.
– Michael
Nov 12 '18 at 16:06
I tried doing that but I am using QTSpim and I don't think it has that feature. Can you please advise me on how to fix/improve my code?
– Eva Achim
Nov 12 '18 at 16:16
Sure it does. You can set breakpoints by right-clicking in the code window, and you can single-step with the F10 key.
– Michael
Nov 12 '18 at 16:17
|
show 1 more comment
"I get errors in my code." and "it seems to not be working." are not good problem descriptions. What exactly are the errors, and where exactly do they occur? Also, the code appears to be targeting a simulator like SPIM or MARS, which have fairly decent debugging features built in (e.g. single-stepping, breakpoints, register/memory viewer). What have you done in terms of analyzing the runtime behavior of your code?
– Michael
Nov 12 '18 at 16:01
Ok. So basically, it is not an error from mips. What I mean by that is that if I try to convert 12AB to base 33, it is not working. It just keeps it at 12AB. Also, I don't know for sure if the string to int conversion is actually working. Can you please help?
– Eva Achim
Nov 12 '18 at 16:03
Alright. Then use the simulator to single-step through the conversion code and verify that the result of each step is what you expect.
– Michael
Nov 12 '18 at 16:06
I tried doing that but I am using QTSpim and I don't think it has that feature. Can you please advise me on how to fix/improve my code?
– Eva Achim
Nov 12 '18 at 16:16
Sure it does. You can set breakpoints by right-clicking in the code window, and you can single-step with the F10 key.
– Michael
Nov 12 '18 at 16:17
"I get errors in my code." and "it seems to not be working." are not good problem descriptions. What exactly are the errors, and where exactly do they occur? Also, the code appears to be targeting a simulator like SPIM or MARS, which have fairly decent debugging features built in (e.g. single-stepping, breakpoints, register/memory viewer). What have you done in terms of analyzing the runtime behavior of your code?
– Michael
Nov 12 '18 at 16:01
"I get errors in my code." and "it seems to not be working." are not good problem descriptions. What exactly are the errors, and where exactly do they occur? Also, the code appears to be targeting a simulator like SPIM or MARS, which have fairly decent debugging features built in (e.g. single-stepping, breakpoints, register/memory viewer). What have you done in terms of analyzing the runtime behavior of your code?
– Michael
Nov 12 '18 at 16:01
Ok. So basically, it is not an error from mips. What I mean by that is that if I try to convert 12AB to base 33, it is not working. It just keeps it at 12AB. Also, I don't know for sure if the string to int conversion is actually working. Can you please help?
– Eva Achim
Nov 12 '18 at 16:03
Ok. So basically, it is not an error from mips. What I mean by that is that if I try to convert 12AB to base 33, it is not working. It just keeps it at 12AB. Also, I don't know for sure if the string to int conversion is actually working. Can you please help?
– Eva Achim
Nov 12 '18 at 16:03
Alright. Then use the simulator to single-step through the conversion code and verify that the result of each step is what you expect.
– Michael
Nov 12 '18 at 16:06
Alright. Then use the simulator to single-step through the conversion code and verify that the result of each step is what you expect.
– Michael
Nov 12 '18 at 16:06
I tried doing that but I am using QTSpim and I don't think it has that feature. Can you please advise me on how to fix/improve my code?
– Eva Achim
Nov 12 '18 at 16:16
I tried doing that but I am using QTSpim and I don't think it has that feature. Can you please advise me on how to fix/improve my code?
– Eva Achim
Nov 12 '18 at 16:16
Sure it does. You can set breakpoints by right-clicking in the code window, and you can single-step with the F10 key.
– Michael
Nov 12 '18 at 16:17
Sure it does. You can set breakpoints by right-clicking in the code window, and you can single-step with the F10 key.
– Michael
Nov 12 '18 at 16:17
|
show 1 more comment
1 Answer
1
active
oldest
votes
For starters:
lb $s1, 1($a0) #last digit
lb $s2 2($a0) #third
lb $s3 3($a0) #second digit
lb $s4, 4($a0) #first digit
lb $t0, 0($a0) #checks for n
You have a 4 character string in a0 - lets assume it was types ABCD
So:
0($a0) will be A
1($a0) will be B
2($a0) will be C
3($a0) will be D
Next assuming s1 is 'A'
Label1:
blt $s1, $t2, L1 # 65
blt $s1, $t5, L2 # 97
bgt $s1, $t6, L3 # 96
L1:
addi $s1, $s1, -48 #subtracts 48 from $s1 which is 48 to get int from 0 to 9
L2:
addi $s1, $s1, -55 #gets values from 10 to 33
L3:
addi $s1, $s1, -87 #gets values from 10 to 33 for small caps
'A' is 65 so will jump to L2, subtract -55 so not 10, then fall into L3 and subtract 87 to make -77.
If it was '9' (57) instead of 'A' it would go to L1, subtract 48, fall to L2, subtract 55, fall to L3, subtract 87.
So for each letter, check, something more like this should occur:
L1:
addi $s1, $s1, -48 #subtracts 48 from $s1 which is 48 to get int from 0 to 9
j DoneL13
L2:
addi $s1, $s1, -55 #gets values from 10 to 33
j DoneL13
L3:
addi $s1, $s1, -87 #gets values from 10 to 33 for small caps
DoneL13:
Finally you have some sys calls - not sure what they are mean to do do, but am guessing it magically meant to be knowing you want to print the value in s5 ?
Yeah, I am meant to print that after conversion to base 10. Thanks for help. I am still a bit confused with why I am not getting my conversion right.
– Eva Achim
Nov 12 '18 at 18:21
Can you please tell me how I could fix it?
– Eva Achim
Nov 12 '18 at 18:27
at the very least you need to update the L1-L3 statements to not run each other ie: L1 should do the L1 stuff and not do L2 etc.
– lostbard
Nov 12 '18 at 18:37
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265789%2fmips-code-for-conversion-of-string-of-characters-to-base-10-from-base-33%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
For starters:
lb $s1, 1($a0) #last digit
lb $s2 2($a0) #third
lb $s3 3($a0) #second digit
lb $s4, 4($a0) #first digit
lb $t0, 0($a0) #checks for n
You have a 4 character string in a0 - lets assume it was types ABCD
So:
0($a0) will be A
1($a0) will be B
2($a0) will be C
3($a0) will be D
Next assuming s1 is 'A'
Label1:
blt $s1, $t2, L1 # 65
blt $s1, $t5, L2 # 97
bgt $s1, $t6, L3 # 96
L1:
addi $s1, $s1, -48 #subtracts 48 from $s1 which is 48 to get int from 0 to 9
L2:
addi $s1, $s1, -55 #gets values from 10 to 33
L3:
addi $s1, $s1, -87 #gets values from 10 to 33 for small caps
'A' is 65 so will jump to L2, subtract -55 so not 10, then fall into L3 and subtract 87 to make -77.
If it was '9' (57) instead of 'A' it would go to L1, subtract 48, fall to L2, subtract 55, fall to L3, subtract 87.
So for each letter, check, something more like this should occur:
L1:
addi $s1, $s1, -48 #subtracts 48 from $s1 which is 48 to get int from 0 to 9
j DoneL13
L2:
addi $s1, $s1, -55 #gets values from 10 to 33
j DoneL13
L3:
addi $s1, $s1, -87 #gets values from 10 to 33 for small caps
DoneL13:
Finally you have some sys calls - not sure what they are mean to do do, but am guessing it magically meant to be knowing you want to print the value in s5 ?
Yeah, I am meant to print that after conversion to base 10. Thanks for help. I am still a bit confused with why I am not getting my conversion right.
– Eva Achim
Nov 12 '18 at 18:21
Can you please tell me how I could fix it?
– Eva Achim
Nov 12 '18 at 18:27
at the very least you need to update the L1-L3 statements to not run each other ie: L1 should do the L1 stuff and not do L2 etc.
– lostbard
Nov 12 '18 at 18:37
add a comment |
For starters:
lb $s1, 1($a0) #last digit
lb $s2 2($a0) #third
lb $s3 3($a0) #second digit
lb $s4, 4($a0) #first digit
lb $t0, 0($a0) #checks for n
You have a 4 character string in a0 - lets assume it was types ABCD
So:
0($a0) will be A
1($a0) will be B
2($a0) will be C
3($a0) will be D
Next assuming s1 is 'A'
Label1:
blt $s1, $t2, L1 # 65
blt $s1, $t5, L2 # 97
bgt $s1, $t6, L3 # 96
L1:
addi $s1, $s1, -48 #subtracts 48 from $s1 which is 48 to get int from 0 to 9
L2:
addi $s1, $s1, -55 #gets values from 10 to 33
L3:
addi $s1, $s1, -87 #gets values from 10 to 33 for small caps
'A' is 65 so will jump to L2, subtract -55 so not 10, then fall into L3 and subtract 87 to make -77.
If it was '9' (57) instead of 'A' it would go to L1, subtract 48, fall to L2, subtract 55, fall to L3, subtract 87.
So for each letter, check, something more like this should occur:
L1:
addi $s1, $s1, -48 #subtracts 48 from $s1 which is 48 to get int from 0 to 9
j DoneL13
L2:
addi $s1, $s1, -55 #gets values from 10 to 33
j DoneL13
L3:
addi $s1, $s1, -87 #gets values from 10 to 33 for small caps
DoneL13:
Finally you have some sys calls - not sure what they are mean to do do, but am guessing it magically meant to be knowing you want to print the value in s5 ?
Yeah, I am meant to print that after conversion to base 10. Thanks for help. I am still a bit confused with why I am not getting my conversion right.
– Eva Achim
Nov 12 '18 at 18:21
Can you please tell me how I could fix it?
– Eva Achim
Nov 12 '18 at 18:27
at the very least you need to update the L1-L3 statements to not run each other ie: L1 should do the L1 stuff and not do L2 etc.
– lostbard
Nov 12 '18 at 18:37
add a comment |
For starters:
lb $s1, 1($a0) #last digit
lb $s2 2($a0) #third
lb $s3 3($a0) #second digit
lb $s4, 4($a0) #first digit
lb $t0, 0($a0) #checks for n
You have a 4 character string in a0 - lets assume it was types ABCD
So:
0($a0) will be A
1($a0) will be B
2($a0) will be C
3($a0) will be D
Next assuming s1 is 'A'
Label1:
blt $s1, $t2, L1 # 65
blt $s1, $t5, L2 # 97
bgt $s1, $t6, L3 # 96
L1:
addi $s1, $s1, -48 #subtracts 48 from $s1 which is 48 to get int from 0 to 9
L2:
addi $s1, $s1, -55 #gets values from 10 to 33
L3:
addi $s1, $s1, -87 #gets values from 10 to 33 for small caps
'A' is 65 so will jump to L2, subtract -55 so not 10, then fall into L3 and subtract 87 to make -77.
If it was '9' (57) instead of 'A' it would go to L1, subtract 48, fall to L2, subtract 55, fall to L3, subtract 87.
So for each letter, check, something more like this should occur:
L1:
addi $s1, $s1, -48 #subtracts 48 from $s1 which is 48 to get int from 0 to 9
j DoneL13
L2:
addi $s1, $s1, -55 #gets values from 10 to 33
j DoneL13
L3:
addi $s1, $s1, -87 #gets values from 10 to 33 for small caps
DoneL13:
Finally you have some sys calls - not sure what they are mean to do do, but am guessing it magically meant to be knowing you want to print the value in s5 ?
For starters:
lb $s1, 1($a0) #last digit
lb $s2 2($a0) #third
lb $s3 3($a0) #second digit
lb $s4, 4($a0) #first digit
lb $t0, 0($a0) #checks for n
You have a 4 character string in a0 - lets assume it was types ABCD
So:
0($a0) will be A
1($a0) will be B
2($a0) will be C
3($a0) will be D
Next assuming s1 is 'A'
Label1:
blt $s1, $t2, L1 # 65
blt $s1, $t5, L2 # 97
bgt $s1, $t6, L3 # 96
L1:
addi $s1, $s1, -48 #subtracts 48 from $s1 which is 48 to get int from 0 to 9
L2:
addi $s1, $s1, -55 #gets values from 10 to 33
L3:
addi $s1, $s1, -87 #gets values from 10 to 33 for small caps
'A' is 65 so will jump to L2, subtract -55 so not 10, then fall into L3 and subtract 87 to make -77.
If it was '9' (57) instead of 'A' it would go to L1, subtract 48, fall to L2, subtract 55, fall to L3, subtract 87.
So for each letter, check, something more like this should occur:
L1:
addi $s1, $s1, -48 #subtracts 48 from $s1 which is 48 to get int from 0 to 9
j DoneL13
L2:
addi $s1, $s1, -55 #gets values from 10 to 33
j DoneL13
L3:
addi $s1, $s1, -87 #gets values from 10 to 33 for small caps
DoneL13:
Finally you have some sys calls - not sure what they are mean to do do, but am guessing it magically meant to be knowing you want to print the value in s5 ?
edited Nov 12 '18 at 18:42
answered Nov 12 '18 at 17:47
lostbard
3,0631311
3,0631311
Yeah, I am meant to print that after conversion to base 10. Thanks for help. I am still a bit confused with why I am not getting my conversion right.
– Eva Achim
Nov 12 '18 at 18:21
Can you please tell me how I could fix it?
– Eva Achim
Nov 12 '18 at 18:27
at the very least you need to update the L1-L3 statements to not run each other ie: L1 should do the L1 stuff and not do L2 etc.
– lostbard
Nov 12 '18 at 18:37
add a comment |
Yeah, I am meant to print that after conversion to base 10. Thanks for help. I am still a bit confused with why I am not getting my conversion right.
– Eva Achim
Nov 12 '18 at 18:21
Can you please tell me how I could fix it?
– Eva Achim
Nov 12 '18 at 18:27
at the very least you need to update the L1-L3 statements to not run each other ie: L1 should do the L1 stuff and not do L2 etc.
– lostbard
Nov 12 '18 at 18:37
Yeah, I am meant to print that after conversion to base 10. Thanks for help. I am still a bit confused with why I am not getting my conversion right.
– Eva Achim
Nov 12 '18 at 18:21
Yeah, I am meant to print that after conversion to base 10. Thanks for help. I am still a bit confused with why I am not getting my conversion right.
– Eva Achim
Nov 12 '18 at 18:21
Can you please tell me how I could fix it?
– Eva Achim
Nov 12 '18 at 18:27
Can you please tell me how I could fix it?
– Eva Achim
Nov 12 '18 at 18:27
at the very least you need to update the L1-L3 statements to not run each other ie: L1 should do the L1 stuff and not do L2 etc.
– lostbard
Nov 12 '18 at 18:37
at the very least you need to update the L1-L3 statements to not run each other ie: L1 should do the L1 stuff and not do L2 etc.
– lostbard
Nov 12 '18 at 18:37
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53265789%2fmips-code-for-conversion-of-string-of-characters-to-base-10-from-base-33%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
"I get errors in my code." and "it seems to not be working." are not good problem descriptions. What exactly are the errors, and where exactly do they occur? Also, the code appears to be targeting a simulator like SPIM or MARS, which have fairly decent debugging features built in (e.g. single-stepping, breakpoints, register/memory viewer). What have you done in terms of analyzing the runtime behavior of your code?
– Michael
Nov 12 '18 at 16:01
Ok. So basically, it is not an error from mips. What I mean by that is that if I try to convert 12AB to base 33, it is not working. It just keeps it at 12AB. Also, I don't know for sure if the string to int conversion is actually working. Can you please help?
– Eva Achim
Nov 12 '18 at 16:03
Alright. Then use the simulator to single-step through the conversion code and verify that the result of each step is what you expect.
– Michael
Nov 12 '18 at 16:06
I tried doing that but I am using QTSpim and I don't think it has that feature. Can you please advise me on how to fix/improve my code?
– Eva Achim
Nov 12 '18 at 16:16
Sure it does. You can set breakpoints by right-clicking in the code window, and you can single-step with the F10 key.
– Michael
Nov 12 '18 at 16:17