PROF. JOHN ABRAHAM UTRGV MIPS - RISC PROF. JOHN ABRAHAM UTRGV Prof. John Abraham UTRGV
Prof. John Abraham UTRGV MARS SIMULATOR FIRST MAKE SURE YOU HAVE JAVA JDK, IF NOT DOWNLOAD AND INSTALL DOWNLOAD MARS MIPS SIMULATOR FROM MISSOURI STATE UNIVERSITY http://courses.missouristate.edu/kenvollmar/mars/ Prof. John Abraham UTRGV
Prof. John Abraham UTRGV MIPS CODE C=A+B .data #data used in this program A: .word 40 # set aside RAM memory for A and place 40 in it B: .word 30 # set aside RAM memory for B and place 30 in it C: .word 0 # set aside RAM memory for C and place 0 in it .text #code for this program lw $t0, A #load A from memory into a CPU register t0 lw $t1, B #load AB from memory into a CPU register t1 add $t2, $t0, $t1 #add a and b sw $t2,C # Store the result from the CPU register to memory #display results a0-a3 and v0,v2 used with functions li $v0, 1 #1 to display following integer(4 to display text) move $a0, $t2 syscall Prof. John Abraham UTRGV
Prof. John Abraham UTRGV
Prof. John Abraham UTRGV
Prof. John Abraham UTRGV How to use SYSCALL system services Step 1. Load the service number in register $v0. Step 2. Load argument values, if any, in $a0, $a1, $a2, or $f12 as specified. Step 3. Issue the SYSCALL instruction. Step 4. Retrieve return values, if any, from result registers as specified. Prof. John Abraham UTRGV
Expanded program receiving input and sending output. Slide 1 .data outText: .asciiz "MIPS for C=A+B.\n Total stored in C is: " A: .word 0 B: .word 0 C: .word 0 prompt1: .asciiz "Enter the number to store in A: " prompt2: .asciiz "\Enter the number to store in B: “ Prof. John Abraham UTRGV
Prof. John Abraham UTRGV Slide 2 .text li $v0,4 #get ready to display the message la $a0,prompt1 syscall #displays the first prompt #read the first number and save it in A li $v0,5 #5 to read integer syscall sw $v0, A lw $t1,A #also put it in t1 for calculation Prof. John Abraham UTRGV
Prof. John Abraham UTRGV Slide 3 li $v0,4 #get ready to display the message 4 to display text la $a0,prompt2 syscall #displays the second prompt #read the second number and save it in B li $v0,5 #5 to read integer syscall sw $v0, B #put input into memory location B and in register t2 lw $t2, B #by the way faster to move between registers. This is to show you how to bring from ram add $t3,$t2,$t1 sw $t3, C #store contents of t3 in C Prof. John Abraham UTRGV
Prof. John Abraham UTRGV Slide 4 #display results li $v0,4 la $a0, outText syscall li $v0,1 move $a0,$t3 Prof. John Abraham UTRGV
Prof. John Abraham UTRGV MIPS ISA MIPS WORD IS 32 BITS, so registers can hold 4 bytes. 0 to 31 registers, PC (incremented by 4), HI and LO Ex Rformat instruction: add $t0,$s1, $s2 (computation) Ex I format instruction: lw $t0, B (load store branch) memory can be given as register and offset like 24($s2) Ex J format unconditional jump Some registers are special like r0 holds only 0, can’t be changed Instructional formats: R format, I format and j format Prof. John Abraham UTRGV