Question: ; CSC 2 7 0 - Example Program to read 5 integers, find the sum, and max ( excluding first value ) BR main ;
; CSC Example Program to read integers, find the sum, and max excluding first value
BR main ; Jump to the main program
; Variable declarations
fVal: BLOCK ; Stores the first entered number
sVal: BLOCK ; Stores the sum of entered numbers
cVal: BLOCK ; Counts entries
mVal: BLOCK ; Stores the maximum of entered numbers
iVal: BLOCK ; Stores the current input number
; Start of main program
main: LDWA i ; Load immediate into A
STWA sVal, d ; Initialize sum to
STWA cVal, d ; Initialize count to
LDWA d ; Initialize max value to the smallest possible value
STWA mVal, d ; Store initial max value in mVal to be updated with real input
; Read the first number
STRO prompt, d ; Display input prompt
DECI iVal, d ; Read an integer into iVal
LDWA iVal, d ; Store first value
STWA fVal, d ; Store first value in fVal
LDWA iVal, d ; Add first value to sum
STWA sVal, d ; Store updated sum
; Now process the next numbers and find the max
LDWA i ; Initialize count to since first value is already entered
inputLp: STRO prompt, d ; Display input prompt
DECI iVal, d ; Read an integer into iVal
; Add the input to sum
LDWA sVal, d ; Load sum
ADDA iVal, d ; Add iVal to sum
STWA sVal, d ; Store updated sum
; Compare current input with the max
LDWA iVal, d ; Load current input value
LDWA mVal, d ; Load current max value
CPWA mVal, d ; Compare current input value with current max
BRLE maxSkip ; If current input is not larger, skip update
; Update the max value
STWA iVal, d ; Store new max value in mVal
maxSkip: LDWA cVal, d ; Load current count
ADDA i ; Increment count
STWA cVal, d ; Store updated count
; Check if we've processed exactly numbers st more
LDWA cVal, d
CPWA i
BRNE inputLp ; If not, continue input loop
BR endLoop ; If numbers processed, end loop
endLoop: STRO firstMsg, d ; Print "First ; LDWA fVal, d loads first
LDWA fVal, d ; Load first value
DECO fVal, d ; Output first
STRO sumMsg, d ; Print "Sum ; LDWA sVal, d loads sum
LDWA sVal, d ; Load sum
DECO sVal, d ; Output sum
STRO maxMsg, d ; Print "Max ; LDWA mVal, d loads max
LDWA mVal, d ; Load max value
DECO mVal, d ; Output max
STRO newline, d ; Output newline at the end
STOP ; End program
; Data section
prompt: ASCII x ; Input prompt
firstMsg: ASCII "First x ; Output first message
sumMsg: ASCII Sum x ; Output sum message
maxMsg: ASCII Max x ; Output max message
newline: ASCII
x ; Newline character
END, my input is
is the prompt it reads integers, then my output is First Sum Max everything about the input and output is correct except for the MAX, I cannot figure out the code to get it to read the max integer! in this case would b
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
