Question

.text main:    ori $s7,$0,4097       # put a memory location in $s7    sll $s7,$s7,16  ...

.text
main:
   ori $s7,$0,4097       # put a memory location in $s7
   sll $s7,$s7,16       #
   ori $s0,$0,0x2       # put 2 into $s0
and $s0,$s0,$zero # clear $s0
ori $s0,$zero,0x2 # put 2 back into $s0
nor $s0,$s0, $zero # complement $s0
ori $s0,$zero,0x2 # put 2 back into $s0
ori $s1,$0,0x3     # put 3 into $s1
   add $s2,$s0,$s1    # add
beq $s2,$zero, exit
   sw $s2, 4($s7)       # store the result to memory
j exit
ori $s0,$zero,0x2 # pretend like we might do
nor $s0,$s0, $zero # other work after jump

# exit gracefully
exit:   addi $v0,$0,10       # load exit
   syscall           # exit

## end of file

Look at code provided in ALU2015.asm. Write down what it does.

1) What is the result and where is the result stored? Explain how it gets there.

2) Why are they using the ori instruction?

3) Why a complement operation is used in this code?

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

Assuming it is 32 bit processor.


The main thing that the program is doing is, just moving immediate data into the suitable registers, and then performs addition operation and stores that result in memory.

In this code some dead code is there, those lines of code will never executed. Due to the unconditional jump instruction to exit label.

1)

The final result is 5.

It is stored at location

Because initially $s7 = 4096

i.e., $s7 = 0000 0000 0000 0000 0001 0000 0000 0001

After logical left shifting by 16 bits,

$s7 = 0001 0000 0000 0001 0000 0000 0000 0000

The result is storing at 4($s7) i.e., 4 + $s7

Result location = 0001 0000 0000 0001 0000 0000 0000 0100

2)

ori instruction is used for moving the immediate data into the registers. It will take less time to move the data when compared to mov instructions.

3)

Here the complement operation is used to complement the data in $s0 to one's complement form. But after that that register is modified.

And another complement is used in dead code, which cannot executed by the assembler.

