1

I have to write two programs in assembly for class and I was just wondering whether you guys could help me understand what's being asked of me / any general tips on how to go about it.

The first problem reads:

Write your own routine to convert an integer into a hexadecimal ascii string placing the result into a sequence of eight characters in a buffer. When your routine is called, $a0 will contain the number to format, $a1 will contain a pointer to the location in memory where the ASCII representation is to be placed, because hexadecimals digits correspond to groups of four binary digits, you can generate the digits from left to right. Don't worry about negative values. You can convert individual decimal digits to the corresponding ASCII charcter by adding the value of an ASCII zero character (0x30 or '0) to the integer digit.

I bolded the sections I'm confused on. Can anyone explain to me how a point works exactly & how I would go about utilizing it in this situation? And is the second bolded part literally just telling me how to convert decimals to hex? Meaning to convert, my code would look something like:

add $a1,$a0, '0

Write a general purpose routine to format integers into a string buffer in any number base between 2 and 36. $a0 should contain the number to format, $a1 a pointer to the string buffer, $a2 the base between 2 and 36 to use for this conversion and $a3 the size of the buffer including the terminal nul. You will need to generate the digits from right to left, using division by the base with the remainder giving the next digit, while the quotient holds the balance of the number. When the quotient returns zero, it will signal the end of the loop. Space fill any remaining locations in the buffer. Negative numbers should be handled by placing a minus sign to the left of the most significant digit. To handle negative numbers, you will need to take the absolute value of the remainders, while retaining a copy of the original number to hold the sign. Should the number not fit into the supplied buffer, fill the buffer with # character.

This one I'm honestly confused about the overall question and what it's asking of from me. Again the bolded parts here emphasize the parts I'm especially stuck on.

Thanks in advance for any help you can offer! I'm using MIPSym btw, if that's necessary info.

conejo
  • 11
  • 3
  • `add $a1,$a0, '0'` overwrites the pointer, it doesn't dereference the pointer in `$a1` and store to memory. Use `$t0` as a destination or something, and use an `sb` instruction. – Peter Cordes Sep 17 '18 at 23:26
  • computer memory is like street of houses... each house has postal number (at least in our country, so by using address like "Superstreet 35" the particular house on that street is addressed). In computer memory each "house" is one byte (8 bits, or when you use them as unsigned integer, the range 0..255 can be expressed by all variations of 8 bit pattern). And every next house has +1 address. The "pointer/memory address" is the address of memory cell (house), so you are given in `a1` "superstreet 35" as input, and you are expected to store first char into that house, next char into 36, etc.. – Ped7g Sep 18 '18 at 13:40
  • (you can do `addi $a1, $a1, 1` to increment current address to point to the next byte, or `addi $a1, $a1, 4` to make it point to the next "word" would you operate with consecutive words in memory - as MIPS \[32 bit\] word does occupy four bytes when stored in memory ... to store value inside the memory cell, you can use one of the "store" instructions, like `sb` (relevant to your ASCII characters) or `sw` (when working with whole "words")) – Ped7g Sep 18 '18 at 13:41

0 Answers0