. Write complete code for the following switch statement in MIPS. Print the valu
ID: 3589164 • Letter: #
Question
. Write complete code for the following switch statement in MIPS. Print the value the final value of "X. should be provided as user input. switchlx) f case 0:x+1; break; case 1:x+3; break; case 2: x+ 5; break; 2. Write complete code for the following switch statement in MIPS. Print the final value ory,should be provided as user input-a" and "b" should have the values 12 and 5 respectively switchix) t case 0: y = a + b: break; case 1: y a - b: break; case 2 y a+x break Write a MIPS subprogram called "addtwo" which takes two integer arguments and adds their values. Then write a main program that uses this subprogram to add the values in S:0 and $t1 and print out the sum. Set the value of $t0 to 5 and $t1 to 9. 3. 4. Write a MIPS subprogram called "gthan" which takes two integer arguments and determines the greater of the two integers. Then wnite a main program that uses the subprogram to determine if $10 or $11 has the greater number. If $10 is greater than $11, print 0 else print 1. Sot the value of $10 to 7 and $t1 to 15 5 6 8 0Explanation / Answer
Question 1
.file 1 ""
.section .mdebug.abi32
.previous
.nan legacy
.module fp=32
.module nooddspreg
.abicalls
.section .rodata.str1.4,"aMS",@progbits,1
.align 2
$LC0:
.ascii "Enter the value of x"
.align 2
$LC1:
.ascii "%d"
.align 2
$LC2:
.ascii "Invalid Choice "
.align 2
$LC3:
.ascii "The final value of x is %d"
.section .text.startup,"ax",@progbits
.align 2
.globl main
.set nomips16
.set nomicromips
.ent main
.type main, @function
main:
.frame $sp,40,$31 # vars= 8, regs= 1/0, args= 16, gp= 8
.mask 0x80000000,-4
.fmask 0x00000000,0
.set noreorder
.cpload $25
.set nomacro
lw $4,%got($LC0)($28)
addiu $sp,$sp,-40
lw $25,%call16(puts)($28)
.cprestore 16
sw $31,36($sp)
movz $31,$31,$0
.reloc 1f,R_MIPS_JALR,puts
1: jalr $25
addiu $4,$4,%lo($LC0)
lw $28,16($sp)
addiu $5,$sp,24
lw $4,%got($LC1)($28)
lw $25,%call16(__isoc99_scanf)($28)
nop
.reloc 1f,R_MIPS_JALR,__isoc99_scanf
1: jalr $25
addiu $4,$4,%lo($LC1)
lw $2,24($sp)
li $3,1 # 0x1
lw $28,16($sp)
beq $2,$3,$L3
li $4,2 # 0x2
beq $2,$4,$L4
nop
bne $2,$0,$L7
nop
b $L6
sw $3,24($sp)
$L3:
b $L9
li $2,4 # 0x4
$L4:
li $2,7 # 0x7
$L9:
b $L6
sw $2,24($sp)
$L7:
lw $4,%got($LC2)($28)
lw $25,%call16(puts)($28)
nop
.reloc 1f,R_MIPS_JALR,puts
1: jalr $25
addiu $4,$4,%lo($LC2)
lw $28,16($sp)
nop
$L6:
lw $5,%got($LC3)($28)
lw $6,24($sp)
lw $25,%call16(__printf_chk)($28)
addiu $5,$5,%lo($LC3)
.reloc 1f,R_MIPS_JALR,__printf_chk
1: jalr $25
li $4,1 # 0x1
lw $31,36($sp)
move $2,$0
j $31
addiu $sp,$sp,40
.set macro
.set reorder
.end main
.size main, .-main
.ident "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.1) 5.4.0 20160609"
Question 2
.file 1 ""
.section .mdebug.abi32
.previous
.nan legacy
.module fp=32
.module nooddspreg
.abicalls
.section .rodata.str1.4,"aMS",@progbits,1
.align 2
$LC0:
.ascii "Enter the value of x"
.align 2
$LC1:
.ascii "%d"
.align 2
$LC2:
.ascii "Invalid Choice "
.align 2
$LC3:
.ascii "The final value of y is %d"
.section .text.startup,"ax",@progbits
.align 2
.globl main
.set nomips16
.set nomicromips
.ent main
.type main, @function
main:
.frame $sp,40,$31 # vars= 8, regs= 2/0, args= 16, gp= 8
.mask 0x80010000,-4
.fmask 0x00000000,0
.set noreorder
.cpload $25
.set nomacro
lw $4,%got($LC0)($28)
addiu $sp,$sp,-40
lw $25,%call16(puts)($28)
.cprestore 16
sw $31,36($sp)
movz $31,$31,$0
sw $16,32($sp)
.reloc 1f,R_MIPS_JALR,puts
1: jalr $25
addiu $4,$4,%lo($LC0)
lw $28,16($sp)
addiu $5,$sp,24
lw $4,%got($LC1)($28)
lw $25,%call16(__isoc99_scanf)($28)
nop
.reloc 1f,R_MIPS_JALR,__isoc99_scanf
1: jalr $25
addiu $4,$4,%lo($LC1)
lw $2,24($sp)
li $3,1 # 0x1
lw $28,16($sp)
beq $2,$3,$L5
li $16,7 # 0x7
li $3,2 # 0x2
beq $2,$3,$L5
li $16,14 # 0xe
beq $2,$0,$L5
li $16,17 # 0x11
lw $4,%got($LC2)($28)
lw $25,%call16(puts)($28)
nop
.reloc 1f,R_MIPS_JALR,puts
1: jalr $25
addiu $4,$4,%lo($LC2)
lw $28,16($sp)
nop
$L5:
lw $5,%got($LC3)($28)
lw $25,%call16(__printf_chk)($28)
move $6,$16
addiu $5,$5,%lo($LC3)
.reloc 1f,R_MIPS_JALR,__printf_chk
1: jalr $25
li $4,1 # 0x1
lw $31,36($sp)
lw $16,32($sp)
move $2,$0
j $31
addiu $sp,$sp,40
.set macro
.set reorder
.end main
.size main, .-main
.ident "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.1) 5.4.0 20160609"
Question 3
.file 1 ""
.section .mdebug.abi32
.previous
.nan legacy
.module fp=32
.module nooddspreg
.abicalls
.text
.align 2
.globl addtwo
.set nomips16
.set nomicromips
.ent addtwo
.type addtwo, @function
addtwo:
.frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, gp= 0
.mask 0x00000000,0
.fmask 0x00000000,0
.set noreorder
.set nomacro
j $31
addu $2,$4,$5
.set macro
.set reorder
.end addtwo
.size addtwo, .-addtwo
.section .rodata.str1.4,"aMS",@progbits,1
.align 2
$LC0:
.ascii "The sum is %d"
.section .text.startup,"ax",@progbits
.align 2
.globl main
.set nomips16
.set nomicromips
.ent main
.type main, @function
main:
.frame $sp,32,$31 # vars= 0, regs= 1/0, args= 16, gp= 8
.mask 0x80000000,-4
.fmask 0x00000000,0
.set noreorder
.cpload $25
.set nomacro
lw $5,%got($LC0)($28)
addiu $sp,$sp,-32
lw $25,%call16(__printf_chk)($28)
li $6,14 # 0xe
sw $31,28($sp)
movz $31,$31,$0
.cprestore 16
addiu $5,$5,%lo($LC0)
.reloc 1f,R_MIPS_JALR,__printf_chk
1: jalr $25
li $4,1 # 0x1
lw $31,28($sp)
move $2,$0
j $31
addiu $sp,$sp,32
.set macro
.set reorder
.end main
.size main, .-main
.ident "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.1) 5.4.0 20160609"
Question 4
.file 1 ""
.section .mdebug.abi32
.previous
.nan legacy
.module fp=32
.module nooddspreg
.abicalls
.text
.align 2
.globl gthan
.set nomips16
.set nomicromips
.ent gthan
.type gthan, @function
gthan:
.frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, gp= 0
.mask 0x00000000,0
.fmask 0x00000000,0
.set noreorder
.set nomacro
j $31
slt $2,$5,$4
.set macro
.set reorder
.end gthan
.size gthan, .-gthan
.section .rodata.str1.4,"aMS",@progbits,1
.align 2
$LC0:
.ascii "The value is %d"
.section .text.startup,"ax",@progbits
.align 2
.globl main
.set nomips16
.set nomicromips
.ent main
.type main, @function
main:
.frame $sp,32,$31 # vars= 0, regs= 1/0, args= 16, gp= 8
.mask 0x80000000,-4
.fmask 0x00000000,0
.set noreorder
.cpload $25
.set nomacro
lw $5,%got($LC0)($28)
addiu $sp,$sp,-32
lw $25,%call16(__printf_chk)($28)
li $6,1 # 0x1
sw $31,28($sp)
movz $31,$31,$0
.cprestore 16
addiu $5,$5,%lo($LC0)
.reloc 1f,R_MIPS_JALR,__printf_chk
1: jalr $25
li $4,1 # 0x1
lw $31,28($sp)
move $2,$0
j $31
addiu $sp,$sp,32
.set macro
.set reorder
.end main
.size main, .-main
.ident "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.1) 5.4.0 20160609"
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.