How can I calculate the expression "A = D[2] – D[4] " in MIPS assembly language? -
i have been learning assembly language (mips) couple of weeks (so suppose new @ this) , have found myself being confused using arrays , right registers when try code in assembly language.
at moment trying program this:
a program supposed calculate , print out values of following expression: = d[2] – d[4] has "d" array 10 words , "a" array 1 word.
this have coded far , don't know how calculate value of "x" here. hope question clear enough! please clarify in comments if not :) :)
# variable in register $s1 # base address of array d in $s2 #allocating array .data .align 2 d: .word 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 .space 320 #main function .text .globl main main: addu $s7, $0, $ra #calculate value of #this value of supposed calculated. #first load number @ d[3] temporary register can #be calculated later = number in index (position) 3 #then load number @ d[5] temporary register can #be calculated later = number in index (position) 5 #then subtract results, d[3] - d[5]. = number @ #position 3 - number @ position 5 # finally, should value of "a" la $t0, d #put base address of array d $t0 lw $t2, 3 #load index "3" $t2 lw $t3, 5 #load index "5" $t3 sub $s1, $t2, $t3 #a = d[3] - d[5] #print value of .data .globl message1 message1: .asciiz "\nthe value of is: " .text li $v0, 4 # print string la $a0, message1 syscall li $v0, 1 # print interger add $a0, $0, $s1 # print value of syscall #end of main addu $ra, $0, $s7 # restore return address jr $ra # return main program
Comments
Post a Comment