Question: Statement: Recode the program to do the following task: Array_A[k] = 20*Array_A[k] - 2*Array_B[k]; for k = 0~20 Note: A[] = {0,1, 2,3, , 19}


 Statement: Recode the program to do the following task:

Array_A[k] = 20*Array_A[k] - 2*Array_B[k]; for k = 0~20

Note: A[] = {0,1, 2,3, …, 19}

B[] = A[]; Both sets are same.

.data # Data sesent
Array_A: .word 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Array_B: .word

.space 40

.text

.eqv Pointer $t0
.eqv offset $t1
.eqv BaseAddressRegA $t4
.eqv BaseAddressRegB $t5
.eqv EffectiveAddressA $t6
.eqv EffectiveAddressB $t7


.macro PrintAnyStringMessage(%message)
.data
ArbitraryMessage: .asciiz %message
.space 40

.text
li $v0, 4
la $a0, ArbitraryMessage
syscall
.end_macro

.macro PrintInteger(%n,%m)
li $v0,%n
move $a0,%m
syscall
.end_macro


.globl Main
Main:
PrintAnyStringMessage("Dr. Farmallah Jan Says Welcome to Assembly Proming Session!\n")
PrintAnyStringMessage("Perform Array = Array A+ 10 Using a for-loop!\n")
li Pointer, 0
li offset, 0
la BaseAddressRegA, Array_A
la BaseAddressRegB, Array_B

For_Loop:
add EffectiveAddressA, BaseAddressRegA, offset
add EffectiveAddressB, BaseAddressRegB, offset

lw $t8, 0(EffectiveAddressA)
PrintAnyStringMessage("\n Value Of Array A=")
PrintInteger(1, $t8)
addiu $t9, $t8, 10
PrintAnyStringMessage("\n Value Of Array B=")
PrintInteger(1, $t9)
sw $t9, 0(EffectiveAddressB)

addiu Pointer, Pointer, 1
sll offset, Pointer, 2
ble Pointer, 9, For_Loop

Stop:
li $v0, 10

syscall
data # Data segment Array A: .word 0, 1, 2, 3, 4,

data # Data segment Array A: .word 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Array B: .word space 40 text #Code Segment #Array A with initial values Array B is empty and to 10 word wide, 40 bytes space allocated eqv Pointer St0 Sto remanmed as Pointer eqv offset St1 St1 renamed as offset eqv BaseAddressRegA St4 .eqv BaseAddressRegB St5 .eqv Effective AddressA St6 .eqv Effective AddressB St7 #St4 renamed as BaseAddressReg #S15 renamed as BaseAddressRegB #St6 renamed as EffectiveAddressA #St7 renamed as EffectiveAddressB #Print Any Arbitrary String Message macro PrintAnyStringMessage(%message) .data ArbitraryMessage: .asciiz %message .space 40 .text li Sv0, 4 #Empty space reserved to hold 40 letters #Code to print character or siting message la Sa0, ArbitraryMessage # Base address loaded into Sa0 syscall .end_macro # Print message #Print Integers in hex, binary, etc macro PrintInteger (%n, %m) li Sv0,%n move Sa0, %m syscall .end_macro .globl Main Main: PrintAnyStringMessage("Dr. Farmamillah Jan Says Welcome to Assembly Programming Session! ") PrintAnyStringMessage("Perform: Array B Array A+ 10 Using a for-loop! ") li Pointer, 0 li offset, 0 # Clear Pointer # Clear offset la BaseAddressRegA, Array A la BaseAddressRegB, Array B For Loop: #Base address of Array A is loaded into "BaseAddressRegA" #Base address of Array B is loaded into "BaseAddressRegB" add Effective AddressA, BaseAddressRegA, offset add Effective AddressB, BaseAddressRegB, offset #Effective addres for Array A[pointer] #Effective addres for Array B[poner] Iw St8, 0(EffectiveAddressA) #8t8

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!