Question

Write a simplified machine language program that has register $s0 loop through the numbers 0, 5,...

Write a simplified machine language program that has register $s0 loop through the numbers 0, 5, 10, ..., 50.

See Lab 11 for details on submitting the simplified machine language programs.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Below is the MIPS assembly language program which has register $s0 loop through 0,5,..,50

ADD $s0, $zero , $zero //This will load 0 into $s0

ADDI $s1, $zero, 50 //Load 50 into $s1

START : ADDI $s0, $s0, 5 //Add 5 into $s0

BNE $s0, $s1, START //Branch to label START if $s0 and $s1 content are not equal i.e. $s0 not contain 50

Now let us write above program into machine language

ADD $s0, $zero , $zero , ADD instruction has 6 bit opcode 000000 since its R type instruction, then $zero is source regiter whose 5 bit binary encoding is 00000 , then next 5 bit will be also binary encoding of register $zero i.e. 00000, then the next 5 bit will be binary encoding of target register $s0 which is register R16 with binary encoding being 10000 , then the next 5 bit will be 00000 for ADD instruction and the last 6 bits will be 100000.

Hence the machine code will be 0000 0000 0000 0000  1000 0000 0010 0000 which in hexadecimal is 0x0000 8020

ADDI $s1, $zero, 50 will have 6 bit opcode 001000, then 5 bit register code for $zero which is 00000, then 5 bit encoding of register $s1 which is R17 hence encoding will be 10001 , then last 16 bit for 50 which is 0000 0000 0011 0010. Hence the instruction is 0010  0000 0001  0001  0000 0000 0011 0010 which in hexadecimal is 0x20 11 00 32.

ADDI $s0, $s0, 5 will be 001000 10000  10000 0000 0000 0000 0101 which in Hexadecimal will be 0x22 10 00 05.

Then in BNE $s0, $s1, START, the 6 bit opcode for BNE is 000101 followed by 5 bit encoding of $s0 which is 10000, then 5 bit encoding of $s1 which is 10001 then label start is just 1 instruction behind, hence 16 bit offset will be -1 which in binary 2's complement form is 1111 1111 1111 1111. Hence the instruction is   0001 0110  0001  0001 1111 1111 1111 1111 which in hexadecimal is 0x16 11 FF FF.

Hence the overall machine language instructions are :-

0x00 00 80 20

0x20 11 00 32

0x22 10 00 05

0x16 11 FF FF

Please comment for any clarification.

Add a comment
Know the answer?
Add Answer to:
Write a simplified machine language program that has register $s0 loop through the numbers 0, 5,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT