Question

Refer the program in the next page: Assume the starting address of data segment: 0x10010000. What...

Refer the program in the next page:

  1. Assume the starting address of data segment: 0x10010000. What is the address of label num3?

    _______________________________
  2. Write the common syscall code to print string for the blank marked as #Question 2


_________________________________

  1. Write proper comments for the lines marked as #Question 3


________________________________________________________

  1. Write the machine code for the line marked as #Question 4 in both binary and hex.


Binary:_______________________________________ Hex:___________________

  1. Write the machine code for the line marked as #Question 5 in both binary and hex. Assume $t0 has the starting address of the data segment.


Binary:_______________________________________ Hex:___________________

  1. Write the syscall code to exit the program for the blank marked as #Question 6


__________________________________

  1. Describe what this program is doing in detail.


________________________________________________________________________________

  1. Provide the memory address in which the character ‘t’ is stored.


____________________________________

# MIPS program for Questions

#

# ________________________________________________________________________________

#

# ________________________________________________________________________________

        .data

prompt:        .asciiz "The Number:"

Result:        .asciiz "The Result:"

num1:          .word   0

num2:          .word   0

num3:          .word   0

                         

        .globl main

        .text

main:

        ­­­­­­____________________           # Question 2

        la      $a0, prompt            #

        syscall                        #

        li      $v0, 5                 # Question 3

        syscall                        #

        sw      $v0, num1              #

       

        ­­­­­­____________________           # Question 2

        syscall                        #

        li      $v0, 5                 # Question 3

        syscall                        #

        sw      $v0, num2              #

        lw      $t1, num1              #

        lw      $t2, num2              #

        add     $t3, $t1, $t2          # Question 4

        sw      $t3, num3              # Question 5

        ____________________           # Question 2

        la      $a0, result            #

        syscall                        #

        lw      $a0, num3              #

        li      $v0, 1                 #

        syscall                        #

        ____________________           # Question 6

        syscall                        #

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

Question 1

Assume the starting address of data segment: 0x10010000. What is the address of label num3?

Ans) 0x10010020

Explanation:-

Start address 0x10010000.Then 'Prompt' label start that address.

It has 11 charcater so allocate 11 bytes space +null termination=12 bytes there

Next address 'Result' starts from 0x10010000+12=0x1001000c

It has 11 charcater so allocate 11 bytes space +null termination=12 bytes there

Next address' num1' starts from 0x1001000c+12=0x10010018

'num1' is word data type , so 4 bytes allocate

Next address' num2' starts from 0x10010018+4=0x1001001c

Next address' num2' starts from 0x1001001c+4=0x10010020

----------------------------------------------------------------------------------------------------------

Question 2

Write the common syscall code to print string for the blank marked as #Question 2

Ans) li $v0,4

Explanation:-

string print syscall in MIPS is li $v0,4 and syscall

------------------------------------------------------------------------------------------

Question 3

Write proper comments for the lines marked as #Question 3

Ans) Instruction read for read integer input and get the read data in v0 register

Explanation:-

In MIPS comments start with # , then comment in english

--------------------------------------------------------------------------------------------------------

Question 4

Write the machine code for the line marked as #Question 4 in both binary and hex.

Instruction:-

add     $t3, $t1, $t2

R-Type instruction format

opcode(6-bit)      rs(5-bit)     rt(5-bit)      rd(5-bit)    shampt(5-bit)    func(6-bit)

000000             01001        01010          01011           00000            100000

Binary code: 00000001001010100101100000100000

Hex: 0x012a5820

------------------------------------------------------------------------------

Question 5

Write the machine code for the line marked as #Question 5 in both binary and hex.

Instruction:-

sw      $t3, num3

I-Type instruction format

opcode(6-bit)      rs(5-bit)     rt(5-bit)        offset(16-bit)

101011               00000       01011           0000000000100000

Binary code: 10101100000010110000000000100000

Hex:0xac0b0020

------------------------------------------------------------------------------------------------

Question 6

Write the syscall code to exit the program for the blank marked as #Question 6

Ans) li $v0,10

Explanation:-

It is MIPS exit system call

----------------------------------------------------------------------

Question 7

Describe what this program is doing in detail.

#Data declaration section
             .data
prompt:        .asciiz "The Number:"
Result:        .asciiz "The Result:"
num1:          .word   0
num2:          .word   0
num3:          .word   0
#Program starts here
        .globl main
        .text
main:

       #Prompt for number1
       li $v0,4
       la      $a0, prompt         
        syscall                      
    #Read user input
        li      $v0, 5               
        syscall                     
#Store first number in variable num1
        sw      $v0, num1            
        syscall                     
       #Read num2 from user
        li      $v0, 5              
        syscall                      
        #Store second number in variable num2
        sw      $v0, num2
        #Get first number in t1         
        lw      $t1, num1            
         #Get first number in t2
        lw      $t2, num2
        #Add first and second number and store into t3           
        add     $t3, $t1, $t2       
        #Store sum,that is t3 value into memory num3
        sw      $t3, num3   
        #display reuslt prompt
        li $v0,4
        la      $a0, Result          
        syscall                      
       #Get sum from num3
        lw      $a0, num3            
       #Display sum
        li      $v0, 1               
        syscall                      
        #End of the program
        li $v0,10
        syscall

------------------------------------------------------------

Question 8

Provide the memory address in which the character ‘t’ is stored.

Ans)0x10010017

Explanation:

'Result ' starts at the address 0x1001000c

't' is the 11 the character, so 0x1001000c+11=0x10010017

Add a comment
Know the answer?
Add Answer to:
Refer the program in the next page: Assume the starting address of data segment: 0x10010000. What...
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