LC3 assemly code like provided Assignment #4: add to code below ALL of this plea
ID: 3867408 • Letter: L
Question
LC3 assemly code like provided
Assignment #4: add to code below ALL of this
please do not answer with the same code i provided in this question. Need help with the storing of the user input then doing the sort.
need code added to accept multiple inputs from user and sort them after!!! ADD necesary code to code provided below
add the prompts for the user to input a number
add a loop for input to continue until zero is entered
sort the array
print out on the screen “Sorted Array”
print out the sorted array, one number per line. Note this will require conversion of binary integers to ASCII.
You will need to use various IO traps for this assignment.
so the output will look something like this
Enter a number <Program output>
3 <User input>
Enter a number <Program output>
2 <User input>
Enter a number <Program output>
5 <User input>
Enter a number <Program output>
0 <User input. Note: this will terminate input>
Sorted Array <Program output>
2
3
5
Thanks!
.ORIG x3000
AND R2,R2,#0
LD R3, FILE
COUNT LDR R0,R3,#0
BRz END_COUNT
ADD R3,R3,#1
ADD R2,R2,#1
BRnzp COUNT
END_COUNT ADD R4,R2,#0
BRz SORTED
OUTERLOOP ADD R4,R4,#-1
BRnz SORTED
ADD R5,R4,#0
LD R3,FILE
INNERLOOP LDR R0,R3,#0
LDR R1,R3,#1
NOT R2,R1
ADD R2,R2,#1
ADD R2,R0,R2
BRnz SWAPPED
STR R1,R3,#0
STR R0,R3,#1
SWAPPED ADD R3,R3,#1
ADD R5,R5,#-1
BRp INNERLOOP
BRnzp OUTERLOOP
SORTED HALT
FILE .FILL x7000
.END
Explanation / Answer
ORIG x3000
AND R3, R3, #0 ;r3 stores the sum, set r3 to zer
AND R4, R4, #0 ;r4 is the counter
LD R5, INVERSE_ASCII_OFFSET ;inverse ascii offset
LD R6, DECIMAL_OFFSET ;decimal offset
storing first input digits
LEA R0, display1 ;load the address of the 'display1' message strin
PUTS ;Prints the message string
GETC ;get the first number
OUT ;print the first number
ADD R1, R0, #0 ;store input value(ascii) to r1
ADD R1, R1, R5 ;get real value of r1
storing second input digits
LEA R0, display2 ;load the address of the 'display2' message string
PUTS ;Prints the message string
GETC ;get the first number
OUT ;print the first number
ADD R2, R0, #0 ;store input value(ascii) to r2
ADD R2, R2, R5 ;get real value of r2
ADD R4, R2, #0 ;fill counter with multiplier
MULTIPLICATION:
ADD R3, R3, R1 ;add to sum
ADD R4, R4, #-1 ;decrease counter by one
BRp MULTIPLICATION ;continue loop until multiplier is 0
LEA R0, stringResult
PUTS
ADD R0, R3, R6 ;move result to r0
OUT ;print result
HALT
display1 .STRINGZ " enter the 1st no.: "
display2 .STRINGZ " enter the 2nd no.: "
stringResult .STRINGZ " Result: "
INVERSE_ASCII_OFFSET .fill xFFD0 ; Negative of x0030.
DECIMAL_OFFSET .fill #48
END
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.