The problem is that you can't think of assembly in the way you think in a high-level language. It's an entirely different world.
You don't have methods, you don't have loops. Conditional branching and jumping is all you have. Forget language-imposed execution control - you've returned to the land where GOTO is king. So like @deviantfan said, you're going to have to get comfortable with jal (jump and "link", aka save the PC in $ra) and jr $ra.
And you don't have arrays. You don't even have variables, not in the way an HLL does. And the idea of scope is altogether foreign. All you have are registers, which belong to whoever puts something in them. And memory locations, which can be written by anybody. If you want to think of those like variables, remember that they're all globals. That's where the MIPS calling conventions @deviantfan mentioned come in. If you write a function (that is, a chunk of code called with jal that ends with jr $ra, it's up to you to follow those conventions so you don't put garbage in your caller's registers. And it's completely up to you to be sure the data you're writing goes where you meant for it to, and doesn't overwrite a memory location that someone else is using. Because there's no concept of a "string", either - just a bunch of bytes that might contain data of any sort from ASCII to floating point numeric.
That's how computers really work. Everything else an HLL gives you is just abstraction (aka sugar-coating) to make programming easier and more reliable.
0
deviantfan
On
Have a look at jal and jr, $fp, $sp, and MIPS calling convention(s)
And yes, you won't get rid of the label stuff
The problem is that you can't think of assembly in the way you think in a high-level language. It's an entirely different world.
You don't have methods, you don't have loops. Conditional branching and jumping is all you have. Forget language-imposed execution control - you've returned to the land where GOTO is king. So like @deviantfan said, you're going to have to get comfortable with
jal
(jump and "link", aka save the PC in$ra
) andjr $ra
.And you don't have arrays. You don't even have variables, not in the way an HLL does. And the idea of scope is altogether foreign. All you have are registers, which belong to whoever puts something in them. And memory locations, which can be written by anybody. If you want to think of those like variables, remember that they're all globals. That's where the MIPS calling conventions @deviantfan mentioned come in. If you write a function (that is, a chunk of code called with
jal
that ends withjr $ra
, it's up to you to follow those conventions so you don't put garbage in your caller's registers. And it's completely up to you to be sure the data you're writing goes where you meant for it to, and doesn't overwrite a memory location that someone else is using. Because there's no concept of a "string", either - just a bunch of bytes that might contain data of any sort from ASCII to floating point numeric.That's how computers really work. Everything else an HLL gives you is just abstraction (aka sugar-coating) to make programming easier and more reliable.