# void Choice0() # { # printf("In Choice 0 \n"); # } # void Choice1() # { # printf("In Choice 1 \n"); # } # void Choice2() # { # printf("In Choice 2 \n"); # } # main() # { # int option = 1; # void (*func_ptr[3])() = Choice0, Choice1, Choice2}; # (*func_ptr[option])(); # return 0; # } .globl main .data input: .word 0x1 DUMMY: .asciiz "D" str0: .asciiz "In Choice 0 :" str1: .asciiz "In Choice 1 :" str2: .asciiz "In Choice 2 :" exitcmd: .word choice0 choice1 choice2 .text main: lw t0, input li t3,2 loop: blt t3,x0,exit mv t0,t3 addi t3,t3,-1 slli t0,t0,2 la t1,exitcmd add t1,t1,t0 lw t1, 0 (t1) addi t1,zero,0 jalr t1 choice0: la a1, str0 addi a0, x0, 4 # prepare for print string syscall ecall addi a0, x0, 1 addi a1, t0, 0 ecall jal loop choice1: la a1, str1 addi a0, x0, 4 # prepare for print string syscall ecall addi a0, x0, 1 addi a1, x0, 1 ecall jal loop choice2: la a1, str2 addi a0, x0, 4 # prepare for print string syscall ecall addi a0, x0, 1 addi a1, x0, 2 ecall jal loop exit: addi a0, x0, 10 ecall # terminate ecall