1. Discuss the importance and value of register Sv0 when using syscall 2. Write
ID: 3890647 • Letter: 1
Question
1. Discuss the importance and value of register Sv0 when using syscall 2. Write a program in MIPS assembly language that implements the following a. Ask the user to input his/her name b. Greet the user with his/her name and ask for an integer. The message should look like "Hello (user name), please input an integer and press Enter." c. If the integer is odd print "The integer is odd" d. If the integer is even print "The integer is even" e. Terminate with politely greeting the user using his/her name. The message should look like "Goodbye(user name) , thank you for your input“Explanation / Answer
Question 1
Register $v0 is important in syscall.This is because the syscall is used to request a service from the kernel and for the MIPS language the service number or the code must be passed throught the register $v0.
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 name: "
.align 2
$LC1:
.ascii "%s"
.align 2
$LC2:
.ascii "Hello %s,please input an integer and press Enter. "
.align 2
$LC3:
.ascii "%d"
.align 2
$LC4:
.ascii "The integer is even "
.align 2
$LC5:
.ascii "The integer is odd "
.align 2
$LC6:
.ascii "Goodbye %s,thank you for your input "
.section .text.startup,"ax",@progbits
.align 2
.globl main
.set nomips16
.set nomicromips
.ent main
.type main, @function
main:
.frame $sp,56,$31 # vars= 24, regs= 2/0, args= 16, gp= 8
.mask 0x80010000,-4
.fmask 0x00000000,0
.set noreorder
.cpload $25
.set nomacro
lw $5,%got($LC0)($28)
addiu $sp,$sp,-56
lw $25,%call16(__printf_chk)($28)
addiu $5,$5,%lo($LC0)
sw $31,52($sp)
movz $31,$31,$0
.cprestore 16
sw $16,48($sp)
.reloc 1f,R_MIPS_JALR,__printf_chk
1: jalr $25
li $4,1 # 0x1
lw $28,16($sp)
addiu $16,$sp,24
lw $4,%got($LC1)($28)
lw $25,%call16(__isoc99_scanf)($28)
move $5,$16
.reloc 1f,R_MIPS_JALR,__isoc99_scanf
1: jalr $25
addiu $4,$4,%lo($LC1)
lw $28,16($sp)
move $6,$16
lw $5,%got($LC2)($28)
lw $25,%call16(__printf_chk)($28)
addiu $5,$5,%lo($LC2)
.reloc 1f,R_MIPS_JALR,__printf_chk
1: jalr $25
li $4,1 # 0x1
lw $28,16($sp)
addiu $5,$sp,44
lw $4,%got($LC3)($28)
lw $25,%call16(__isoc99_scanf)($28)
nop
.reloc 1f,R_MIPS_JALR,__isoc99_scanf
1: jalr $25
addiu $4,$4,%lo($LC3)
lw $2,44($sp)
lw $28,16($sp)
andi $2,$2,0x1
lw $25,%call16(puts)($28)
bne $2,$0,$L2
nop
lw $4,%got($LC4)($28)
b $L5
addiu $4,$4,%lo($LC4)
$L2:
lw $4,%got($LC5)($28)
nop
addiu $4,$4,%lo($LC5)
$L5:
.reloc 1f,R_MIPS_JALR,puts
1: jalr $25
nop
lw $28,16($sp)
move $6,$16
lw $5,%got($LC6)($28)
lw $25,%call16(__printf_chk)($28)
addiu $5,$5,%lo($LC6)
.reloc 1f,R_MIPS_JALR,__printf_chk
1: jalr $25
li $4,1 # 0x1
lw $31,52($sp)
lw $16,48($sp)
move $2,$0
j $31
addiu $sp,$sp,56
.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.