Computer Organization and Assembly Language Programming Solutions

Verified

Added on  2019/09/21

|3
|597
|172
Homework Assignment
AI Summary
This document provides solutions to various assembly language problems. The solutions cover topics such as 3-operand arithmetic instructions, sorting of arrays, conditional statements, and loop implementations. It includes examples of loading data, performing arithmetic operations, implementing control flow using branch instructions, and defining procedures with stack manipulation. The solutions are designed to help students understand fundamental concepts in computer architecture and assembly language programming. The document also demonstrates how to handle different instruction types, including immediate and register-based operations, and how to manage data within the program's memory space. The solutions are presented with clear code snippets and explanations to facilitate learning and problem-solving. Students can use these examples to understand the implementation of core programming concepts in assembly language.
tabler-icon-diamond-filled.svg

Contribute Materials

Your contribution can guide someone’s learning journey. Share your documents today.
Document Page
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
.globl main
main:
lw $s1, B # Load the word stored in label B
addiu $s0, $s1, -201 # here S0 is A and s1 is B
.data
tabler-icon-diamond-filled.svg

Secure Best Marks with AI Grader

Need help grading? Try our AI Grader for instant feedback on your assignments.
Document Page
4. Answer
if ( q != r)
r = r + 1 ;
else
q = r * 2 ;
.text
.globl main
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: .word 4
R: .word 4
5. Answer
Address/Immediate
Instruction Type Opcode RS RT RD SHAMT FUNCT
lw $t0,0($s0) I 0x23 NA
addi $s0,$s0,4 I 0x08 NA
slt $t3,$t0,$t1 R 0x00 0x2A
Document Page
beq
$t3,$zero,rept I 0x04 NA
j loop0 J 0x02
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
chevron_up_icon
1 out of 3
circle_padding
hide_on_mobile
zoom_out_icon
logo.png

Your All-in-One AI-Powered Toolkit for Academic Success.

Available 24*7 on WhatsApp / Email

[object Object]