Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Conv

java mips output new to mips bad output list

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1 flyntcoal

flyntcoal

    CC Lurker

  • New Member
  • Pip
  • 8 posts

Posted 27 September 2015 - 03:37 PM

This has been an adventure if you can see my other post, but I just had to make a new one because this is a completely different issue with the program. Right now I have been mainly working with 2 sections (Search and Search2), but made a few changes to the instructor's code because he made major errors that was giving me headaches. Now I just got one last thing and this program should work like a dream.
 
When I run the code and test is over and over again, all I seem to get in the output is 7. It is supposed to tell me the right address where the number is stored in the list, but all i am getting is 7. I have tried many different numbers, but just get 7. Help me figure this out.
 
MIPS Code:
 
 .data
list: .word 5
.word 7
.word 4
.word 6
.word 3
.word 8
.word 2
.word 9
.word 0
.word 30
.word 31
.word 39
.word 32
.word 38
.word 33
.word 37
.word 34
.word 36
.word 35
.word 20
.word 21
.word 29
.word 22
.word 28
.word 23
.word 27
.word 24
.word 26
.word 25
.word 10
.word 11
.word 19
.word 12
.word 18
.word 13
.word 17
.word 14
.word 16
.word 15
.word 1 # last array element
.word -1 # not part of array
prompt1: .asciiz "\nPlease enter an array element: "
prompt2: .asciiz "\nPlease enter a search target: "
space: .asciiz " "
nfound: .asciiz "\nThe target was not found."
found: .asciiz "\nThe target was found at array location "
 
.text
.globl main
main: add $t0, $zero, $zero # [main]
add $t1, $zero, $zero #
addi $t2, $zero, 1 #
addi $t3, $zero, 39 #
add $t4, $zero, $zero #
add $t5, $zero, $zero #
add $t6, $zero, $zero #
# add $t7, $zero, $zero #
la $t8, list
 
read: addi $v0, $zero, 4 # [read]
la $a0, prompt1 #
syscall
addi $v0, $zero, 5 #
syscall
sll $t7, $t0, 2 #
add $t9, $t8, $t7
sw $v0, 0($t9)
addi $t0, $t0, 1 #
blt $t0, $t2, read #
 
add $t0, $zero, $zero #
 
search: add $t1, $zero, $zero
 
search2: lw $t4, 0($t9)
add $t5, $t4, 1
lw $t5, 0($t9)
sgt $t7, $t4, $t5
sw $t4, 0($t9)
add $t5, $t4, 1
sw $t5, 0($t9)
add $t1, $t1, 1
blt $t1, $t3, search2
sub $t3, $t3, 1
add $t0, $t0, 1
blt $t0, $t2, search
 
print: addi $v0, $zero, 1 # [print]
sll $t7, $t0, 2 #
add $t9, $t8, $t7
lw $a0, 0($t9)
syscall
addi $v0, $zero, 4 #
la $a0, space #
syscall
addi $t0, $t0, 1 #
ble $t0, $t2, print #
 
end: addi $v0, $zero, 10 # [end]
syscall
 
 
Here is the Java code I am supposed to work with.
 
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication15;
import java.io.*;
 
public class CIS2233StarterCode2Java {
 
public static void main (String [] args) throws IOException {
 
BufferedReader kbd = new BufferedReader (new InputStreamReader (System.in));
int [] list = {5,7,4,6,3,8,2,9,0,20,21,29,22,28,23,27,24,26,25,30,31,39,32,38,33,37,34,36,35,10,11,19,12,18,13,17,14,16,15,1};
String prompt1 = "\nPlease enter an array element: ";
String prompt2 = "\nPlease enter a search target: ";
String space = " ";
String nfound = "\nThe target was not found.";
String found = "\nThe target was fount at array location ";
int t0 = 0;
int t1 = 0;
int t2 = 1;
int t3 = 39;
int t4;
int t5;
int t6;
int a0;
int v0;
// address calculation register t7
// base address of array register t8
// address calculation register t9
do {
System.out.print (prompt1);
v0 = Integer.parseInt(kbd.readLine());
list [t0] = v0;
t0 ++;
} while (t0 < t2);
t0 = 0;
do {
t1 = 0;
do {
t4 = list [t1];
t5 = list [t1 + 1];
if (t4 > t5) {
list [t1 + 1] = t4;
list [t1] = t5;
}
t1 ++;
} while (t1 < t3);
t3 --;
t0 ++;
} while (t0 < t2);
t0 = 0;
do {
a0 = list [t0];
System.out.print (a0);
System.out.print (space);
t0 ++;
} while (t0 <= t2);
        }
        }

