Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Methods, Load/Store and Arrays in Assembly Language 1. Load and Store (like in t

ID: 3573196 • Letter: M

Question

Methods, Load/Store and Arrays in Assembly Language 1. Load and Store (like in the lecture....)

(a) Specify memory location (la)

(b) Load immediate Integer-1 to reg. ($t1)

(c) Load immediate Integer-2 to reg. ($t2

(d) Load Immediate Integer-3 to reg. ($t3)

(e) Store Integer-1 to Memory

(f) Store Integer-2 to Memory

(g) Store Integer-3 to Memory

(h) Load Integer-1 from memory to Register ($t4)

(i) Load Integer-1 from memory to Register ($t5)

(j) Load Integer-1 from memory to Register ($t6)

(k) Add: Integer-1 + Integer-2 + Integer-3 ($t7)

(l) Store Result of the addition again to memory

(m) Load the result of Add to a register ($t8)....(DONE)

Array(3) 3

Explanation / Answer

The purpose of the memory is to store group of bits and deliver them to the processor for loading into the registers. Memory addresses are 32 bit numbers ranging from 0x00000000 to 0xFFFFFFFF. Memory can hold both program instructions and data. One function of the operating system is to assign blocks of memory for the instructions and data of each process. Another thing a good operating system does is to allow many processes to run concurrently on the computer.

The program counter (PC) always holds the address of the next instruction. Normally it is incremented every time an instruction is executed. This controls the flow of the program.

There are 32 general purpose registers, numbered 0 to 31. Registers may be referred to by name or number in assembly language, for instance, register 4 can be referred to as $4 or $a0, and is usually used for an argument to a procedure.

$0 is a constant 0, and cannot be changed
$31 stores the return address from a procedure (function) call.

$1($at) - Assembler temporary

$v0-$v1- values returned by the functions

$a0-$a3- arguments to the function

$t0-$t9- temporary use. can be used freely but if the procedure calls then that procedure may change it.

$s0-$s7- when we write a procedure, used for saving and restoring the prevoius values.

Load immediate Integer-1 to reg. ($t1)- lw $t1 , Integer-1 //load contents of the integer-1 into register t1

                                                                 li $t1, 1   // load immediate $t1=1

Load immediate integer-2 to reg.($t2)- lw $t2, integer-2 //load contents of the interger-2 into register t2

                                                               li $t2,2 // load immediate $t2=2

Load immediate interger-3 to reg.($t3)- lw $t3, integer-3 //load contents of the integer-3 into register t3

li $t3,3   // load immediate %t3=3

Store integer-1 to memory- sw $t1 var1 // stores the content of the register t1 into ram var1

Store integer-2 to memory- sw $t2 var2 // stores the content of the regiter t2 into ram location var2

Store integer3- to memory - sw $t3 var3 // stores the content of the register t3 into the ram location var3

Load integer-1 from memory to register ($t4)- lw $t4,var1 //load the contents of the ram var1 into register $t4

Load integer-2 from memory to register ($t5)- lw $t5, var2 // load the contents of the ram var2 into register $t5

Load integer-3 from memory to register ($t6)- lw $t6, var3 // load the contents of the ram var3 into register $t6

Add integer-1+integer-2+integer-3($t7)- add $t4,$t5,$t6

Store the result of the addition in memory- sw $t7 var4

Load the result of add to register ($t8)- lw $t8 var4

Program to add 3-integers of array:-

                 .data

array1:      .space   12    // declare 12 bytes of the storage to hold array of 3 integers

                 .text

_start :      la   $t0,   array1 //load the base address of the array 1 into the register $t0

                 li    $t1,   2           // $t1=2

                 sw $t1, ($t0)     // first array element set to 2, indirect addressing

                 li $t2,    3       // $t1=3

                 sw $t2, 4($t0)   //second array element set to 3

                  li$t3, 4            //$t1=4

                  sw $t3, 8($t0) // third array element set to 4

                  add $t0,$t1,$t2,$t3

                  la   $to, final

                    done

Program to add 2 integers

.text           

.globl __start

__start:

        la      $a0, prompt     # address of prompt goes in
        li      $v0, 4          # service code for print string
        syscall

        li      $v0, 5         

        sw      $v0, Num1       # store what was entered
        li      $v0, 5         
        sw      $v0, Num2       # store what was entered

        lw      $t0, Num1
        add     $a0, $t0, $v0

        li      $v0, 1          # print integer service call

        la      $a0, final
        li      $v0, 4
        syscall

        li      $v0, 10         # exit program service
        syscall