How to write int to string in Mips











up vote
1
down vote

favorite












I'm asking a user for input and I want to replace each character of the word by the number of uppercase characters in this word



Example:
Input: AaAA
output: 3333 (4 letters - 3 uppercase)



The part for counting upercase letters in a word works (stored in $t5)



However I cannot replace e.g "3333" with "AaAA". I'm trying to do it using sb in word_replace section. In my output I can see boxes instead of numbers.



Here is my code:



.data
prompt: .asciiz "Enter a string: "
msgout: .asciiz "Output string: "
input: .space 256
output: .space 256
.text
.globl main

main:
li $v0, 4 # Print enter a string prompt
la $a0, prompt
syscall

li $v0, 8 # Ask the user for the string they want to reverse
la $a0, input # We'll store it in 'input'
li $a1, 256 # Only 256 chars/bytes allowed
syscall

la $t2, ($a0) # t2 - input string

word:
li $t1, 0 # Normal counter
li $t5, 0 # Uppercase counter

word_countUppercase:
add $t3, $t2, $t1 # $t2 is the base address for our 'input' array, add loop index
lb $t4, 0($t3) # load a byte at a time according to counter

bltu $t4, ' ', word_prereplace # We found end of word

addi $t1, $t1, 1 # Advance our counter (i++)

bltu $t4, 'A', word_countUppercase
bgtu $t4, 'Z', word_countUppercase

addi $t5, $t5, 1 # Advance our counter (i++)
j word_countUppercase

word_prereplace:
la $t2, ($a0) # t2 - input string
li $t1, 0 # Normal counter

word_replace:
add $t3, $t2, $t1 # $t2 is the base address for our 'input' array, add loop index
lb $t4, 0($t3) # load a byte at a time according to counter

bltu $t4, ' ', exit # We found end of word

sb $t5, output($t1) # Overwrite this byte address in memory

addi $t1, $t1, 1 # Advance our counter (i++)
j word_replace


exit:
li $v0, 4 # Print msgout
la $a0, msgout
syscall

li $v0, 4 # Print the output string!
la $a0, output
syscall

li $v0, 10 # exit()
syscall









