Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am writing a multiplication subroutine in LC-3. I have the basis of it. But I am wondering: when multiplying negative numbers, what would be
I am writing a multiplication subroutine in LC-3. I have the basis of it. But I am wondering: when multiplying negative numbers, what would be the best way to approach it?
ORIG x3000 LDI RO, NUMBER ;load 1st number BRn STOP LDI R1, NUMBER2 ;load 2nd number BRn STOP AND R2, R2, #0 ;set R2 equal to zero to add multiplicant Loop ADD R2, R2, RO ;LOOP thru, to continue adding the number until ADD RI, RI, #-1 ;decrement until r1 is 0 BRp Loop ;loop until R1 is 0 STI R2, STORE_MULT ;STORE RESULT STOP HALT NUMBER .FILL x3100 NUMBER2 .FILL x3101 STORE MULT .FILL x3102 END Would it be possible to convert to twos compliment and then multiply or would that give an inaccurate result?
Or should I stick with my original plan of just testing each number to see if negative, and then if it is negative, I'm not really sure how to multiply the numbers without causing an overflow.
I attached the code I have below, but im just asking for help when either number is negative.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started