can i edit the title some how?



#2 flyntcoal

flyntcoal

    CC Lurker

  • New Member
  • Pip
  • 8 posts

Posted 27 September 2015 - 04:59 PM

So here is what I think is happening and I am not sure how to fix this, it is moving to the 2nd number in the list which is 7 and making a0 = 7



#3 flyntcoal

flyntcoal

    CC Lurker

  • New Member
  • Pip
  • 8 posts

Posted 27 September 2015 - 05:56 PM

Okay so now all I get is all the numbers I enter (because it makes me enter them 39 times, if someone can fix that I would appreciate that), plus I also get 780. I should be getting the user input and then where the number is stored.
     .data
    list: .word 5
     .word 7
     .word 4
     .word 6
     .word 3
     .word 8
     .word 2
     .word 9
     .word 0
     .word 30
     .word 31
     .word 39
     .word 32
     .word 38
     .word 33
     .word 37
     .word 34
     .word 36
     .word 35
     .word 20
     .word 21
     .word 29
     .word 22
     .word 28
     .word 23
     .word 27
     .word 24
     .word 26
     .word 25
     .word 10
     .word 11
     .word 19
     .word 12
     .word 18
     .word 13
     .word 17
     .word 14
     .word 16
     .word 15
     .word 1 # last array element
     .word -1 # not part of array
    prompt1: .asciiz "\nPlease enter an array element: "
    prompt2: .asciiz "\nPlease enter a search target: "
    space: .asciiz " "
    nfound: .asciiz "\nThe target was not found."
    found: .asciiz "\nThe target was found at array location "
    
     .text
     .globl main
    main: add $t0, $zero, $zero # [main]
     add $t1, $zero, $zero #
     addi $t2, $zero, 39 #
     addi $t3, $zero, 39 #
     add $t4, $zero, $zero #
     add $t5, $zero, $zero #
     add $t6, $zero, $zero #
    # add $t7, $zero, $zero #
     la $t8, list
    
    read: addi $v0, $zero, 4 # [read]
     la $a0, prompt1 #
     syscall
     addi $v0, $zero, 5 #
     syscall
     sll $t7, $t0, 2 #
     add $t9, $t8, $t7
     sw $v0, 0($t9)
     addi $t0, $t0, 1 #
     ble $t0, $t2, read #
     
     add $t0, $zero, $zero #
     
    search: add $t1, $zero, $zero
    
    search2: sw $t4, 0($t9)
     add $t5, $t4, 1
     sw $t5, 0($t9)
     sgt $t6, $t4, $t5
     lw $t4, 0($t9)
     add $t5, $t4, 1
     lw $t5, 0($t9)
     add $t1, $t1, 1
     blt $t1, $t3, search2
     sub $t3, $t3, 1
     add $t0, $t0, 1
     blt $t0, $t2, search
     add $t0, $zero, $zero
     
    print: addi $v0, $zero, 1 # [print]
     sll $t7, $t0, 2 #
     add $t9, $t8, $t7
     lw $a0, 0($t9)
     syscall
     addi $v0, $zero, 4 #
     la $a0, space #
     syscall
     addi $t0, $t0, 1 #
     ble $t0, $t2, print #
    
    end: addi $v0, $zero, 10 # [end]
     syscall
 
Java Code:
 
   
    package javaapplication15;
     import java.io.*;
     
     public class CIS2233StarterCode2Java {
     
     public static void main (String [] args) throws IOException {
     
     BufferedReader kbd = new BufferedReader (new InputStreamReader (System.in));
     int [] list = {5,7,4,6,3,8,2,9,0,20,21,29,22,28,23,27,24,26,25,30,31,39,32,38,33,37,34,36,35,10,11,19,12,18,13,17,14,16,15,1};
     String prompt1 = "\nPlease enter an array element: ";
     String prompt2 = "\nPlease enter a search target: ";
     String space = " ";
     String nfound = "\nThe target was not found.";
     String found = "\nThe target was fount at array location ";
     int t0 = 0;
     int t1 = 0;
     int t2 = 39;
     int t3 = 39;
     int t4;
     int t5;
     int t6;
     int a0;
     int v0;
     // address calculation register t7
     // base address of array register t8
     // address calculation register t9
     do {
     System.out.print (prompt1);
     v0 = Integer.parseInt(kbd.readLine());
     list [t0] = v0;
     t0 ++;
     } while (t0 < t2);
     t0 = 0;
     do {
     t1 = 0;
     do {
     t4 = list [t1];
     t5 = list [t1 + 1];
     if (t4 > t5) {
     list [t1 + 1] = t4;
     list [t1] = t5;
     }
     t1 ++;
     } while (t1 < t3);
     t3 --;
     t0 ++;
     } while (t0 < t2);
     t0 = 0;
     do {
     a0 = list [t0];
     System.out.print (a0);
     System.out.print (space);
     t0 ++;
     } while (t0 <= t2);
            }
            }


