컴퓨터 구조
MIPS(2)
UTF-404
2024. 3. 2. 22:05
728x90
💡 Write and submit a MIPS program performed as follows.
➡️ 조건은 다음과 같다.
위의 예시 화면과 같이 첫 번째 숫자와 두 번째 숫자를 입력받고 그 숫자들의 범위까지 곱을 진행하면 된다.
📍MIPS code 보기
.data
prompt1: .asciiz "Please, type the first number: "
prompt2: .asciiz "Please, type the last number: "
result: .asciiz "The result is "
.text
main:
li $v0, 4
la $a0, prompt1
syscall
li $v0, 5
syscall
move $t0, $v0
li $v0, 4
la $a0, prompt2
syscall
li $v0, 5
syscall
move $t1, $v0
li $t2, 1
factorial_loop:
bgt $t0, $t1, print_result
mul $t2, $t2, $t0
addi $t0, $t0, 1
j factorial_loop
print_result:
li $v0, 4
la $a0, result
syscall
li $v0, 1
move $a0, $t2
syscall
li $v0, 10
syscall
728x90