Mips, hexadecimal to binary conversion
I've been trying to do some conversion in mips assembly to try and turn hexadecimals to binary but I'm not sure how I would implement it. Here's the fragment of my code that's relevant to the conversion
.data
operand: .asciiz "nEnter correct value to be converted: "
result: .asciiz "nYour result is: "
hexstore: .space 8
.globl main
.text
main:
li $v0, 4 #display welcome message
la $a0, welcome
syscall
li $v0, 5 #get int for type of operation
syscall
move $t0, $v0 #store result in t0, now compare t0 to t1 in order to get a branching result
addi $t1, $zero, 0 #set t1 to 0
addi $t1, $t1, 1 #set t1 to 1
beq $t0, $t1, hexatobinary #jump to hextobinary if t0 is 1
hexatobinary:
la $a0, operand #prompt for input
li $v0, 4
syscall
li $v0, 5 #integer input
syscall
add $t0, $v0, $zero #Move to t0
addi $t1, $zero, 0
sw $t0, hexstore($t1)
So pretty much my thought process is to store the user inputted hex value, then try and read one bit at a time in a for loop and through 16 branches putting the correct binary values in a register, then after the loop is complete I would print the register and the conversion would complete. Is this the correct implementation? What code would I need in order to actually do that? Could i convert binary to hex through the same process? Thanks!
assembly low-level mips32
add a comment |
I've been trying to do some conversion in mips assembly to try and turn hexadecimals to binary but I'm not sure how I would implement it. Here's the fragment of my code that's relevant to the conversion
.data
operand: .asciiz "nEnter correct value to be converted: "
result: .asciiz "nYour result is: "
hexstore: .space 8
.globl main
.text
main:
li $v0, 4 #display welcome message
la $a0, welcome
syscall
li $v0, 5 #get int for type of operation
syscall
move $t0, $v0 #store result in t0, now compare t0 to t1 in order to get a branching result
addi $t1, $zero, 0 #set t1 to 0
addi $t1, $t1, 1 #set t1 to 1
beq $t0, $t1, hexatobinary #jump to hextobinary if t0 is 1
hexatobinary:
la $a0, operand #prompt for input
li $v0, 4
syscall
li $v0, 5 #integer input
syscall
add $t0, $v0, $zero #Move to t0
addi $t1, $zero, 0
sw $t0, hexstore($t1)
So pretty much my thought process is to store the user inputted hex value, then try and read one bit at a time in a for loop and through 16 branches putting the correct binary values in a register, then after the loop is complete I would print the register and the conversion would complete. Is this the correct implementation? What code would I need in order to actually do that? Could i convert binary to hex through the same process? Thanks!
assembly low-level mips32
The read-int system call (v0=5) already takes care of converting from an ASCII hex string to a binary integer in a register. (If it supports hex at all?) Hex is a text / human-readable serialization format for numbers. Anyway yes, then you just need to isolate each binary bit in a register into0/1(usually with a shift / AND) and convert to ASCII'0'/'1'. (Or use a print-int function to do that last part for you.)
– Peter Cordes
Nov 15 '18 at 20:50
add a comment |
I've been trying to do some conversion in mips assembly to try and turn hexadecimals to binary but I'm not sure how I would implement it. Here's the fragment of my code that's relevant to the conversion
.data
operand: .asciiz "nEnter correct value to be converted: "
result: .asciiz "nYour result is: "
hexstore: .space 8
.globl main
.text
main:
li $v0, 4 #display welcome message
la $a0, welcome
syscall
li $v0, 5 #get int for type of operation
syscall
move $t0, $v0 #store result in t0, now compare t0 to t1 in order to get a branching result
addi $t1, $zero, 0 #set t1 to 0
addi $t1, $t1, 1 #set t1 to 1
beq $t0, $t1, hexatobinary #jump to hextobinary if t0 is 1
hexatobinary:
la $a0, operand #prompt for input
li $v0, 4
syscall
li $v0, 5 #integer input
syscall
add $t0, $v0, $zero #Move to t0
addi $t1, $zero, 0
sw $t0, hexstore($t1)
So pretty much my thought process is to store the user inputted hex value, then try and read one bit at a time in a for loop and through 16 branches putting the correct binary values in a register, then after the loop is complete I would print the register and the conversion would complete. Is this the correct implementation? What code would I need in order to actually do that? Could i convert binary to hex through the same process? Thanks!
assembly low-level mips32
I've been trying to do some conversion in mips assembly to try and turn hexadecimals to binary but I'm not sure how I would implement it. Here's the fragment of my code that's relevant to the conversion
.data
operand: .asciiz "nEnter correct value to be converted: "
result: .asciiz "nYour result is: "
hexstore: .space 8
.globl main
.text
main:
li $v0, 4 #display welcome message
la $a0, welcome
syscall
li $v0, 5 #get int for type of operation
syscall
move $t0, $v0 #store result in t0, now compare t0 to t1 in order to get a branching result
addi $t1, $zero, 0 #set t1 to 0
addi $t1, $t1, 1 #set t1 to 1
beq $t0, $t1, hexatobinary #jump to hextobinary if t0 is 1
hexatobinary:
la $a0, operand #prompt for input
li $v0, 4
syscall
li $v0, 5 #integer input
syscall
add $t0, $v0, $zero #Move to t0
addi $t1, $zero, 0
sw $t0, hexstore($t1)
So pretty much my thought process is to store the user inputted hex value, then try and read one bit at a time in a for loop and through 16 branches putting the correct binary values in a register, then after the loop is complete I would print the register and the conversion would complete. Is this the correct implementation? What code would I need in order to actually do that? Could i convert binary to hex through the same process? Thanks!
assembly low-level mips32
assembly low-level mips32
asked Nov 15 '18 at 20:40
MarcelMarcel
1
1
The read-int system call (v0=5) already takes care of converting from an ASCII hex string to a binary integer in a register. (If it supports hex at all?) Hex is a text / human-readable serialization format for numbers. Anyway yes, then you just need to isolate each binary bit in a register into0/1(usually with a shift / AND) and convert to ASCII'0'/'1'. (Or use a print-int function to do that last part for you.)
– Peter Cordes
Nov 15 '18 at 20:50
add a comment |
The read-int system call (v0=5) already takes care of converting from an ASCII hex string to a binary integer in a register. (If it supports hex at all?) Hex is a text / human-readable serialization format for numbers. Anyway yes, then you just need to isolate each binary bit in a register into0/1(usually with a shift / AND) and convert to ASCII'0'/'1'. (Or use a print-int function to do that last part for you.)
– Peter Cordes
Nov 15 '18 at 20:50
The read-int system call (v0=5) already takes care of converting from an ASCII hex string to a binary integer in a register. (If it supports hex at all?) Hex is a text / human-readable serialization format for numbers. Anyway yes, then you just need to isolate each binary bit in a register into
0/1 (usually with a shift / AND) and convert to ASCII '0' / '1'. (Or use a print-int function to do that last part for you.)– Peter Cordes
Nov 15 '18 at 20:50
The read-int system call (v0=5) already takes care of converting from an ASCII hex string to a binary integer in a register. (If it supports hex at all?) Hex is a text / human-readable serialization format for numbers. Anyway yes, then you just need to isolate each binary bit in a register into
0/1 (usually with a shift / AND) and convert to ASCII '0' / '1'. (Or use a print-int function to do that last part for you.)– Peter Cordes
Nov 15 '18 at 20:50
add a comment |
0
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',
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%2f53327577%2fmips-hexadecimal-to-binary-conversion%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
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%2f53327577%2fmips-hexadecimal-to-binary-conversion%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
The read-int system call (v0=5) already takes care of converting from an ASCII hex string to a binary integer in a register. (If it supports hex at all?) Hex is a text / human-readable serialization format for numbers. Anyway yes, then you just need to isolate each binary bit in a register into
0/1(usually with a shift / AND) and convert to ASCII'0'/'1'. (Or use a print-int function to do that last part for you.)– Peter Cordes
Nov 15 '18 at 20:50