share|improve this question
























  • How is AaAA related to 3333?
    – wallyk
    Nov 10 at 18:22










  • There are 3 uppercase letters so 3 and there are 4 of them so 3333. Added more details in description.
    – sswwqqaa
    Nov 10 at 18:23








  • 3




    the character "3" has ASCII code 0x33 (51 decimal), so you have to do addi $t5, $t5, '0' (or addi $t5, $t5, 48 if your assembler does not support parsing ASCII characters in single quotes) before overwriting the word letters. Also this will work only up to count 9, for count 10 the +48 will produce value 58, which in ASCII encoding encodes character ':', etc... The "boxes" you see are "non-printable" (although it does print a box, so it's sort of printable) character mapped to value 3.
    – Ped7g
    Nov 10 at 19:09












  • Are you supposed to assume that the result will always be a single-digit number? So you never have to fill a long word with 1010101010... or something? If so then int->ASCII character is just addition or OR.
    – Peter Cordes
    Nov 10 at 19:18








  • 1




    well.. count mod 10 will always produce value in range 0..9, so that one will work with the trivial number->ASCII conversion by doing add/or 0x30. (i.e. for ABCDEFGHIJ it will produce 0000000000)
    – Ped7g
    Nov 10 at 19:21

















up vote
1
down vote

favorite












I'm asking a user for input and I want to replace each character of the word by the number of uppercase characters in this word



Example:
Input: AaAA
output: 3333 (4 letters - 3 uppercase)



The part for counting upercase letters in a word works (stored in $t5)



However I cannot replace e.g "3333" with "AaAA". I'm trying to do it using sb in word_replace section. In my output I can see boxes instead of numbers.



Here is my code:



.data
prompt: .asciiz "Enter a string: "
msgout: .asciiz "Output string: "
input: .space 256
output: .space 256
.text
.globl main

main:
li $v0, 4 # Print enter a string prompt
la $a0, prompt
syscall

li $v0, 8 # Ask the user for the string they want to reverse
la $a0, input # We'll store it in 'input'
li $a1, 256 # Only 256 chars/bytes allowed
syscall

la $t2, ($a0) # t2 - input string

word:
li $t1, 0 # Normal counter
li $t5, 0 # Uppercase counter

word_countUppercase:
add $t3, $t2, $t1 # $t2 is the base address for our 'input' array, add loop index
lb $t4, 0($t3) # load a byte at a time according to counter

bltu $t4, ' ', word_prereplace # We found end of word

addi $t1, $t1, 1 # Advance our counter (i++)

bltu $t4, 'A', word_countUppercase
bgtu $t4, 'Z', word_countUppercase

addi $t5, $t5, 1 # Advance our counter (i++)
j word_countUppercase

word_prereplace:
la $t2, ($a0) # t2 - input string
li $t1, 0 # Normal counter

word_replace:
add $t3, $t2, $t1 # $t2 is the base address for our 'input' array, add loop index
lb $t4, 0($t3) # load a byte at a time according to counter

bltu $t4, ' ', exit # We found end of word

sb $t5, output($t1) # Overwrite this byte address in memory

addi $t1, $t1, 1 # Advance our counter (i++)
j word_replace


exit:
li $v0, 4 # Print msgout
la $a0, msgout
syscall

li $v0, 4 # Print the output string!
la $a0, output
syscall

li $v0, 10 # exit()
syscall









share|improve this question
























  • How is AaAA related to 3333?
    – wallyk
    Nov 10 at 18:22










  • There are 3 uppercase letters so 3 and there are 4 of them so 3333. Added more details in description.
    – sswwqqaa
    Nov 10 at 18:23








  • 3




    the character "3" has ASCII code 0x33 (51 decimal), so you have to do addi $t5, $t5, '0' (or addi $t5, $t5, 48 if your assembler does not support parsing ASCII characters in single quotes) before overwriting the word letters. Also this will work only up to count 9, for count 10 the +48 will produce value 58, which in ASCII encoding encodes character ':', etc... The "boxes" you see are "non-printable" (although it does print a box, so it's sort of printable) character mapped to value 3.
    – Ped7g
    Nov 10 at 19:09












  • Are you supposed to assume that the result will always be a single-digit number? So you never have to fill a long word with 1010101010... or something? If so then int->ASCII character is just addition or OR.
    – Peter Cordes
    Nov 10 at 19:18








  • 1




    well.. count mod 10 will always produce value in range 0..9, so that one will work with the trivial number->ASCII conversion by doing add/or 0x30. (i.e. for ABCDEFGHIJ it will produce 0000000000)
    – Ped7g
    Nov 10 at 19:21















up vote
1
down vote

favorite









up vote
1
down vote

favorite











I'm asking a user for input and I want to replace each character of the word by the number of uppercase characters in this word



Example:
Input: AaAA
output: 3333 (4 letters - 3 uppercase)



The part for counting upercase letters in a word works (stored in $t5)



However I cannot replace e.g "3333" with "AaAA". I'm trying to do it using sb in word_replace section. In my output I can see boxes instead of numbers.



Here is my code:



.data
prompt: .asciiz "Enter a string: "
msgout: .asciiz "Output string: "
input: .space 256
output: .space 256
.text
.globl main

main:
li $v0, 4 # Print enter a string prompt
la $a0, prompt
syscall

li $v0, 8 # Ask the user for the string they want to reverse
la $a0, input # We'll store it in 'input'
li $a1, 256 # Only 256 chars/bytes allowed
syscall

la $t2, ($a0) # t2 - input string

word:
li $t1, 0 # Normal counter
li $t5, 0 # Uppercase counter

word_countUppercase:
add $t3, $t2, $t1 # $t2 is the base address for our 'input' array, add loop index
lb $t4, 0($t3) # load a byte at a time according to counter

bltu $t4, ' ', word_prereplace # We found end of word

addi $t1, $t1, 1 # Advance our counter (i++)

bltu $t4, 'A', word_countUppercase
bgtu $t4, 'Z', word_countUppercase

addi $t5, $t5, 1 # Advance our counter (i++)
j word_countUppercase

word_prereplace:
la $t2, ($a0) # t2 - input string
li $t1, 0 # Normal counter

word_replace:
add $t3, $t2, $t1 # $t2 is the base address for our 'input' array, add loop index
lb $t4, 0($t3) # load a byte at a time according to counter

bltu $t4, ' ', exit # We found end of word

sb $t5, output($t1) # Overwrite this byte address in memory

addi $t1, $t1, 1 # Advance our counter (i++)
j word_replace


exit:
li $v0, 4 # Print msgout
la $a0, msgout
syscall

li $v0, 4 # Print the output string!
la $a0, output
syscall

li $v0, 10 # exit()
syscall









share|improve this question















I'm asking a user for input and I want to replace each character of the word by the number of uppercase characters in this word



Example:
Input: AaAA
output: 3333 (4 letters - 3 uppercase)



The part for counting upercase letters in a word works (stored in $t5)



However I cannot replace e.g "3333" with "AaAA". I'm trying to do it using sb in word_replace section. In my output I can see boxes instead of numbers.



Here is my code:



.data
prompt: .asciiz "Enter a string: "
msgout: .asciiz "Output string: "
input: .space 256
output: .space 256
.text
.globl main

main:
li $v0, 4 # Print enter a string prompt
la $a0, prompt
syscall

li $v0, 8 # Ask the user for the string they want to reverse
la $a0, input # We'll store it in 'input'
li $a1, 256 # Only 256 chars/bytes allowed
syscall

la $t2, ($a0) # t2 - input string

word:
li $t1, 0 # Normal counter
li $t5, 0 # Uppercase counter

word_countUppercase:
add $t3, $t2, $t1 # $t2 is the base address for our 'input' array, add loop index
lb $t4, 0($t3) # load a byte at a time according to counter

bltu $t4, ' ', word_prereplace # We found end of word

addi $t1, $t1, 1 # Advance our counter (i++)

bltu $t4, 'A', word_countUppercase
bgtu $t4, 'Z', word_countUppercase

addi $t5, $t5, 1 # Advance our counter (i++)
j word_countUppercase

word_prereplace:
la $t2, ($a0) # t2 - input string
li $t1, 0 # Normal counter

word_replace:
add $t3, $t2, $t1 # $t2 is the base address for our 'input' array, add loop index
lb $t4, 0($t3) # load a byte at a time according to counter

bltu $t4, ' ', exit # We found end of word

sb $t5, output($t1) # Overwrite this byte address in memory

addi $t1, $t1, 1 # Advance our counter (i++)
j word_replace


exit:
li $v0, 4 # Print msgout
la $a0, msgout
syscall

li $v0, 4 # Print the output string!
la $a0, output
syscall

li $v0, 10 # exit()
syscall






assembly mips mars-simulator






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 20:34









Ped7g

12.9k21738




12.9k21738










asked Nov 10 at 18:21









sswwqqaa

5531314




5531314












  • How is AaAA related to 3333?
    – wallyk
    Nov 10 at 18:22










  • There are 3 uppercase letters so 3 and there are 4 of them so 3333. Added more details in description.
    – sswwqqaa
    Nov 10 at 18:23








  • 3




    the character "3" has ASCII code 0x33 (51 decimal), so you have to do addi $t5, $t5, '0' (or addi $t5, $t5, 48 if your assembler does not support parsing ASCII characters in single quotes) before overwriting the word letters. Also this will work only up to count 9, for count 10 the +48 will produce value 58, which in ASCII encoding encodes character ':', etc... The "boxes" you see are "non-printable" (although it does print a box, so it's sort of printable) character mapped to value 3.
    – Ped7g
    Nov 10 at 19:09












  • Are you supposed to assume that the result will always be a single-digit number? So you never have to fill a long word with 1010101010... or something? If so then int->ASCII character is just addition or OR.
    – Peter Cordes
    Nov 10 at 19:18








  • 1




    well.. count mod 10 will always produce value in range 0..9, so that one will work with the trivial number->ASCII conversion by doing add/or 0x30. (i.e. for ABCDEFGHIJ it will produce 0000000000)
    – Ped7g
    Nov 10 at 19:21




















  • How is AaAA related to 3333?
    – wallyk
    Nov 10 at 18:22










  • There are 3 uppercase letters so 3 and there are 4 of them so 3333. Added more details in description.
    – sswwqqaa
    Nov 10 at 18:23








  • 3




    the character "3" has ASCII code 0x33 (51 decimal), so you have to do addi $t5, $t5, '0' (or addi $t5, $t5, 48 if your assembler does not support parsing ASCII characters in single quotes) before overwriting the word letters. Also this will work only up to count 9, for count 10 the +48 will produce value 58, which in ASCII encoding encodes character ':', etc... The "boxes" you see are "non-printable" (although it does print a box, so it's sort of printable) character mapped to value 3.
    – Ped7g
    Nov 10 at 19:09












  • Are you supposed to assume that the result will always be a single-digit number? So you never have to fill a long word with 1010101010... or something? If so then int->ASCII character is just addition or OR.
    – Peter Cordes
    Nov 10 at 19:18








  • 1




    well.. count mod 10 will always produce value in range 0..9, so that one will work with the trivial number->ASCII conversion by doing add/or 0x30. (i.e. for ABCDEFGHIJ it will produce 0000000000)
    – Ped7g
    Nov 10 at 19:21


















How is AaAA related to 3333?
– wallyk
Nov 10 at 18:22




How is AaAA related to 3333?
– wallyk
Nov 10 at 18:22












There are 3 uppercase letters so 3 and there are 4 of them so 3333. Added more details in description.
– sswwqqaa
Nov 10 at 18:23






There are 3 uppercase letters so 3 and there are 4 of them so 3333. Added more details in description.
– sswwqqaa
Nov 10 at 18:23






3




3




the character "3" has ASCII code 0x33 (51 decimal), so you have to do addi $t5, $t5, '0' (or addi $t5, $t5, 48 if your assembler does not support parsing ASCII characters in single quotes) before overwriting the word letters. Also this will work only up to count 9, for count 10 the +48 will produce value 58, which in ASCII encoding encodes character ':', etc... The "boxes" you see are "non-printable" (although it does print a box, so it's sort of printable) character mapped to value 3.
– Ped7g
Nov 10 at 19:09






the character "3" has ASCII code 0x33 (51 decimal), so you have to do addi $t5, $t5, '0' (or addi $t5, $t5, 48 if your assembler does not support parsing ASCII characters in single quotes) before overwriting the word letters. Also this will work only up to count 9, for count 10 the +48 will produce value 58, which in ASCII encoding encodes character ':', etc... The "boxes" you see are "non-printable" (although it does print a box, so it's sort of printable) character mapped to value 3.
– Ped7g
Nov 10 at 19:09














Are you supposed to assume that the result will always be a single-digit number? So you never have to fill a long word with 1010101010... or something? If so then int->ASCII character is just addition or OR.
– Peter Cordes
Nov 10 at 19:18






Are you supposed to assume that the result will always be a single-digit number? So you never have to fill a long word with 1010101010... or something? If so then int->ASCII character is just addition or OR.
– Peter Cordes
Nov 10 at 19:18






1




1




well.. count mod 10 will always produce value in range 0..9, so that one will work with the trivial number->ASCII conversion by doing add/or 0x30. (i.e. for ABCDEFGHIJ it will produce 0000000000)
– Ped7g
Nov 10 at 19:21






well.. count mod 10 will always produce value in range 0..9, so that one will work with the trivial number->ASCII conversion by doing add/or 0x30. (i.e. for ABCDEFGHIJ it will produce 0000000000)
– Ped7g
Nov 10 at 19:21



















active

oldest

votes











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',
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
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242047%2fhow-to-write-int-to-string-in-mips%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242047%2fhow-to-write-int-to-string-in-mips%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Lugert, Oklahoma