Question: Here's the updated code with the recommendations: INCLUDE Irvine 3 2 . inc . 3 8 6 . stack 4 0 9 6 ; macros
Here's the updated code with the recommendations: INCLUDE Irvineinc
stack
; macros
mGet MACRO promptAddr, bufferAddr, bufferSize
lea edx, promptAddr
call WriteString
mov edx, bufferAddr
mov ecx, bufferSize
call ReadString
ENDM
mDisplayString MACRO stringAddr
mov edx, stringAddr
call WriteString
ENDM
mDisplayChar MACRO charValue
mov alcharValue
call WriteChar
ENDM
; constants
TEMPSPERDAY EQU
DELIMITER EQU
BUFFER EQU
data
getFileName BYTE "Enter file name:
giveError BYTE "Error occurred trying to open this file.
outputMsg BYTE "The temperatures in the correct order:
tempFileName BYTE C:UsersDesktopAssignment ProjectTempstxt
fileBuffer BYTE BUFFER DUP
arrayTemps SDWORD TEMPSPERDAY DUP
numTemps SDWORD
code
main PROC
; get file name
mGet getFileName, OFFSET tempFileName, BUFFER
; open file
mov edx, OFFSET tempFileName
call OpenInputFile
JC FileError
; read file
mov edx, OFFSET fileBuffer
mov ecx, BUFFER
call ReadFromFile
cmp eax,
jle FileError
mov byte ptr edx eax
; display file
mov edx, OFFSET fileBuffer
call WriteString
; put temps in right order
PUSH OFFSET fileBuffer
PUSH OFFSET arrayTemps
call ParseTempsFromString
; display new order
mDisplayString OFFSET outputMsg
PUSH OFFSET arrayTemps
call WriteReverse
; exit
jmp endProg
FileError:
mov edx, OFFSET giveError
call WriteString
jmp EndProg
EndProg:
Invoke ExitProcess,
main ENDP
ParseTempsFromString PROC
push ebp
mov ebp, esp
mov esi, ebp
mov edi, ebp
xor ebx, ebx
xor edx, edx
ParseLoop:
lodsb
test alal
jz StoreLastValue
cmp alDELIMITER
je StoreValue
cmp al
je NegativeNum
cmp al
jb SkipChar
cmp al
ja SkipChar
; Convert ASCII to integer and add to running total
sub al
imul ebx,
add ebx, eax
jmp ParseLoop
NegativeNum:
inc edx
jmp ParseLoop
StoreValue:
; If a number was accumulated, store it in arrayTemps
cmp ebx,
je ClearFlags
test edx, edx
jz PositiveNum
neg ebx
PositiveNum:
mov ediebx
add edi,
call WriteInt
inc numTemps
xor ebx, ebx
xor edx, edx
ClearFlags:
jmp ParseLoop
SkipChar:
jmp ParseLoop
StoreLastValue:
; Handle last value if one exists
cmp ebx,
je ExitParseLoop
test edx, edx
jz PositiveLast
neg ebx
PositiveLast:
mov ediebx ; store the last number
add edi,
call WriteInt
inc numTemps ; count the last value as well
ExitParseLoop:
pop ebp
ret
ParseTempsFromString ENDP
WriteReverse PROC
push ebp
mov ebp, esp
mov esi, ebp
mov ecx, numTemps
test ecx, ecx
je ExitWriteReverse
lea esi, esi ecx
WriteLoop:
sub esi,
mov eax, esi
call WriteInt
loop WriteLoop
ExitWriteReverse:
pop ebp
ret
WriteReverse ENDP
END main the console output im getting from this: Enter file name: Tempstxt
The temperatures in the correct order: it ends here with no corrected versionand this is Tempstxt: the output i need is: Enter the name of the file to be read: Tempstxt Here's the corrected temperature order! can you write the updated version of this file, that actually works this time.
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
