banner



How To Assign Hex Value To A Register Mips

1 Answer i

I'yard merely going to testify how this could exist washed in C, which should exist like shooting fish in a barrel enough for you to translate into MIPS associates:

                // Assume that data from the file has been read into a char *buffer // Assume that there'south an int32_t *values where the values volition exist stored  while (bufferBytes) {     c = *buffer++;     bufferBytes--;      // Consume the "0x" prefix, and so read digits until whitespace is found     if (c == '0' && prefixBytes == 0) {         prefixBytes++;     } else if (c == 'x' && prefixBytes == 1) {         prefixBytes++;     } else {         if (c == ' ' || c == '\t' || c == '\northward' || c == '\r') {             if (prefixBytes == two) {                 // Reached the finish of a number. Store it and start over                 prefixBytes = 0;                 *values++ = currValue;                 currValue = 0;             } else if (prefixBytes == 0) {                 // IGNORE (whitespace in betwixt numbers)             } else {                 // ERROR             }         } else if (prefixBytes == 2) {             if (c >= '0' && c <= 'nine') {                 c -= '0';             } else if (c >= 'a' && c <= 'f') {                 c -= ('a'-10);             } else if (c >= 'A' && c <= 'F') {                 c -= ('A'-ten);             } else {                 // ERROR             }             currValue = (currValue << 4) | c;         } else {             // Error         }     } } // Store any pending value that was left when reaching the cease of the buffer if (prefixBytes == 2) {     *values++ = currValue; }                              

answered May 23, 2013 at 8:21

user avatar

3

  • It is not easily translatable, a grapheme in hexadecimal is 4 $.25. An ascii graphic symbol is 8 $.25. Since yous do non deal with registers in C language a conversion code may function well in C. However if you try to apply this code to MIPS assembly then y'all accept to deal with registers. A annals is 32 bit and can agree a hexadecimal value of 8 characters. When you read them as ascii characters you lot basically put 8 hexadecimal characters into 2 registers and since the minimum data you lot can achieve is a byte this makes the conversion totally dissimilar from C language.

    May 23, 2013 at eleven:05

  • When I asked you earlier in a annotate you lot said that the numbers were stored in the file as strings. Each graphic symbol in the string will be one byte (assuming ASCII encoding), e.1000. '0', 'x', 'five' and and so on (which yous tin can read with the LBU education). I maintain that it'd exist fairly easy to translate this into MIPS assembly, you just take to spend some time on it.

    May 23, 2013 at xi:24

  • @BerkayDincer: Whatever legal C-code is hands translatable into MIPS by any MIPS C-compiler, or indeed by any competent MIPS assembly programmer. This includes Michael's conversion code.

    May 24, 2013 at 0:40

Non the answer you're looking for? Scan other questions tagged assembly hex mips or ask your ain question.

Source: https://stackoverflow.com/questions/16693274/mips-assembly-reading-from-a-file-with-hexadecimal-values

Posted by: sargentproutiting1980.blogspot.com

0 Response to "How To Assign Hex Value To A Register Mips"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel