Question: In this question you will write an LC3 program that implements the modulo operator (for positive numbers) using a subroutine -- i.e., for inputs N

In

this

question you will write an LC3 program that implements the modulo operator

(for positive numbers) using a subroutine

--

i.e., for inputs

N

and

K

, your program will return the

number (

N

Modulo K

). You will need the modulo operator for your project, so make sure you do

this correctly and seek help from the instruction team if you have trouble completing this

assignment. Your program must have a main and a subroutine MODULO with the fo

llowing

specification. Your program must be loaded at address x3000 (i.e., it must have a .ORIG x3000

at the start).

The subroutine MODULO takes its input arguments from registers

R0

and

R1

;

it returns

the result in register

R2

. Specifically, the DIVIDEND

(i.e., the number N) is passed

through register R0 and the DIVISOR (i.e., the number K) is passed using register R1.

The output (N Modulo K) is placed in register R2. For example, if the inputs are

Dividend = x000F and Divisor= x0004 then the result in R2

is x000

3

(since 15 Modulo 4

= 3).

T

he main program will simply read the numbers N (

Dividend

) and K (the

Divisor

)

from memory locations x3100 and x3101 respectively (i.e., the dividend is stored at

x3100 and divisor is stored at x3101) and

will then

cal

l the MODULO subroutine. It then

stores the

Result

(N Modulo K) in memory location x3102. The main program will call

your subroutine using the caller

-

save convention, i.e. before calling MODULO you must

store R1 and R0 to predefined memory locations called

SaveR0 and SaveR1 before

calling your subroutine. You can define SaveR0 and SaveR1 as constants as in figure

9.6(page 227

-

228) of the book. Upon returning from the subroutine you will retrieve

those values from the corresponding memory locations so that at the end of the program,

R0 and R1 still retain the values in them before the subroutine was called

Suppose the Dividend, Divisor and Result are instead stored at address x5100, x5101 and x5102

respectively

will your program still work correctly ?

Suppose you are not given the addresses of Dividend, Divisor, and Result but are only given that

there are locations in memory with these labels. Would you need to change your code ?

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 Databases Questions!