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

Building LC-3 arithmetic program. (subtraction, multiplication, division) LC-3 A

ID: 640125 • Letter: B

Question

Building LC-3 arithmetic program. (subtraction, multiplication, division)

LC-3 ASSEMBLY LANGUAGE

NEED TO START WITH CODE PROVIDED BELOW. or else point will not be given.

No need to check if number is too big, divide by zero etc, assume number that is going to be inputted is from 0-9 and the second number inputted will be less than the first

START:
AND R0, R0, 0
AND R1, R0, 0
AND R2, R0, 0
AND R3, R0, 0
AND R4, R0, 0

LEA R0, GREETING
PUTS


GETC
PUTC


ST R0, USERINPUT


LEA R0, NEWLINE
PUTS


LD R0, USERINPUT
PUTC

LEA R0, USERSTRING
PUTS

HALT
JSR SUBT
JSR MULT
JSR DIV

HALT
SUBT   .FILL x3100

NOT R2 , R1        ; inverse of R1 in R2
ADD R2 , R2 , #1 ; add 1 to R2, R2 is now - R1
ADD R3 , R0, R2   ; results go to r2

RET

MULT   .FILL x3101
RET

DIV   .FILL x3102
RET
RMD   .FILL x3103
RET

  

GREETING: .STRINGZ "enter a number "
USERSTRING: .STRINGZ " <--entered"
NEWLINE: .STRINGZ " --> ";

; variables
USERINPUT: .FILL 0


.END

Explanation / Answer

#include /* for fprintf and stderr */ #include /* for exit */ int main( void ) { int dividend = 50; int divisor = 0; int quotient; if (divisor == 0) { /* Example handling of this error. Writing a message to stderr, and * exiting with failure. */ fprintf(stderr, "Division by zero! Aborting... "); exit(EXIT_FAILURE); /* indicate failure.*/ } quotient = dividend / divisor; exit(EXIT_SUCCESS); /* indicate success.*/ }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote