For this assignment you will write two programs in MIPS assembly that
accomplish something with a loop. Refer back to print_chars.s
from the
previous homework for reference.
Write the first program in the provided file powers_of_2.s
. This program must
print out the first 30 powers of 2 starting with , which is 1. Each power
of 2 must be on its own line, so you must print a '\n'
after each power.
You may create named variables in the data segment if you want, but you can
also simply keep track of everything in the general purpose registers $t0
,
$t1
, etc.
For this program you will need to keep multiplying a value by 2. Since these
values will always be positive, you can use the unsigned integer multiplication
instruction multu
. Unlike with addition, the multiplication instructions
store the result in 2 registers: Hi and Lo. Each of these registers is 32
bits. If the multiplication does not cause an overflow, Lo will contain the
product and Hi will be 0. If you are multiplying two larger numbers, the
overflow will be stored in Hi. Rather than accessing these registers directly,
you copy the contents of the Lo register into another register with mflo
and
copy the contents of the Hi register into another register with mfhi
.
In print_binary.s
, write a program that reads an integer from the user and
then prints out the binary representation of that integer. It should print out
all 32 bits of the binary representation. Recall from a previous assignment
that to print out each bit you need to shift the original number so that the
bit you want to print is in the least significant position, and then perform a
bitwise AND with the shifted number and 1.
Read in the number convert to binary from standard input. You can do this using
syscall
with code 5 in $v0
. After the syscall returns, the value in
$v0
will be replaced by the integer read from standard input. You can then
copy the $v0
value into another register and start shifting that value’s bits.
You can shift an integer right by a stored value like so:
srlv <destination> <register containing original value> <register containing shift amount>
You can perform a bitwise AND operation with an immediate value using andi
.
Push your modified powers_of_2.s
and print_binary.s
to git-keeper.