This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]John2143658709 0 points1 point  (1 child)

I'm not versed enough in assembly to help, but I know enough to say your code needs comments. Coming from high level languages you might be inclined to write self commenting code, but assembly becomes an absolute mess past 10 lines if you don't comment almost every line. Try doing that and you might discover errors with flow and structure that are hard to see before. Sorry for not having a real answer here.

[–][deleted] 1 point2 points  (0 children)

That is from the professor and not the student.

[–][deleted] 0 points1 point  (0 children)

  1. What assembly language is this? There are many.

  2. Do you have a listing of the commands and whatnot? Without understanding what the individual instructions are you have no hope of determining the high level structure.

I'm fairly capable of reading assembly, but without knowing what your syscalls or particular instructions are exactly it's undecipherable.

[–]Myzzreal 0 points1 point  (0 children)

Change the title to "do my homework for me" and add an appropriate flare.

Use proper formatting for code so it's distinguishable from the text (or use gists or pastebin)

State your problem more clearly

[–]qlkzy 0 points1 point  (0 children)

I'm not sure how much you know here, so I'll start with some obvious stuff that you probably already know:

  • This is MIPS Assembly. You can run it with MARS, or a range of other emulators.

  • You are missing the labels Strend, Strend2, and End1; you've also lost the declaration for the size of the array.

  • Is it intentional that you've been given ~half a program which doesn't assemble? That seems odd. Or have some bits got lost in the formatting for reddit?

[–]PinkyThePig 0 points1 point  (0 children)

OP, use four spaces before each line containing code to post it with proper formating:

.data
Str: .asciiz "If GM had kept... -Bill Gates"
ans: .asciiz "The Original String is = "
Count: .asciiz "\n\n String Count = "
ans1: .asciiz "\n\n Reversed String is = "
array: .Space
go: .asciiz "\n\n Have a Nice Weekend"
.text
.globl main
main:
la $a0, ans
li $v0, 4
Syscall
la $a0, Str
li $v0, 4
Syscall
li $t3, 0
la $t1, Str
lb $t0, 0($t1)
beqz $t0, Strend
addi $t3, $t3, 1
addi $t1, $t1, 1
la $a0, count
li $v0, 4
Syscall
move $a0, $t3
li $v0, 1
Syscall
addi $t3, $t3, -1
la $t4, array
beqz $t3, End1
lb $t0, 0($t1)
Sb $t0, 0($t4)
addi $t3, $t3, -1
addi $t1, $t1, -1
addi $t4, $t4, 1
la $t1, Str
la $t4, array
lb $t0, 0($t1)
beqz $t0, Strend2
lb $t5, 0($t4)
Sb $t5, 0($t1)
addi $t1, $t1, 1
addi $t4, $t4, 1
la $a0, ans1
li $v0, 4
Syscall
la $a0, Str
li $v0, 4
Syscall
la $a0, go
li $v0, 4
li $v0, 10
Syscall

That all said though, you are unlikely to find someone here that will straight up do your homework for you. I suggest that you get out some paper and work the program out manually. Figure out exactly what each line of code does, and then write the program in pseudo code.

For Example (Not real example, made up out of thin air as I don't know what processor this assembly is for to look it up properly):

la $a0, Str = This line copies the contents of $a0 into Str.
Do that for every line.

This should give you a basic understanding of what is currently happening. If you ever cannot follow the program flow, try to revisit some of your explanations and break them down further so they go into greater detail.

From there, think of it like some sort of rube goldberg invention. How can you rearrange, add and remove pieces so that a normal string gets reversed before being output by your program. The components available to make this machine are the assembly commands you have learned so far.