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

this is what I have but I don\'t know if it\'s right: .ORIG x3000 ;INPUTNUMBER i

ID: 3807833 • Letter: T

Question

this is what I have but I don't know if it's right:

.ORIG x3000

;INPUTNUMBER inputs: r1 points to the ascii number string
; r2 contains the number of digits
;RETURNS:r0 contains the integer


atoi st r3, SaveReg3 ; Save registers
   st r4, SaveReg4
   st r5, SaveReg5
   st r7, SaveReg7
   st r2, string
   st r2, len
   ld r7, minus30
   add r3, r2, #0 ; R3 <--- len

;
;Setup
;

and r0, r0, #0 ; Accumulator
add r3, r3, #-1               ;length-1
lea r4, Weight               ;Multiplicand(the constant)
add r4,r4, r3               ;get the appropriate weight
ldr r2, r4, #0             ;r2 <--- Constant(multiplicand)
ldr r5, r1, #0           ;get ASCII digit. r5 is multiplier
add r5, r5, r7               ;convert to decimal

mulLoop

   add r0,r0,r2
   add r5, r5, #-1
   brp mulLoop
;
   add r4, r4, #-1           ; points to the next constant
   ldr r2, r4, #0           ; R2 <-- next constant
   add r1,r1,#1           ; update pointer to Next digit of multipl.
   ldr r5, r1, #0           ; get ascii digit
   add r5, r5, r7           ; convert to decimal
   add r3, r3, #-1           ; decrement length
   brzp mulLoop

any help will be appreciated!

1. On the LC-3 simulator, you can only input one character with the getc trap subroutine. However, it does print a multi-character string. In this lab, you will write a program that will accept a multi-character string and display it We would like to input a multi-digit number, convert it to an integer and display it. The range of numbers you can process on the LC-3 is 32768 +32767]. Write a program in LC-3 assembly to input and display a multidigit number in the valid range for this machine

Explanation / Answer

.ORIG x3000

;INPUTNUMBER inputs: r1 points to the ascii number string
; r2 contains the number of digits
;RETURNS:r0 contains the integer


atoi st r3, SaveReg3 ; Save registers
   st r4, SaveReg4
   st r5, SaveReg5
   st r7, SaveReg7
   st r2, string
   st r2, len
   ld r7, minus30
   add r3, r2, #0 ; R3 <--- len

;
;Setup
;

and r0, r0, #0 ; Accumulator
add r3, r3, #-1               ;length-1
lea r4, Weight               ;Multiplicand(the constant)
add r4,r4, r3               ;get the appropriate weight
ldr r2, r4, #0             ;r2 <--- Constant(multiplicand)
ldr r5, r1, #0           ;get ASCII digit. r5 is multiplier
add r5, r5, r7               ;convert to decimal

mulLoop

   add r0,r0,r2
   add r5, r5, #-1
   brp mulLoop
;
   add r4, r4, #-1           ; points to the next constant
   ldr r2, r4, #0           ; R2 <-- next constant
   add r1,r1,#1           ; update pointer to Next digit of multipl.
   ldr r5, r1, #0           ; get ascii digit
   add r5, r5, r7           ; convert to decimal
   add r3, r3, #-1           ; decrement length
   brzp mulLoop