| Colour Theme | Font Size Options | |
	There are different ways to specify the address of the operands 
	for any given operations such as load, add or branch.  
	The different ways of determining the address of the operands are 
        called addressing modes.
	
	In this lab, we are going to explore different addressing modes 
	of MIPS processor and learn how all instructions can fit into a 
	single word (32 bits).
There are three types of instruction format. They are Register Type, Immediate Type, and Jump Type.
The meaning of the different parts in each format: op - 6-bit operation code rs - 5-bit source register specifier rd - 5-bit destination register specifier rt - 5-bit target (source/destination) register or branch condition immediate - 16-bit immediate branch displacement or address displacement target - 26-bit jump target address shamt - 5-bit shift amount funct - 6-bit function fieldThere are different MIPS addressing modes. We have already seen some examples in the previous labs.
Now look at an example:
 
The following table shows some of the opcodes used by MIPS.
The value of rs, rd, rt should be the actual register
number, and can fit in five bits since there are 32 registers.
 
The jump instruction format can also be considered as an example
of immediate addressing, since the destination is held in the 
instruction. 
Here is a reference for you: The Jump Instruction
 
int number[50]; // declare an array number with 50 elements number[0] specifies the 1st element of the number array number[1] specifies the 2nd element of the number array number[2] specifies the 3rd element of the number array number[3] specifies the 4th element of the number array number[4] specifies the 5th element of the number array . . . number[48] specifies the 2nd last element of the number array number[49] specifies the last element of the number arrayIn base register addressing we add a small constant to a pointer held in a register.
lw rd,i(rb)For example, if $t0 pointed to the base of a record or structure, we could get at the fields using
lw $t1, ($t0) lw $t1,4($t0) lw $t1,8($t0) lw $t1,12($t0) lw $t1,16($t0) etc ...We have used a form of base addressing with zero offset in the program length.s.
 
This kind of addressing is also known as indirect register addressing since the operand is at the memory location whose address is in the register.
Here is an example to help you understand it.
 
 
Here is the program min-max.s for you to study. The lw instruction is used to load each word into a register.
##
## 	Program Name:	min-max.s 
##
##		- will print out the minimum value min 
##		- and the maximum value max of an array.
##		
##		- Assume the array has at least two elements (a[0] and a[1]). 
##		- It initializes both min and max to a[0] and then
##		- goes through the loop count - 1 times.
##		- This program will use pointers.
##		
##
##		$t0 - point to array elements in turn
##		$t1 - contains count of elements
##      	$t2 - contains min
##		$t3 - contains max
##		$t4 - each word from array in turn
##
#################################################
#                                               #
#               text segment                    #
#                                               #
#################################################
        .text
        .globl __start
__start:           	   	# execution starts here
	lw $t1,count		# $t1 is the counter and contains array size now.
	la $t0,array		# $t0 contains base address of the array.
				# $t0 will point to the array elements.
	lw $t2,($t0)		# $t2 is current min, like initializing min = a[0].
	lw $t3,($t0)		# $t3 is current max, like initializing max = a[0].
	add $t0,$t0,4		# $t0 is updated and points to a[1].
	add $t1,$t1,-1		# $t1, the counter is updated.
	
        
loop:	lw $t4,($t0)		# load next word from array
	bge $t4,$t2,notMin	# skip if a[i] >= min
	move $t2,$t4		# otherwise, copy a[i] to min
notMin:	ble $t4,$t3,notMax	# skip if a[i] <= max
	move $t3,$t4		# otherwise, copy a[i] to max
notMax:	add $t1,$t1,-1		# decrement counter
	add $t0,$t0,4		# increment pointer by 4 to the next word
	bnez $t1, loop		# continue if $t1 > 0,  exit loop when $t1 == 0
	la $a0,ans1   		# print prompt on terminal
	li $v0,4		# system call to print
	syscall			# out "min = "
               
	move $a0,$t2		# print result min
	li $v0,1
	syscall
	
	
	la $a0,ans2		# print out "max = "
	li $v0,4
	syscall 
	move $a0,$t3		# print result max
	li $v0,1
	syscall
	la $a0,endl		# syscal to print out
	li $v0,4		# a new line
	syscall 
	li $v0,10		# Exit
	syscall			# Bye!
#################################################
#                                               #
#               data segment                    #
#                                               #
#################################################
        .data
	array:	.word 3, 4, 2, 6, 12, 7, 18, 26, 2, 14, 19, 7, 8, 12, 13
	count:	.word 15
	ans1:	.asciiz "min = "
	ans2:	.asciiz "\nmax = "
	endl:	.asciiz "\n"	   
##
## 	end of file min-max.s
 Copyright: Department of Computer Science, University of Regina.
    
    Copyright: Department of Computer Science, University of Regina.