Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

BASIC COMPUTER ASSEMBLY LANGUAGE Array Maximum and Minimum Declare an array of i

ID: 3710543 • Letter: B

Question

BASIC COMPUTER ASSEMBLY LANGUAGE

Array Maximum and Minimum

Declare an array of integers:

.data

size: .word 8

array: .word 23, -12, 45, -32, 52, -72, 8, 13

Write a program that determines the minimum and the maximum element in the array. Assume that the array has at least one element (in which case, that element will be both the minimum and maximum.) Leave the results in registers.

Qtspim simulator: The starting address of Data Section is 0x10000000

Mars simulator: The starting address of Data Section is 0x10010000

Explanation / Answer

.data 0x10000000

size: .word 8

array: .word 23, -12, 45, -32, 52, -72, 8, 13

.text

.globl main

main:

la $t0,size

lw $t1,0($t0) #size is stored in $t1

la $s0,array #array base address is stored in $s0

li $t2,0 #max

li $t3,0 #min

li $t0,0 #count

lw $t2,0($s0) #max = array[0]

lw $t3,0($s0) #min = array[0]

addi $t0,$t0,1

addi $s0,$s0,4

LOOP:

beq $t0,$t1,LOOP_END

lw $t4,0($s0)

slt $t5,$t4,$t3

beq $t5,$0,MAX_COND

move $t3,$t4

MAX_COND:

slt $t5,$t2,$t4

beq $t5,$0,NEXT

move $t2,$t4

NEXT:

addi $t0,$t0,1

addi $s0,$s0,4

j LOOP

LOOP_END:

move $s2,$t2 #max stored in $s2

move $s3,$t3 #min stored in $s3

li $v0,10

syscall