Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Has to be in LC3 Assembly I need help with the following. I wrote below, but it is wrong. I do not get the desired

Has to be in LC3 Assembly

I need help with the following. I wrote below, but it is wrong. I do not get the desired outcome and a lot of errors. Can someone please write a new code that works with comments. Thank you

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

.ORIG x3000

LDI R0, X ; Argument X is now in R0

LDI R1, Y ; Argument Y is now in R1

LDI R2, Z ; Argument X*Y is now in R2

LDI R3, A ; Argument X/Y is now in R3

LDI R4, B ; Argument X%Y is now in R4

JSR MULT ; Jump subroutine Multiplication

JSR DIV ; Jump subroutine Division

JSR MOD ; Jump subroutine Remainder

STI R2, Z

STI R3, A

STI R4, B

HALT

X .Fill 3100 ; Address where X is located

Y .Fill 3101 ; Address where Y is located

Z .Fill 3102 ; Address where XY is located

A .Fill 3103 ; Address where X/Y is located

B .Fill 3104 ; Address where X%Y is located

MULT AND R0, R0, x0 ;Clear R0

AND R1, R1, x0 ;Clear R1

MUL R2, R0, R1 ; R2

LDR R2, R2, Z ; R2

RET

DIV AND R0, R0, x0 ;Clear R0

AND R1, R1, x0 ;Clear R1

MOV edx, 0 ;Clear dividend,high

MOV AX, R0 ;dividend,low

MOV CX, R1 ;divisor[AX=X, DX=Y]

IDIV R3, AX, CX ; R2

LDR R3, R3, A ; R2

RET

MOD AND R0, R0, X ;Clear R0

AND R1, R1, Y ;Clear R1

MOV eax, X ;Clear dividend, high

MOV R0, AX, X ;dividend,low

MOV R1, CX, Y ;divisor[AX=X, DX=Y]

IDIV R4, AX, CX ; R2

LDR R4, R4, B ; R2

RET

.END

SUBROUTINES: MULTIPLICATION DIVISION, MODULUS 5.1 Problem Statement Given two integers X and Y compute the product XY (multiplication), the quotient X/Y (inte- ger division), and the modulus X (mod Y) (remainder). 5.1.1 Inputs The integers X and Y are stored at locations 3100 and 3101, respectively. 5.1.2 Outputs The product XY, the quotient X/Y, and modulus X (mod Y) are stored at locations 3102, 3103, and 3104, respectively. If X, Y inputs are invalid for X/Y and X (mod Y) (see section 5.2.5 on page 5-3) place 0 in both locations 3103 and 3104 5.2 The program 5.2.1 Subroutines Subroutines in assembly language correspond to functions in C/C++ and other computer languages: they form a group of code that is intended to be used multiple times. They perform a logical task by operating on parameters passed to them, and at the end they return one or more results. As an example consider the simple subroutine in listing 5.1 on page 5-2 which implements the function fn-2n+ 3. The integer n is located at 3120, and the result Fn is stored at location 3121. Register R0 is used to pass parameter n to the subroutine, and R1 is used to pass the return value fn from the subroutine to the calling program. Execution is transfered to the subroutine using the JSR (jump to subroutine") instruction. This instruction also saves the return address, that is the address of the instruction that follows JSR, in register R7. See figure 5.1 on page 5-2 for the steps taken during execution of JSR. The subroutine terminates execution via the RET "return from subroutine" instruction. It simply assigns the return value in R7 to the PC The program will have two subroutines: MULT for the multiplication and DIV for division and modulus Revision: 1.8, August 14, 2005 5-1 SUBROUTINES: MULTIPLICATION DIVISION, MODULUS 5.1 Problem Statement Given two integers X and Y compute the product XY (multiplication), the quotient X/Y (inte- ger division), and the modulus X (mod Y) (remainder). 5.1.1 Inputs The integers X and Y are stored at locations 3100 and 3101, respectively. 5.1.2 Outputs The product XY, the quotient X/Y, and modulus X (mod Y) are stored at locations 3102, 3103, and 3104, respectively. If X, Y inputs are invalid for X/Y and X (mod Y) (see section 5.2.5 on page 5-3) place 0 in both locations 3103 and 3104 5.2 The program 5.2.1 Subroutines Subroutines in assembly language correspond to functions in C/C++ and other computer languages: they form a group of code that is intended to be used multiple times. They perform a logical task by operating on parameters passed to them, and at the end they return one or more results. As an example consider the simple subroutine in listing 5.1 on page 5-2 which implements the function fn-2n+ 3. The integer n is located at 3120, and the result Fn is stored at location 3121. Register R0 is used to pass parameter n to the subroutine, and R1 is used to pass the return value fn from the subroutine to the calling program. Execution is transfered to the subroutine using the JSR (jump to subroutine") instruction. This instruction also saves the return address, that is the address of the instruction that follows JSR, in register R7. See figure 5.1 on page 5-2 for the steps taken during execution of JSR. The subroutine terminates execution via the RET "return from subroutine" instruction. It simply assigns the return value in R7 to the PC The program will have two subroutines: MULT for the multiplication and DIV for division and modulus Revision: 1.8, August 14, 2005 5-1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Privacy In Statistical Databases International Conference Psd 2022 Paris France September 21 23 2022 Proceedings Lncs 13463

Authors: Josep Domingo-Ferrer ,Maryline Laurent

1st Edition

3031139445, 978-3031139444

More Books

Students also viewed these Databases questions