Add a comment
Know the answer?
Add Answer to:
.text main:    ori $s7,$0,4097       # put a memory location in $s7    sll $s7,$s7,16  ...
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
  • im trying to complete mips program code about a calculator program that can calculate integer addition...

    im trying to complete mips program code about a calculator program that can calculate integer addition / subtraction written using the MIPS assembler. im having hard times to debug this. The input is given to the array of Formula char (base address $ s0) in the form of a formula. The null character (\ 0, ASCII code 0) is placed at the end. The calculation result is given to the register $ s1 and the overflow is ignored. For example,...

  • what is the output of the following assembly code ? .data A: .word 84 111 116 97 108 32 105 115 32 . text main:​li $v0, 1l ​li $s0,0 ​la $s1, A ​li $t3, 0 loop: ​slti $t0, $s0, 17   ​be...

    what is the output of the following assembly code ? .data A: .word 84 111 116 97 108 32 105 115 32 . text main:​li $v0, 1l ​li $s0,0 ​la $s1, A ​li $t3, 0 loop: ​slti $t0, $s0, 17   ​beq: $t0, $zero, end ​sll $t1, $s0 2 ​add $t2 $s1 $t1   ​syscall ​addi $s0, $s0, 1 ​j loop end: ​li $v0, 1 ​add $a0, $zero, $t3 ​syscall

  • .data A: .word 84 111 116 97 108 32 105 115 32 . text main:​li $v0,...

    .data A: .word 84 111 116 97 108 32 105 115 32 . text main:​li $v0, 1l ​li $s0,0 ​la $s1, A ​li $t3, 0 loop: ​slti $t0, $s0, 17   ​beq: $t0, $zero, end ​sll $t1, $s0 2 ​add $t2 $s1 $t1   ​syscall ​addi $s0, $s0, 1 ​j loop end: ​li $v0, 1 ​add $a0, $zero, $t3 ​syscall /// whats the output of above assembly program

  • Please comment the MIPS code to help me understand. Here is what the code accomplishes. Here...

    Please comment the MIPS code to help me understand. Here is what the code accomplishes. Here is the code, partially commented. .data Matrix: .word 41,45,5, 34,8, 15,16,23,44,48,12,32,18,47,22,8,22 .word 46,40,42,33,13,38,27,6, 29,25,18,40,47,22,26,14,3 .word 7, 48,35,9, 43,38,9, 49,28,25,42,5, 44,10,5, 38,14 .word 46,33,16,6, 13,20,31,1, 8, 17,1, 47,28,46,14,28,7 .word 32,2, 48,25,41,29,14,39,43,46,3, 39,32,49,41,28,46 .word 5, 43,2, 48,13,4, 33,41,32,19,9, 25,30,22,2, 9, 40 .word 14,47,22,18,47,3, 35,44,18,6, 33,22,11,6, 47,50,4 .word 28,34,20,30,18,27,38,5, 26,40,37,23,16,13,37,8,7 .word 48,38,39,12,10,39,23,20,21,20,33,16,24,21,25,3,46 .word 49,38,40,38,13,47,5, 13,4, 13,23,26,12,30,29,29, 3 .word 8, 20,10,13,31,7, 12,41,12,21,28,26,43,14,35,10,19 .word 49,33,25,26,24,29,46,22,7, 5, 15,41,10,31,19,41,27 .word 48,9,...

  • MIPS Insertion program.........I could really use some help ASAP

    I have this MIPS program and I'm having trouble with it. This program is user inputs numbers until zero and sorts and print the numbers in order. Please soove this issue. You can use any sorting algorithm except bubble sort.  Need it as soon as possible. Here is the code:.datanum: .word 0space: .byte ' ' .text main:  # la $t0, val # loads val into a register  # li $t1, 0      #keeps track of how many numbers entered  la $a0,...

  • Convert the following MIPS instructions Into Machine Code Instructions. Assume the first Instruction starts at memory...

    Convert the following MIPS instructions Into Machine Code Instructions. Assume the first Instruction starts at memory address 20000 slt $t1, $s1, $s0 beq $s1, $s2, L1 beq $t1, $zer0, L2 j Exit L1: add $s1, $s1, $s1 j Exit L2: add! $s1, $s1, 1 Exit:

  • 5. Consider the SPIM code below. globl main .text main: ori $t1, $0, 10 ori $t2,...

    5. Consider the SPIM code below. globl main .text main: ori $t1, $0, 10 ori $t2, $0, 11 add $t3, $t1,$t2 move $t4, $t3 The following image shows a screen shot of QtSPIM page when this program is loaded, and executed in step-by step fashion. Current instruction is highlighted. Data Text x Text Regs Int Regs [16] Int Regs [16] PC = 400028 EPC 0 Cause = 0 BadAddr = 0 Status = 3000ff10 HI LO = 0 = 0...

  • I want to calculate Y[2]=X[3]+X[4] I'm not sure that I wrote right codes. .text main ....

    I want to calculate Y[2]=X[3]+X[4] I'm not sure that I wrote right codes. .text main . la $50, x #get base address of x la $s1, y #get base address of y lw $to, 12 ($50)#get data from memory of x[3] lw $t1 , 1 6($50) #get data from memory of x[4] add $t2, $t0, $t1 sw $t2, 8($51 ) #store result to y[2] li $v0, 10 #exit program syscall data x: word 5, 1, 17,-4, 6, 3 y: .word...

  • I AM POSTING MY QUESTION 3RD TIME . FIRST TWO TIMES I DIDNOT GET THE PROPER...

    I AM POSTING MY QUESTION 3RD TIME . FIRST TWO TIMES I DIDNOT GET THE PROPER ANSWER. PLEASE DO ALL STEPS BY LABELING THE EACH STEP. THIS IS THE ASSIGNMENT IN WHICH THE EACH STEP SHOULD BE LABEL . I MEAN EVERY THING SHOULD BE WRITTEN WHAT WE HAVE DONE IN OUR PROGRAM THIS IS THE REQUIREMENT OF TEACHER , PLEASE DO IT PROPERLY   1) MIPS to C. Assume that the variables f, g, h, i, and j are assigned...

  • Subroutines in MIPS Determines the minimum of two integers Functions within the MIPS slides describe how...

    Subroutines in MIPS Determines the minimum of two integers Functions within the MIPS slides describe how one can use subroutines (also called procedures, functions, and methods) in MIPS. Because of the importance of subroutines in modern programming, most hardware designers include mechanisms to help programmers. In a high-level language like C or Java, most of the details of subroutine calling are hidden from the programmer. MIPS has special registers to send information to and from a subroutine. The registers $a0,...

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
ADVERTISEMENT