0% found this document useful (0 votes)
5 views2 pages

C22 3

The document contains a MIPS assembly program that implements a switch-case structure to perform basic arithmetic operations based on user input. It defines variables for input and output, processes the input to determine which case to execute, and performs operations such as addition, subtraction, multiplication, and division. After executing the selected operation, it outputs the result and prompts for another input in a loop until termination is requested.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

C22 3

The document contains a MIPS assembly program that implements a switch-case structure to perform basic arithmetic operations based on user input. It defines variables for input and output, processes the input to determine which case to execute, and performs operations such as addition, subtraction, multiplication, and division. After executing the selected operation, it outputs the result and prompts for another input in a loop until termination is requested.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#Chuong trinh: switch-case

#-------------------------------
.include "macro.mac"
#Data segment
.data
#Cac dinh nghia bien
int_a: .word 0
int_b: .word 100
int_c: .word 2
int_in: .word 0
#Cac cau nhac nhap du lieu
nhap_in: .asciiz "Nhap input: "
xuat_a: .asciiz "a = "
daungan: .asciiz "\n------------------------\n"
#-------------------------------
#Code segment
.text
#-------------------------------
# Chuong trinh chinh
#-------------------------------
main:
#Nhap (syscall)
#Nhap intput
geti_p nhap_in,int_in
#Xu ly
# t0=input/a, t1=case_values, t2=b, t3=c
lw $t0,int_in
lw $t2,int_b
lw $t3,int_c
#switch (input)
addi $t1,$zero,1
beq $t0,$t1,case1
addi $t1,$zero,2
beq $t0,$t1,case2
addi $t1,$zero,3
beq $t0,$t1,case3
addi $t1,$zero,4
beq $t0,$t1,case4
j default
#case 1: val=1 a=b+c
case1: add $t0,$t2,$t3
sw $t0,int_a
j end_sw #break
#case 2: val=2 a=b-c
case2: sub $t0,$t2,$t3
sw $t0,int_a
j end_sw
#case 3: val=3 a=b*c
case3: mul $t0,$t2,$t3
sw $t0,int_a
j end_sw
#case 4: val=4 a=b/c
case4: div $t2,$t3
mflo $t0
sw $t0,int_a
j end_sw
#default:
default: sw $zero,int_a
end_sw:
#Xuat ket qua (syscall)
puti_p xuat_a,int_a
# do-while(1)
puts daungan
j main
#ket thuc chuong trinh (syscall)
Kthuc: addi $v0,$zero,10
syscall
#-------------------------------

You might also like