The assignment content discusses code for three operands and two operands. It explains how the code executes addition instructions and how it differs from adding three operands. The code also includes assembly language instructions, such as lw, addiu, and beq, and a procedure call to demonstrate function calling.
Contribute Materials
Your contribution can guide someone’s learning journey. Share your
documents today.
1.Answer a.Code for Three Operands add $t0, $s1, $s2 add $s0, $t0, $s3 b.Code for Two Operands add $s0, $s1 add $s0, $s2 add $s0, $s3 Here s0 is A , s1 is B , s2 is C and s3 is D in first line s0 will get whatever is s1 , in second line s0 will be added with s2 and in last line s0 ( which have addition of s0+s1) will be added with s3 , so you will get all the added values of s1 , s2 and s3 in s0. Difference between 3-Operand Arithmetic instruction, is 2 operands will take extra time to calculate, and it is executing add instruction three times, however in 3 operands have to execute add two times only. 2.Answer i)$T0 = 1 ii)Sorting of Arrays 3.Answer .text .globlmain main: lw $s1, B#LoadthewordstoredinlabelB addiu $s0, $s1, -201#hereS0isAands1isB .data
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
4.Answer if ( q != r) r = r + 1 ; else q = r * 2 ; .text .globlmain main: lw$t0,Q# Load the word stored in label Q lw$t1,R# Load the word stored in label R beq$t0,$t1,ELSE add$t1,$t1,1# ELSE: li$s0,2 mult$t0,$s0# r * 2 mflo$t0 .data Q:.word4 R:.word4 5.Answer Address/Immediate InstructionTypeOpcodeRSRTRDSHAMTFUNCT lw $t0,0($s0)I0x23NA addi $s0,$s0,4I0x08NA slt $t3,$t0,$t1R0x000x2A
beq $t3,$zero,reptI0x04NA j loop0J0x02 6.Answer main: la $t0, n lw $t1, 100 li $so, 0 lw$t1,0($s0) Loop: bne $t1, $zero, EXIT add $t1, $s0, $t1 addi $t1, $t1, -1 j Loop exit: 7.Answer .text main:#assume value a is already in $t0, b in $t1 add $a0,$0,$t0# it's the same function as move the value add $a1,$0,$t1 jal subr# call procedure add $t3,$0,$v0# move the return value from $v0 to where we want syscall subr: addi $sp,$sp,-4# Moving Stack pointer sw $t0, 0($sp)# Store previous value sub $t0,$a0,$a1# Procedure Body add $v0,$0,$t0# Result lw $t0, 0($sp)# Load previous value addi $sp,$sp,4# Moving Stack pointer jr $ra