One extension of the MIPS instruction set architecture has two new instructions
ID: 3819994 • Letter: O
Question
One extension of the MIPS instruction set architecture has two new instructions called movn (move if not zero) and movz (move if zero). For example, the instruction
movn $8, $11, $4
copies the contents of register 11 into register 8, provided that the value in register 4 is nonzero (otherwise it does nothing). The movz instruction is similar but copying takes place only if the register’s value is zero. Show how to use the new instructions to put whichever is larger, register 8’s value or register 9’s value, into register 10. If the values are equal, copy either into register 10. You may use register 1 as an extra register for temporary use. Do not use any conditional branches.
Explanation / Answer
$LFB1024 = .
greatest(int, int):
addiu $sp,$sp,-24
sw $fp,20($sp)
move $fp,$sp
sw $4,24($fp)
sw $5,28($fp)
lw $3,24($fp)
lw $2,28($fp)
nop
slt $2,$2,$3
movz $2,$0,$L2
nop
lw $2,24($fp)
b $L3
nop
lw $2,28($fp)
nop
sw $2,8($fp)
lw $2,8($fp)
move $sp,$fp
lw $fp,20($sp)
addiu $sp,$sp,24
j $31
nop
$LFB1025 = .
main:
addiu $sp,$sp,-48
sw $31,44($sp)
sw $fp,40($sp)
sw $16,36($sp)
move $fp,$sp
lui $2,%hi($LC0)
addiu $5,$2,%lo($LC0)
lui $2,%hi(std::cout)
addiu $4,$2,%lo(std::cout)
jal std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
nop
addiu $2,$fp,24
move $5,$2
lui $2,%hi(std::cin)
addiu $4,$2,%lo(std::cin)
jal std::basic_istream<char, std::char_traits<char> >::operator>>(int&)
nop
move $3,$2
addiu $2,$fp,28
move $5,$2
move $4,$3
jal std::basic_istream<char, std::char_traits<char> >::operator>>(int&)
nop
lui $2,%hi($LC1)
addiu $5,$2,%lo($LC1)
lui $2,%hi(std::cout)
addiu $4,$2,%lo(std::cout)
jal std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
nop
move $16,$2
lw $2,24($fp)
lw $3,28($fp)
nop
move $5,$3
move $4,$2
jal greatest(int, int)
nop
move $5,$2
move $4,$16
jal std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
nop
move $2,$0
move $sp,$fp
lw $31,44($sp)
lw $fp,40($sp)
lw $16,36($sp)
addiu $sp,$sp,48
j $31
nop
$LFB1029 = .
__static_initialization_and_destruction_0(int, int):
addiu $sp,$sp,-32
sw $31,28($sp)
sw $fp,24($sp)
move $fp,$sp
sw $4,32($fp)
sw $5,36($fp)
lw $3,32($fp)
li $2,1 # 0x1
bne $3,$2,$L9
nop
lw $3,36($fp)
li $2,65535 # 0xffff
movn $3,$2,$L9
nop
lui $2,%hi(std::__ioinit)
addiu $4,$2,%lo(std::__ioinit)
jal std::ios_base::Init::Init()
nop
lui $2,%hi(__dso_handle)
addiu $6,$2,%lo(__dso_handle)
lui $2,%hi(std::__ioinit)
addiu $5,$2,%lo(std::__ioinit)
lui $2,%hi(std::ios_base::Init::~Init())
addiu $4,$2,%lo(std::ios_base::Init::~Init())
jal __cxa_atexit
nop
nop
move $sp,$fp
lw $31,28($sp)
lw $fp,24($sp)
addiu $sp,$sp,32
j $31
nop
$LFB1030 = .
_GLOBAL__sub_I_main:
addiu $sp,$sp,-32
sw $31,28($sp)
sw $fp,24($sp)
move $fp,$sp
li $5,65535 # 0xffff
li $4,1 # 0x1
jal __static_initialization_and_destruction_0(int, int)
nop
move $sp,$fp
lw $31,28($sp)
lw $fp,24($sp)
addiu $sp,$sp,32
j $31
nop
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.