UTF-404 2024. 3. 2. 22:18
728x90

💡 MIPS 프로그래밍 조건 사항

  • The system uses byte-based address and an element in an array has 4-bytes length.
  • Program followings.
    1) f = -h + B[g];
    2) f = A[B[h] + 1];
  • Set the variables as follows :
    A={1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
    B={1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
  • The output result from the program will be as follows :

예시 출력 화면!!

  • The submitted program will be tested by changing the values of g and h in your program and checked if the results are correct.
.data 
	arrayA: .word 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
	arrayB: .word 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
	typeg: .asciiz "Please, type a number for g: "
	typeh: .asciiz "Please, type a number for h: "
	result1st: .asciiz "The 1st result is "
	result2nd: .asciiz "The 2nd result is "
	enter: .asciiz "\n"

.text 

main:

	li $v0, 4
	la $a0, typeg
	syscall

	li $v0, 5
	syscall

	add $s1, $zero, $v0

	li $v0, 4
	la $a0, typeh
	syscall

	li $v0, 5
	syscall

	add $s2, $zero, $v0

	la $s6, arrayA
	la $s7, arrayB

	sll $t0, $s1, 2
	add $t0, $s7, $t0
	lw $t0, 0($t0)
	sub $s0, $t0, $s2

	li $v0, 4
	la $a0, result1st
	syscall

	add $a0, $zero, $s0

	li $v0, 1
	syscall

	li $v0, 4
	la $a0, enter
	syscall

	sll $t0, $s2, 2 
	add $t0, $t0, $s7
	lw $t0, 0($t0)

	addi $t0, $t0, 1
	sll $t0, $t0, 2
	add $t0, $t0, $s6
	lw $s0, 0($t0)

	li $v0, 4
	la $a0, result2nd
	syscall

	add $a0, $zero, $s0

	li $v0, 1
	syscall

	li $v0, 4
	la $a0, enter
	syscall

	li $v0, 10
	syscall
728x90