This is sample MIPS assembler code demonstrating the correct operation of the mult, multu and mul instructions by EzMIPS, the MIPS assembler editor & simulator. The code is fully commented.
Launch EzMIPS, copy the following MIPS code and paste it into EzMIPS. Assemble, Run.
# -------------- mult, multu, mul multiplication ----------------- #
.data
szMenu: .ascii "Choose multiplication type\n"
.ascii "--------------------------\n"
.ascii "1. Use mult instruction\n"
.ascii "2. Use multu instruction\n"
.ascii "3. Use mul instruction\n"
.asciiz "4. Exit\n"
.text
main:
# ................................................................ #
# Comment any 2 lines for $t5 and any 2 lines for $t6 and check result of
# mult, multu and mul. Any combination should give appropriate results!
li $t5, 0xffffffff
li $t5, 0x7fffffff
li $t5, 0x80000000
li $t6, 0xffffffff
li $t6, 0x7fffffff
li $t6, 0x80000000
# ................................................................ #
li $t1, 1
li $t2, 2
li $t3, 3
li $t4, 4
# ................................................................ #
print_menu:
# print menu
li $v0, 4
la $a0, szMenu
syscall
# ................................................................ #
# get user input
li $v0, 5
syscall
# $v0 holds user input
beq $v0, $t4, exit
beq $v0, $t3, use_mul
beq $v0, $t2, use_multu
bne $v0, $t1, print_menu
# ................................................................ #
use_mult:
mult $t5, $t6
j print_menu # Display menu again
# ................................................................ #
use_multu:
multu $t5, $t6
j print_menu # Display menu again
# ................................................................ #
use_mul:
mul $t0, $t5, $t6
j print_menu # Display menu again
# ................................................................ #
exit:
li $v0, 10
syscall
# ---------------------------------------------------------------- #
Launch EzMIPS, copy the following MIPS code and paste it into EzMIPS. Assemble, Run.
# -------------- mult, multu, mul multiplication ----------------- #
.data
szMenu: .ascii "Choose multiplication type\n"
.ascii "--------------------------\n"
.ascii "1. Use mult instruction\n"
.ascii "2. Use multu instruction\n"
.ascii "3. Use mul instruction\n"
.asciiz "4. Exit\n"
.text
main:
# ................................................................ #
# Comment any 2 lines for $t5 and any 2 lines for $t6 and check result of
# mult, multu and mul. Any combination should give appropriate results!
li $t5, 0xffffffff
li $t5, 0x7fffffff
li $t5, 0x80000000
li $t6, 0xffffffff
li $t6, 0x7fffffff
li $t6, 0x80000000
# ................................................................ #
li $t1, 1
li $t2, 2
li $t3, 3
li $t4, 4
# ................................................................ #
print_menu:
# print menu
li $v0, 4
la $a0, szMenu
syscall
# ................................................................ #
# get user input
li $v0, 5
syscall
# $v0 holds user input
beq $v0, $t4, exit
beq $v0, $t3, use_mul
beq $v0, $t2, use_multu
bne $v0, $t1, print_menu
# ................................................................ #
use_mult:
mult $t5, $t6
j print_menu # Display menu again
# ................................................................ #
use_multu:
multu $t5, $t6
j print_menu # Display menu again
# ................................................................ #
use_mul:
mul $t0, $t5, $t6
j print_menu # Display menu again
# ................................................................ #
exit:
li $v0, 10
syscall
# ---------------------------------------------------------------- #
Please let me know of any suggestions or bugs regarding the code above.
Regards,
Antonis
No comments:
Post a Comment