#4 flyntcoal

flyntcoal

    CC Lurker

  • New Member
  • Pip
  • 8 posts

Posted 27 September 2015 - 07:45 PM

I am now getting the entire list followed by the number the user input
 
Example: 5 7 4 6 3 8 2 9 0 30 31 39 32 38 33 37 34 36 35 20 21 29 22 28 23 27 24 26 25 10 11 19 12 18 13 17 14 16 15 5 
 
 .data
list: .word 5
.word 7
.word 4
.word 6
.word 3
.word 8
.word 2
.word 9
.word 0
.word 30
.word 31
.word 39
.word 32
.word 38
.word 33
.word 37
.word 34
.word 36
.word 35
.word 20
.word 21
.word 29
.word 22
.word 28
.word 23
.word 27
.word 24
.word 26
.word 25
.word 10
.word 11
.word 19
.word 12
.word 18
.word 13
.word 17
.word 14
.word 16
.word 15
.word 1 # last array element
.word -1 # not part of array
prompt1: .asciiz "\nPlease enter an array element: "
prompt2: .asciiz "\nPlease enter a search target: "
space: .asciiz " "
nfound: .asciiz "\nThe target was not found."
found: .asciiz "\nThe target was found at array location "
 
.text
.globl main
main: add $t0, $zero, 39 # [main]
add $t1, $zero, $zero #
addi $t2, $zero, 39 #
addi $t3, $zero, 39 #
add $t4, $zero, $zero #
add $t5, $zero, $zero #
add $t6, $zero, $zero #
# add $t7, $zero, $zero #
la $t8, list
 
read: addi $v0, $zero, 4 # [read]
la $a0, prompt1 #
syscall
addi $v0, $zero, 5 #
syscall
sll $t7, $t0, 2 #
add $t9, $t8, $t7
sw $v0, 0($t9)
addi $t0, $t0, 1 #
ble $t0, $t2, read #
 
add $t0, $zero, $zero #
 
search: add $t1, $zero, $zero
search2: lw $t4, 0($t8)
add $t5, $t4, 1
lw $t5, 0($t8)
sgt $t6, $t4, $t5
sw $t5, 0($t8)
add $t5, $t4, 1
sw $t4, 0($t8)
add $t1, $t1, 1
blt $t1, $t3, search2
sub $t3, $t3, 1
add $t0, $t0, 1
blt $t0, $t2, search
 
add $t0, $zero, $zero
 
print: addi $v0, $zero, 1 # [print]
sll $t7, $t0, 2 #
add $t9, $t8, $t7
lw $a0, 0($t9)
syscall
addi $v0, $zero, 4 #
la $a0, space #
syscall
addi $t0, $t0, 1 #
ble $t0, $t2, print #
 
end: addi $v0, $zero, 10 # [end]
syscall


#5 flyntcoal

flyntcoal

    CC Lurker

  • New Member
  • Pip
  • 8 posts

Posted 27 September 2015 - 08:02 PM

helpsmilie.gif well? i am so far hitting a brick wall and it seems the one tool that could be useful (this site) isn't. i know it is volunteer, but to allow someone to just be hung out to dry with 0 help just don't seem right. unsure.gif 


Edited by flyntcoal, 27 September 2015 - 08:04 PM.


#6 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts

Posted 29 September 2015 - 02:54 AM

Patience - the assembly section on this site isn't well-traveled anymore. Most things take a day anyway. So you've posted three different things here and I'm kinda confused by what it exactly is that you're looking for. Can you clarify?


sudo rm -rf / && echo $'Sanitize your inputs!'