LTS

MIPS questions

Hi Amell,

I just watched the entire series of MIPS tutorial that you have uploaded on your YT channel. First of all, thanks for that! It was awesome 🙂

Secondly, I have a few questions. As I am completely new to MIPS, I have received some tasks to do (from school) and do not know how they should be configured. Do you mind looking over them and give me some hints?

For analyze.asm:
Change the program so that only every third character is printed. The program must still stop after “Z”.

For hexmain.asm:
You will now write a small subroutine, that converts numbers in the range 0 through 15 into a printable ASCII-coded character: ‘0’ through ‘9’, or ‘A’ through ‘F’, depending on the number. For numbers not in the range 0 through 15, some bits will be ignored. In file hexmain.asm, add an assembly-language subroutine with the following specification. Name: The subroutine must be called hexasc. Parameter: One, in register $a0. The 4 least significant bits specify a number, from 0 through 15. All other bits in register $a0 can have any value and must be ignored. Return value: The 7 least significant bits in register $v0 must be an ASCII code as described below. All other bits must be zero when your function returns. Required action: The function must convert input values 0 through 9 into the ASCII codes for digits ‘0’ through ‘9’, respectively. Input values 10 through 15 must be converted to the ASCII codes for letters ‘A’ through ‘F’, respectively.

Thanks in advance!

Best regards,
A.
01/3/17

# hexmain.asm

# Written
2015-09-04
by F Lundevall

# Copyright abandonded
– this file is
in the public domain.

.text

main:

li
$a0,3
# change this to test different values

jal hexasc #
call hexasc

nop # delay
slot filler (just in case)

move
$a0,$v0
# copy return value to argument register

li
$v0,11
# syscall with v0 =
11 will print
out

syscall # one
byte from a0 to the Run I/O window

stop: j stop # stop after one run

nop # delay
slot filler (just in case)

# You can write your own code for hexasc here

#

hexasc:

andi
$a0,
$a0,
0xF # remove all bits except the
4 lsb.

addi
$v0,
$0,
0x30

addi
$t0,
$0,
0x9

ble
$a0,
$t0,
converter

nop

addi
$v0,
$v0,
0x7

converter:

add
$v0,
$a0,
$v0

jr
$ra

nop

-Amell

How did you like it?

Leave a Reply