简体   繁体   中英

MIPS Convert binary to ascii string

I was given a 32 bit binary number and told to convert to mips instruction, integer, and four-character ASCII string. I converted to dec and instruction, no prob., but ascii string giving me trouble. I have a table that provides ascii values, but I cannot get a four character word from this number:

0000 0010 0001 0001 0100 0000 0010 0000

I would really like if someone could give brief explanation on how to convert, the number should return 4 characters that should have some meaning. I don't need any code, just by hand conversion.

To see if I am misinterpreting the questions, here it is in its entirety:

A 32-bit word has no inherent meaning and can be represented in a number of equally valid ways. Decode the following into the binary representation, the instruction, the positive integer, and the four-character ASCII string.

0000 0010 0001 0001 0100 0000 0010 0000

ASCII string?

Instruction? add $t0, $s0, $s1

Positive integer? 34,684,960

The binary rep. was given, the instruction/int I entered.

From what I understand, you were told to turn each 8 bits to a single ascii character, but the first 2 bytes are "not printable" (2 is ascii for "Start of the text" and 17 is ascii for "Device Control 1"), so it's not your fault if the output seems off, just simply change the number to see if it's working well.

fe:

0100 0001 0100 1100 0100 0101 0101 1000

With simple coding we have the answer as to what those bits represent (spoiler alert: it's my name :) )

.text
main:

li  $v0, 5
syscall


andi    $t1, $v0, 0xFF000000
srl $t1, $t1, 24

andi    $t2, $v0, 0x00FF0000
srl $t2, $t2, 16

andi    $t3, $v0, 0x0000FF00
srl $t3, $t3, 8

andi    $t4, $v0, 0x000000FF

li  $v0, 11

la  $a0, ($t1)
syscall

la  $a0, ($t2)
syscall

la  $a0, ($t3)
syscall

la  $a0, ($t4)
syscall


li  $v0, 10
syscall

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM