1

I am really struggling with the wording of a project I am working on. For mips they are requesting that I take in two arguments before launch. I store both of them into .word memory addresses. However, it then asks me to treat them as though they are .asciiz files and dissect it character by character in a way that spits back only an integer (and if it's value is negative).

The $a0 register will contain the number of arguments passed to your program. The $a1 register contains the starting address of an array of strings. Each element in the array is an item that you specified on the command line. The labels arg1 and arg2 each store the starting address of a null-terminated sequence of ASCII characters.

My question is how do I properly extract and use the address to get to this sequence of characters they are discussing. Furthermore, where should I store it?

.data
     align 2
     arg1: .word 0
     arg2: .word 0
.macro load_args
     lw $t0,0($a1)
     sw $t0, arg1
     lw $t1,4($a1)
     sw $t1, arg2
.end_macro
.text
.globl main
main:
     load_args()
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Matt
  • 11
  • 2
  • What is the actual wording of your assignment? Are you storing *pointers* into `.word` locations? Also, surely it doesn't say "`.asciiz` files", because string constants aren't files. (They might be file *names*?) Also, MIPS programming obviously has nothing to do with `[x86]`, don't add unrelated tags. – Peter Cordes Mar 19 '18 at 03:00
  • Also, your last sentence says "Here is my code", but there's no code. – Peter Cordes Mar 19 '18 at 03:03
  • Anyway, a string doesn't fit in a `.word` unless the string is at most 4 bytes long (because that's the MIPS word size). Either your strings are always short, or you're doing it wrong, or you're misreading the assignment. – Peter Cordes Mar 19 '18 at 03:04
  • When I run the macro load_args (built into MIPS) I do this to set the two words: – Matt Mar 19 '18 at 03:16
  • lw $t0,0($a1) sw $t0, arg1 lw $t1,4($a1) sw $t1, arg2 – Matt Mar 19 '18 at 03:17
  • [edit] your question with your code and the assignment text. Instead of a messy question + comments, put everything in the question. See [ask]. – Peter Cordes Mar 19 '18 at 03:24
  • @PeterCordes Okay I altered it. By the way I just wanted to say thank you for trying to help me I really appreciate it. Is this formatting okay? (I am trying my best this is my first time actually posting on here) – Matt Mar 19 '18 at 03:38
  • That's better formatting, and paragraphs are much better than a wall of text. Assuming the middle paragraph is a quote from your assignment, yes, you have *pointers* to strings, so they're addresses, not string data directly. There's no reason to store those addresses into static `.word` locations; just keep them in registers (and write comments to keep track of what's where). Adding a bunch of load/store instructions to keep static memory in sync with registers is just a potential source of bugs and more to wade through while debugging. – Peter Cordes Mar 19 '18 at 05:18
  • Looks like your function is called like `main(int argc, char *argv[])`. So `$a1` points to an array of words, where each word is a *pointer* to a 0-terminated ASCII string. At least that's what I assume they mean. So after `load_args`, `$t0` and `$t1` hold `argv[0]` and `argv[1]`, and dereferencing *those* (like `lb $t9, ($t0)`) will give you bytes from the strings. – Peter Cordes Mar 19 '18 at 05:22

0 Answers0