Copy array elements to another array in MIPS assembly -


i have make program fills array 30 integers entered keyboard.then user type 'c' copy array other array.i've done first step cant manage copy array another.

here code

    .data msg1: .asciiz "> " msg2: .asciiz "type 'c' copy \n>"  .align 2 array: .space 400 .text  main:      la $t3 array     loop:           la $a0, msg1 #output message 1         li $v0, 4         syscall         li $v0, 5 #read integer input         syscall         move $t0, $v0         beq  $t0, -99, endloop #loop until user types -99         beq  $t1,30,endloop #get user input 30 times           addi $t1, $t1, 1 #counter         sw $t0,($t3)         addi $t3,$t3,4          b loop #loop until reaches 30       endloop:      la $a0, msg2 #output message 2     li $v0, 4     syscall      li $v0, 12 #read character input     syscall       beq $v0, 'c', copy      j next      copy:       next: 

the primitive way

la $t1, dst_array la $t3, src_array addu $t0, $t3, 30*4     # setup 'ceiling'   copy_loop:     lw $at, 0($t3)     sw $at, 0($t1)      addu $t1, $t1, 4     addu $t3, $t3, 4      blt $t1, $t0, copy_loop # if load pointer < src_array + 30*4 

however, implementations of mips don't use forwarding, , therefore have wait until $at written back. purpose, there may either stall (which rid off)

subu $t1, $t1, 4 copy_loop:     lw $at, 0($t3)     addu $t1, $t1, 4     addu $t3, $t3, 4     sw $at, 0($t1) 

or load delay slot, takes 1 cycle, making

copy_loop:     lw $at, 0($t3)     addu $t1, $t1, 4      sw $at, 0($t1)     addu $t3, $t3, 4 

generally speaking, depends :)


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -