In: Computer Science
This is to be done using MIPS assembly language.
Display the following menus, ask user to select one item. If 1-3 is selected, display message “item x is selected”, (x is the number of a menu item), display menus again; if 0 is selected, quit from the program.
1. Menu item 1
2. Menu item 2
3. Menu item 3
0. Quit
Please select from above menu (1-3) to execute one function. Select 0 to quit
.section .rodata
.LC0:
.string "\n1.Menu Item 1"
.LC1:
.string "\n2.Menu Item 2"
.LC2:
.string "\n3.Menu Item 3"
.LC3:
.string "\n4.Quit"
.align 8
.LC4:
.string "\nPlease select from above menu (1-3) to execute one function. Select 0 to quit"
.LC5:
.string "%d"
.text
.globl main
.type main, @function
main:
.LFB2:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
movl $.LC0, %edi
movl $0, %eax
call printf
movl $.LC1, %edi
movl $0, %eax
call printf
movl $.LC2, %edi
movl $0, %eax
call printf
movl $.LC3, %edi
movl $0, %eax
call printf
movl $.LC4, %edi
movl $0, %eax
call printf
leaq -4(%rbp), %rax
movq %rax, %rsi
movl $.LC5, %edi
movl $0, %eax
call __isoc99_scanf
movl -4(%rbp), %eax
testl %eax, %eax
jne .L2
movl $0, %edi
call exit
.L2:
movl $0, %eax
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE2: